fix: guard text-only models from image read attachments#17204
Open
Harryoung wants to merge 2 commits intoanomalyco:devfrom
Open
fix: guard text-only models from image read attachments#17204Harryoung wants to merge 2 commits intoanomalyco:devfrom
Harryoung wants to merge 2 commits intoanomalyco:devfrom
Conversation
Contributor
|
Hey! Your PR title Please update it to start with one of:
Where See CONTRIBUTING.md for details. |
Contributor
|
Thanks for your contribution! This PR doesn't have a linked issue. All PRs must reference an existing issue. Please:
See CONTRIBUTING.md for details. |
Contributor
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
6b01ede to
c6880aa
Compare
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.
Issue for this PR
Closes #17205
Type of change
What does this PR do?
When a text-only model like
zai-coding-plan/glm-4.7used theReadtool on an image, the tool still produced adata:image/...;base64,...attachment. That attachment could then be carried forward through the message pipeline before the provider layer finally rejected image input, which is the wrong place to catch it and can blow up context size.This change fixes that in two places.
First, the
Readtool now checks the current model capability before attaching image or PDF content. If the active model does not support that modality, the tool returns a short text explanation and does not attach the file at all.Second, tool-result media is now filtered again when model messages are built. If a tool produced media that the current model cannot accept, that media is not re-injected into the prompt. Instead, the tool result gets a small text note explaining that the file was omitted. Models that do support image input keep the old behavior.
The reason this works is straightforward: the bad payload is no longer created for the failing path, and there is still a message-layer guard so other tools cannot accidentally reintroduce the same problem.
How did you verify your code works?
bun test test/tool/read.test.ts test/session/message-v2.test.ts test/provider/transform.test.ts --timeout 30000inpackages/opencodeReadon images with a text-only modelzai-coding-plan/glm-4.7usingimage.pngand confirmed the outbound request body did not containdata:imageor base64 media payloadsScreenshots / recordings
Not a UI change.
Checklist