Skip to content

fix(read): prevent unsupported image formats from being sending to provider#21114

Merged
rekram1-node merged 3 commits intoanomalyco:devfrom
zeke:fix-unsupported-image-formats
May 1, 2026
Merged

fix(read): prevent unsupported image formats from being sending to provider#21114
rekram1-node merged 3 commits intoanomalyco:devfrom
zeke:fix-unsupported-image-formats

Conversation

@zeke
Copy link
Copy Markdown
Contributor

@zeke zeke commented Apr 5, 2026

Issue for this PR

Closes #17772
Closes #15264

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

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

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

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
@github-actions github-actions Bot added contributor needs:compliance This means the issue will auto-close after 2 hours. labels Apr 5, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 5, 2026

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
#17774

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.

@github-actions github-actions Bot removed the needs:compliance This means the issue will auto-close after 2 hours. label Apr 5, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 5, 2026

Thanks for updating your PR! It now meets our contributing guidelines. 👍

@zeke
Copy link
Copy Markdown
Contributor Author

zeke commented Apr 5, 2026

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! 🧡

@momoshell
Copy link
Copy Markdown

Confirming the allowlist catches another case: .dxf from a CAD pipeline — AppFileSystem.mimeType returns image/vnd.dxf and currently triggers the same poison-history loop. This fix drops it cleanly. +1.

@rekram1-node
Copy link
Copy Markdown
Collaborator

will look

Comment thread packages/opencode/src/tool/read.ts Outdated
const mime = AppFileSystem.mimeType(filepath)
const supportedImageMimes = new Set(["image/jpeg", "image/png", "image/gif", "image/webp"])
const isImage = supportedImageMimes.has(mime)
const isUnsupportedImage =
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like if it isnt a supported format it should fall down to the text/byte path, I think that's what some other agents do

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I went ahead and made this change

@rekram1-node
Copy link
Copy Markdown
Collaborator

/review

Comment thread packages/opencode/src/tool/read.ts
@rekram1-node rekram1-node changed the title fix(read): reject unsupported image formats before sending to provider fix(read): prevent unsupported image formats from being sending to provider May 1, 2026
@rekram1-node rekram1-node merged commit 51e310c into anomalyco:dev May 1, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

3 participants