fix(agent): retry 413 after stripping vision payloads (#47339) - #56270
Merged
Conversation
When text compression can't reduce a 413 request further, evict base64 image parts from tool messages and retry once instead of dead-ending with 'Payload too large and cannot compress further.' A 413 is a request-body byte-size limit, not a token limit. browser_vision screenshots (2-5MB base64 each) keep the HTTP body oversized even after aggressive summarization. The strip pass passes remember_model=False so a 413 does not poison _no_list_tool_content_models — that set is for providers that reject list-type tool content, a distinct failure mode. Cherry-picked from #47397 by Tranquil-Flow; placed onto main's current token-aware 413 recovery else branch.
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.
Summary
A 413 no longer dead-ends a session that has
browser_visionscreenshots in context — when compression can't shrink the request further, Hermes evicts the base64 image payloads from tool messages and retries once.Root cause (#47339): a 413 is a request-body byte-size limit, not a token limit.
browser_visionstores 2-5MB base64 screenshots per call, so summarizing to ~44k tokens still leaves the HTTP body oversized and the turn dead-ends with "Payload too large and cannot compress further."Changes
agent/conversation_loop.py: in the 413 recovery terminalelse(compression couldn't reduce messages or tokens), strip retained vision payloads and retry once before giving up.run_agent.py:_try_strip_image_parts_from_tool_messagesgainsremember_model(defaultTrue). The 413 path passesremember_model=Falseso a size error doesn't poison_no_list_tool_content_models— that set is for providers that reject list-type tool content (issue [Bug] computer_use multimodal tool message causes 400 error on providers that don't support multimodal tool content (e.g. Xiaomi MiMo) #27344), a distinct failure mode.tests/run_agent/test_413_compression.py: +1 production-path test.Validation
tests/run_agent/test_413_compression.pyAIAgent, real 413 mid-loop)remember_model=False→ image evicted, text kept → recovered in 2 calls;_no_list_tool_content_modelsstayed cleanSalvaged from #47397 by @Tranquil-Flow; placed onto main's current token-aware 413 recovery branch (the PR targeted the pre-token-aware version). Authorship preserved via rebase-merge.
Infographic