anomalyco / anomalyco/opencode
Empty image attachment is not caught because the guard reads the wrong part shape
@nexxeln is already working on this.
Since Sep 2, 2026.
- Dominant language
- TypeScript
- Stars
- 209k
- Forks
- 27.5k
- PR merge metrics
- PR metrics pending
Description
Description
An empty image attachment is sent to the provider instead of being replaced with the error text.
unsupportedParts in packages/opencode/src/provider/transform.ts:416 guards against empty base64 image data. The guard reads part.image, so it only runs when the part type is image.
The prompt pipeline never produces that shape. session/message-v2.ts:220 pushes an attachment as { type: "file", url, mediaType, filename }, and convertToModelMessages converts it to a file model part. The guard therefore never sees a real attachment, and the empty image reaches the provider, which fails the request with its own error.
The two unit tests that cover the guard build the image shape by hand (test/provider/transform.test.ts:2451 and :2498), so they pass while the production path is broken.
Steps to reproduce
Run this from packages/opencode on ef27925:
import { convertToModelMessages } from "ai"
const msgs = await convertToModelMessages([
{
id: "m1",
role: "user",
parts: [
{ type: "text", text: "What is in this image?" },
{ type: "file", url: "data:image/png;base64,", mediaType: "image/png", filename: "empty.png" },
],
},
] as any)
console.log(JSON.stringify(msgs[0].content, null, 1))
Measured output with the pinned ai@6.0.168:
[
{ "type": "text", "text": "What is in this image?" },
{ "type": "file", "mediaType": "image/png", "filename": "empty.png", "data": "data:image/png;base64," }
]
The part type is file, so ProviderTransform.message returns it unchanged. Attaching a 0-byte PNG in the TUI reproduces the same thing end to end.
Expected: the part is replaced with ERROR: Image file is empty or corrupted. Please provide a valid image., which is what the guard does today for the hand-built image shape.
OpenCode version
1.18.26 (built from ef27925 on dev)
Operating System
macOS 26.6.2
I have a fix and a regression test that drives the real convertToModelMessages path. I will open the PR against this issue.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.