fix: guard text-only models from image read attachments#17204
fix: guard text-only models from image read attachments#17204Harryoung wants to merge 2 commits into
Conversation
|
Hey! Your PR title Please update it to start with one of:
Where See CONTRIBUTING.md for details. |
|
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. |
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
6b01ede to
c6880aa
Compare
c6880aa to
d033c85
Compare
|
Hey @adamdotdevin , bumping this one 👀 This change prevents text-only models from receiving base64 image payloads, which can unnecessarily inflate context and cause downstream failures. Would love your take when you get a chance! |
|
Automated PR Cleanup Thank you for contributing to opencode. Due to the high volume of PRs from users and AI agents, we periodically close older PRs using automated criteria so maintainers can focus review time on the most active and community-supported contributions. This PR was closed because it matched the following cleanup criteria:
PRs created within the last month are not affected by this cleanup. If you believe this PR was closed incorrectly, or if you are still actively working on it, please leave a comment explaining why it should be reopened. A maintainer can review and reopen it if appropriate. Thanks again for taking the time to contribute. |
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