Skip to content

Read: invalid image payload from file attachment poisons subsequent turns #15264

Closed

Description

@LIU9293

Description

When a Read result includes an image attachment whose bytes are not a valid image, provider adapters can throw an image decoding error and the session gets stuck failing on following turns.

Plugins

None

OpenCode version

v1.2.15 (also reproducible on current dev branch before this fix)

Steps to reproduce

  1. Attach or read a file that is labeled as an image (image/png, image/jpeg, image/gif, or image/webp) but contains invalid bytes/base64.
  2. Send a prompt so the message is transformed and forwarded to the model provider.
  3. Observe provider error: "The image data you provided does not represent a valid image..." and subsequent turns continue failing.

Screenshot and/or share link

N/A

Operating System

macOS (arm64)

Terminal

iTerm2

Activity

  1. added
    coreAnything pertaining to core functionality of the application (opencode server stuff)
    on Feb 26, 2026
  2. github-actions commented on Feb 26, 2026

    @github-actions
    Contributor

    This issue might be a duplicate of existing issues. Please check:

  3. kapaandyy commented on Mar 23, 2026

    @kapaandyy

    Additional reproduction scenario: file extension vs actual MIME type mismatch

    @thdxr I hit the exact same "poisons subsequent turns" issue, but with a more specific root cause worth noting:

    What happened

    1. Used bash tool to call Gemini API for image generation. Gemini returned mimeType=image/jpeg data.
    2. The AI-written script saved the JPEG data with a .png extension: /tmp/nano_banana_test.png
    3. AI then called the read tool on this .png file
    4. OpenCode's read tool correctly detected the attachment mime as image/jpeg (stored correctly in the DB with "mime":"image/jpeg" and "url":"data:image/jpeg;base64,...")
    5. However, when assembling the API request for the next turn, OpenCode used media_type: image/png (inferred from the .png file extension), overriding the correctly detected mime
    6. Anthropic API returned 400: "The image was specified using the image/png media type, but the image appears to be a image/jpeg image"
    7. Session permanently stuck - every subsequent turn re-sends the poisoned tool_result

    Key insight

    The bug is in the provider adapter layer: when converting stored attachments into API request payloads, OpenCode re-infers the media type from the file path extension instead of using the already-correct mime field from the stored attachment data.

    Environment

    • OpenCode v1.2.27
    • macOS (arm64)
    • Anthropic claude-opus-4-6
    • Workaround: manually cleaned the SQLite DB (opencode.db) - removed the image attachment from the part data and deleted the error messages
  4. added a commit that references this issue on Apr 5, 2026
    b28b36a
  5. assigned and unassigned on Apr 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

coreAnything pertaining to core functionality of the application (opencode server stuff)

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions