Skip to content
Source
Sign inSign up
pingdotgg/t3code

preview_snapshot includeImage embeds full-res base64 PNGs into tool history; providers that reject inline images brick the session permanently #11295

Closedbompus(GitHub profile, opens in a new tab) opened this issue 1 comment

Problem

t3-code_preview_snapshot with includeImage:true embeds full-resolution base64 PNG data: URLs directly into the MCP tool result (state.attachments). Those bytes persist in agent session history and are replayed to the model provider on every subsequent request.

Some providers reject inline image uploads. Observed case: opencode.ai zen gateway → upstream Console, model muse-spark-1.3-contributor-free, returns non-retryable 400 invalid_request_error: Invalid upload request on all later requests — including trivial text-only prompts. The session is permanently bricked; only surgery on the session store (deleting the attachments) recovers it.

Concrete numbers from the incident: two snapshots produced ~1.35MB + ~50KB base64 attachments (1280×800 PNGs), taking session tool history to ~2MB.

Requests

  1. Downscale/compress screenshots before attaching (e.g. max-width + JPEG quality params on the snapshot tools), so the common case stays small.
  2. Prefer returning a file path / saved-file reference plus text over inline base64, letting the agent re-read the image only when vision is actually needed.
  3. Default includeImage to false (or document text-first usage) so agents don't attach images unless the task needs them.

Related upstream tracker (provider-side rejection): https://github.com/anomalyco/opencode/issues/47237 — this issue is the T3-side mitigation for it.

Built from a real incident diagnosed via Muse Spark through T3 Code.

  1. Triage

    Confirmed. Default preview_snapshot still embeds a full-resolution PNG as MCP image content. Those bytes persist in the provider session (OpenCode state.attachments in the reported case) and are replayed on every later request. Providers that reject inline image uploads then fail with a non-retryable 400, including on trivial text-only follow-ups. The session stays bricked until those attachments are deleted.

    This is the same embed path as #10187, but a worse failure mode. #10187 was about image-count caps (fail after ~5 shots). This is any inline image: one or two snapshots is enough. #10232 closed #10187 by adding opt-in includeImage:false and keeping PNG on by default, so it does not prevent this.

    Incident numbers match current capture: desktop already resizes to MAX_SCREENSHOT_WIDTH = 1280, then encodes PNG. A 1280×800 shot can still be ~1.3MB of base64 in tool history.

    Where this happens

    The image is attached in apps/server/src/mcp/McpHttpServer.ts (registerPreviewSnapshot):

    • Text + structuredContent metadata (screenshot bytes reduced to mime/width/height)
    • Plus { type: "image", data: png, mimeType: "image/png" } unless includeImage === false

    save=true writes <stateDir>/browser-artifacts and returns screenshotPath, but still embeds the PNG unless includeImage is also false. The browser host always captures; includeImage/save are MCP-only flags stripped in apps/server/src/mcp/toolkits/preview/handlers.ts.

    OpenCode is pointed at this MCP server in apps/server/src/provider/Layers/OpenCodeAdapter.ts. After that, OpenCode owns the messages T3 does not assemble. T3 cannot unbrick an already-poisoned session.

    Same default-true embed exists for device_screenshot via registerImageTool.

    What prior work did not fix

    WorkWhat it didWhy this still happens
    #10232 (merged)Opt-in includeImage:falseDefault remains PNG
    #10501 (merged; supersedes #9261 / #9505 / #7408)Bound snapshot text; opt-in save/screenshotPathInline image still attached
    #7410Unbounded metadata sizeDifferent payload
    #7302 (open)Slim AX/console/networkScreenshot still attached
    opencode#47237Provider-side rejectionThis issue is the T3 mitigation

    No open T3 PR closes this.

    Suggested fix (T3-side)

    Provider-independent levers, in registerPreviewSnapshot (and likely device_screenshot):

    1. Default includeImage to false and update the tool description / browser instructions so agents use text (and save) unless they need vision. This is the only change that protects providers that reject all inline images. Compression still embeds an image.
    2. Prefer a file reference: when save=true, return screenshotPath and omit the image content part. Let the agent re-read the file only when vision is required.
    3. Optional: JPEG / further downscale for the explicit includeImage:true path. Desktop already has toJPEG for PiP; automation snapshots always use toPNG(). This shrinks history (#10187-style) but does not fix hard upload rejection.

    A single-call MCP change cannot rewrite images already in OpenCode history.

    Workaround

    • New snapshots: pass includeImage: false (and save: true if the user needs to see the page).
    • Bricked session: start a new thread, or delete the stored image attachments from the provider session store. Later text-only prompts will keep failing until those bytes are gone.

    Implementable from current main. No extra reporter info needed.

  2. juliusmarminge added labelsbug

  3. juliusmarminge added labelsaccepted

  4. juliusmarminge added labelsvia-triage

  5. juliusmarminge closed this

Sign in to join this conversation.