fix(read): reject unsupported image formats before sending to provider#21114
fix(read): reject unsupported image formats before sending to provider#21114zeke wants to merge 1 commit intoanomalyco:devfrom
Conversation
The Read tool accepted any image/* MIME type (except SVG and fastbidsheet) and sent it to the LLM provider. Providers like Anthropic only support JPEG, PNG, GIF, and WebP, so formats like BMP, TIFF, AVIF, and HEIC caused API validation errors. Because the unsupported attachment was persisted in the conversation history, every subsequent message replayed it, making the session unrecoverable. Closes anomalyco#17772 Closes anomalyco#15264
|
The following comment was made by an LLM, it may be inaccurate: Found a potential duplicate: PR #17774: feat: auto-convert unsupported image formats (AVIF, HEIC) to PNG This PR is directly related to the current PR #21114. Both address the same problem with unsupported image formats (AVIF, HEIC, BMP, TIFF) in the Read tool. However, they propose different solutions:
You may want to check if #17774 is still open or if there's been a decision on which approach is preferred. |
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
|
Hey @rekram1-node and @thdxr — this is a small fix for the issues you two are assigned to (#17772 and #15264). It adds an allowlist of supported image formats so unsupported ones like BMP/AVIF/HEIC get rejected with a clear error instead of poisoning the session. Would love your eyes on it when you get a chance. And thanks for building OpenCode — it's been a life-changer for me! 🧡 |
Issue for this PR
Closes #17772
Closes #15264
Type of change
What does this PR do?
This PR adds an allowlist of provider-supported image formats (JPEG, PNG, GIF, WebP) to the Read tool. Previously, any
image/*MIME type (except SVG and fastbidsheet) was base64-encoded and sent to the LLM provider. Formats like BMP, TIFF, AVIF, and HEIC were accepted by the Read tool but rejected by the provider API, and because the unsupported attachment was persisted in conversation history, every subsequent message replayed it — making the session unrecoverable.Unsupported image formats now return a clear error message instead of silently passing through.
There's also #17774 which takes a different approach by auto-converting unsupported formats to PNG using sharp/sips/ffmpeg. That's a nice idea but a bigger change with new dependencies and more failure modes. This PR is a two-line fix that stops the session-poisoning bug immediately. Auto-conversion could be layered on top of this later.
How did you verify your code works?
Added three test cases for BMP, TIFF, and AVIF rejection. All 38 read tool tests pass. Typecheck passes.
Checklist