fix(agent): retry 413 after stripping vision payloads (salvage #47397) - #56293
Merged
Conversation
kshitijk4poor
enabled auto-merge (rebase)
July 1, 2026 10:30
Collaborator
Duplicate of #56270 — the same salvage of #47397 (retry 413 after stripping retained vision payloads, |
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
Salvage of #47397 by @Tranquil-Flow (cherry-picked onto current
main, authorship preserved). On an HTTP 413 that can't compress further, strips retained tool-message image payloads from the retry so an oversized vision request recovers instead of hard-failing (#47339).The bug
Issue #47339: context compression doesn't evict image/vision payloads, so a request can 413 even at ~44k tokens. Confirmed still present on
main:_strip_historical_mediaanchors onrole=="user"images and the compressor only evicts tool-result image envelopes outside the protected tail — so a recent screenshot in the protected tail keeps its base64 bytes through every compression pass. When compression "can't reduce further," it still 413s.The fix
At the terminal else-branch of the 413/
payload_too_largerecovery (reached only when compression didn't reduce the request), strip retained tool-message image payloads:image_urlandinput_imagebyte parts, preservestext/input_text(reassembled as joined text or a placeholder);remember_model=Falsekwarg so a 413 (a size problem) does not permanently mark a vision-capable model as unable to accept list-type tool content — that learning stays scoped to genuine provider list-content rejections.Cluster context (#47339)
This is one of several approaches for #47339. It's the 413-retry-level backstop — complementary to, not competing with:
_strip_historical_media) — currently closed;Verified as a sound standalone backstop: it addresses a real unfixed gap (protected-tail images survive compression) and doesn't collide with the shrink PRs. Ideally a compressor-level fix also lands so the tail case is handled before 413 fires; this remains valuable as the last-resort layer.
Review
Ran hermes-agent-dev + hermes-pr-review Phase 2c — 0 Critical. Strip logic handles both image shapes, preserves text, only fires on the last-resort path; the
_no_list_tool_content_modelslearning-separation is real and tested (non-tautological — the test verifies retry #2's wire payload drops the image bytes present in #1).Tests
Supersedes #47397. Full credit to @Tranquil-Flow.