Repository navigation
fix: budget tool images against the selected model context window - #4032
Merged
kev1n77 merged 4 commits intoNov 25, 2026
Merged
Conversation
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.
Fixes #4031, including the follow-up about HTTP 413 after several screenshot reads.
Changes
Each model request sends the new uploads and tool results that still need inspection. Once the assistant has responded, subsequent requests carry the history text, tool-call IDs and available image references. Reading another screenshot sends that screenshot. Explicitly reopening a reference supplies the pixels again. A parallel tool batch that has yet to reach the model keeps all of its images eligible for the configured count and token budgets.
The runtime saves content-addressed copies of new image observations, including tool frames without a source file. When an older session has only a source path, the model can request the current file again. If the older runtime discarded the pixels and recorded no path, recovering that image requires another attachment.
Image estimates use the encoded dimensions and the selected model’s vision rules. The send path reserves room for output, keeps new images at full resolution when they fit, and can make a proportional preview. If the server rejects the request body with HTTP 413, the client surfaces crop or batch guidance without retrying the identical request. Explicit model token-limit errors retain context-overflow handling.
Reproduction and verification
The same local HTTP gateway capped the entire JSON body at 128 KiB in both runs. The model had a 128k-token window. A and B were distinct 192 × 128 noise PNGs.
A separate loopback regression explicitly reopens A and verifies the four request bodies contain A, no pixels, B and A in order. Provider-conversion tests cover OpenAI Chat, Responses, Anthropic and Gemini tool-result identity. The error regressions exercise HTML gateway errors, structured model errors and localized user guidance.
The runtime regression also saves and reloads a sanitized session snapshot. A pending tool result recovers its original image bytes. A later request carries the tool ID and its image reference. Other tests overwrite the original file, reopen a pathless frame through a scoped runtime URI, and verify a compression summary cannot resend an image already inspected in its retained tail.
The focused runs passed: 120 core tests, 121 adapter tests with vision input enabled, 16 in the minimal adapter build, 10 error classification tests, 156 configuration tests and 5 Web UI tests. Web UI type checking, localization, Rust dependency boundaries and Git object-size checks also passed.
Local verification commands
AI-assisted. Verified locally against loopback providers and a simulated remote-workspace filesystem. Live provider gateways, SSH hosts, remote control, peer devices and detached dispatch were not exercised.