Skip to content

Empty image attachment is not caught because the guard reads the wrong part shape #46859

Closed as not planned

Description

@devYRPauli

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 [email protected]:

[
 { "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.

Activity

  1. Tarquinen commented on Oct 20, 2026

    @Tarquinen
    Member

    Thanks for the report! OpenCode 2.0 is now out and development is focused on V2, so we're closing issues filed against OpenCode 1. Please upgrade (opencode upgrade --major, details: https://anoma.ly/notes/opencode-2-0), and if this is still relevant on 2.0, reopen this issue or open a new one with your 2.0 version.

    — from 𝕺𝖕𝖊𝖓𝕮𝖔𝖉𝖊

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions