fix(coding-agent): recover from 413 request too large#1936
Closed
ogulcancelik wants to merge 1 commit intobadlogic:mainfrom
Closed
fix(coding-agent): recover from 413 request too large#1936ogulcancelik wants to merge 1 commit intobadlogic:mainfrom
ogulcancelik wants to merge 1 commit intobadlogic:mainfrom
Conversation
Contributor
Author
|
also should i have opened an issue first ? let me know if you do prefer issue first prs now, just wanted to provide a quick solution. |
Owner
|
currently refactoring agent session and fixing this will be part of that work. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Anthropic returns HTTP 413
request_too_largewhen the request payload exceeds 32 MB. I could reproduce this consistently in image-heavy sessions where context token usage was still relatively low (~30%), but the request body had grown too large because conversation history contained many base64-encoded images.I couldn’t reproduce the same failure on OpenAI models, likely because their effective payload limits are higher, but 413 is a standard HTTP error for this class of problem.
Root cause
Compaction currently tracks token usage, not HTTP request size.
That works for normal text-heavy sessions, but images are a bad mismatch for token-only accounting:
So a session can stay far below the context window while still exceeding the provider’s request size limit.
Fix
When a request fails with HTTP 413 /
request_too_large:This recovery now works even when auto-compaction is disabled.
The stripping logic handles images in:
usermessagestoolResultmessagescustommessagesSession history on disk is left untouched. Only the in-memory request context is modified for recovery.
Tests
Added tests for:
isRequestTooLarge()detection