Skip to content

acp: embedded blobs without optional mimeType are silently dropped #64687

Description

@yang0228

Description

ACP session/prompt silently drops an embedded blob resource when mimeType is omitted. The same bytes are attached when mimeType is supplied. ACP v1 makes this field optional.

The resource branch in content.ts returns an empty array before prompt submission.

OpenCode version

dev at a61f5ea83460c197229e67b9c07c49ea87615385 (2.3.0 source), Bun 1.4.4.

Steps to reproduce

  1. Initialize ACP and create a session.
  2. Send this content in session/prompt:
[
  { "type": "text", "text": "Inspect this file" },
  {
    "type": "resource",
    "resource": { "uri": "mcp://context/report.pdf", "blob": "JVBERi0xLjQK" }
  }
]

Expected: the embedded bytes reach the session as an attachment. Actual: the session receives the text with no attachment. Adding "mimeType": "application/pdf" forwards it correctly. The short payload above is only a PDF-signature fixture to demonstrate forwarding.

Reproduced with the real ACP wire fixture in packages/cli/test/acp/prompt.test.ts, asserting the submitted attachment list.

Operating System

macOS arm64.

Activity

  1. added
    area/ide-acp
    type/bug
    version/v2
    on Nov 18, 2026
  2. opencodejr commented on Nov 18, 2026

    @opencodejr
    Contributor

    Seen with a simulated model or a mock server, not a real provider; a maintainer should confirm.

    Thanks for the precise report. I reproduced this with the released @opencode/cli 2.3.0, driving opencode acp over stdio with your exact session/prompt payload. A local mock OpenAI-compatible endpoint stood in for the model so I could see what OpenCode sends it:

    • Without mimeType: the user message that reached the model was only "Inspect this file". The PDF blob was gone, and the prompt still ended in end_turn with no error or warning to the ACP client.
    • With "mimeType": "application/pdf": the message carried a file part with data:application/pdf;base64,JVBERi0xLjQK.

    It still happens on the latest dev (a61f5ea), run from source. The cause looks like the line you pointed to in packages/cli/src/acp/content.ts: the resource case returns [] when a blob has no mimeType, while the ACP SDK it uses marks that field as optional.

    The script below reproduces it. The only thing faked is the model endpoint, and the block is dropped before any model call.

    Reproduction script (repro.ts)
    // Reproduces #64687: ACP embedded blob resource without mimeType is dropped.
    // Starts a mock OpenAI-compatible endpoint (stands in for the model), runs `opencode acp`
    // (or the checkout's CLI when OC_DEV is set), sends two prompts, and prints what reached the model.
    import { spawn } from "node:child_process"
    import { mkdirSync, writeFileSync } from "node:fs"
    
    const bodies: any[] = []
    const server = Bun.serve({
      port: 0,
      async fetch(req) {
        const url = new URL(req.url); if (process.env.DUMP) console.error("REQ", req.method, url.pathname)
        if (req.method === "POST" && url.pathname.endsWith("/chat/completions")) {
          { const j = await req.json(); bodies.push(j); if (process.env.DUMP) console.error(JSON.stringify(j).slice(0, 1500)) }
          const chunk = (d: any) => `data: ${JSON.stringify(d)}\n\n`
          const base = { id: "c1", object: "chat.completion.chunk", created: 0, model: "mock" }
          const sse =
            chunk({ ...base, choices: [{ index: 0, delta: { role: "assistant", content: "ok" }, finish_reason: null }] }) +
            chunk({ ...base, choices: [{ index: 0, delta: {}, finish_reason: "stop" }], usage: { prompt_tokens: 1, completion_tokens: 1, total_tokens: 2 } }) +
            "data: [DONE]\n\n"
          return new Response(sse, { headers: { "content-type": "text/event-stream" } })
        }
        return new Response(JSON.stringify({ data: [] }), { headers: { "content-type": "application/json" } })
      },
    })
    
    const proj = "/workspace/repro/proj"
    mkdirSync(proj, { recursive: true })
    writeFileSync(`${proj}/opencode.jsonc`, JSON.stringify({
      providers: { mock: { name: "Mock", env: ["MOCK_API_KEY"], package: "@opencode/ai/providers/openai-compatible",
        settings: { baseURL: `http://127.0.0.1:${server.port}/v1` },
        models: { m: { name: "Mock", capabilities: { tools: false, input: ["text", "image", "pdf"], output: ["text"] } } } } },
      model: "mock/m",
    }))
    
    const dev = process.env.OC_DEV
    const cmd = dev
      ? ["bun", ["--conditions=browser", `--preload=${dev}/packages/tui/node_modules/@opentui/solid/scripts/preload.js`, `${dev}/packages/cli/src/index.ts`, "acp"]]
      : ["opencode", ["acp"]]
    const child = spawn(cmd[0] as string, cmd[1] as string[], { cwd: proj, env: { ...process.env, MOCK_API_KEY: "x", ...(dev ? { BUN_OPTIONS: `--conditions=browser --preload=${dev}/packages/tui/node_modules/@opentui/solid/scripts/preload.js` } : {}) }, stdio: ["pipe", "pipe", "inherit"] })
    let buf = ""
    const pending = new Map<number, (v: any) => void>()
    child.stdout.on("data", (d) => {
      buf += d
      let i
      while ((i = buf.indexOf("\n")) >= 0) {
        const line = buf.slice(0, i); buf = buf.slice(i + 1)
        if (!line.trim()) continue
        const msg = JSON.parse(line)
        if (msg.id !== undefined && pending.has(msg.id)) { pending.get(msg.id)!(msg); pending.delete(msg.id) }
        else if (msg.id !== undefined && msg.method) child.stdin.write(JSON.stringify({ jsonrpc: "2.0", id: msg.id, result: { outcome: { outcome: "cancelled" } } }) + "\n")
      }
    })
    let next = 1
    const rpc = (method: string, params: any) => new Promise<any>((res) => {
      const id = next++; pending.set(id, res)
      child.stdin.write(JSON.stringify({ jsonrpc: "2.0", id, method, params }) + "\n")
    })
    
    const init = await rpc("initialize", { protocolVersion: 1, clientCapabilities: {} })
    console.log("embeddedContext:", JSON.stringify(init.result?.agentCapabilities?.promptCapabilities))
    for (const withMime of [false, true]) {
      const s = await rpc("session/new", { cwd: proj, mcpServers: [] })
      if (s.error) { console.log("session/new error", JSON.stringify(s.error)); break }
      const resource: any = { uri: "mcp://context/report.pdf", blob: "JVBERi0xLjQK" }
      if (withMime) resource.mimeType = "application/pdf"
      const before = bodies.length
      const r = await rpc("session/prompt", { sessionId: s.result.sessionId, prompt: [{ type: "text", text: "Inspect this file" }, { type: "resource", resource }] })
      const body = bodies.slice(before).find((b: any) => !String(b.messages?.[0]?.content).startsWith("You name conversations"))
      const user = body?.messages?.filter((m: any) => m.role === "user").at(-1)
      console.log(`\n== mimeType ${withMime ? "present" : "omitted"} == stopReason=${r.result?.stopReason ?? JSON.stringify(r.error)}`)
      console.log("user message sent to model:", JSON.stringify(user?.content, (k, v) => typeof v === "string" && v.length > 80 ? v.slice(0, 80) + "…" : v))
    }
    child.kill(); server.stop(true); process.exit(0)

    Run it: bun repro.ts

  3. added
    status/repro-simulated
    on Nov 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/ide-acpplatform/macosstatus/repro-simulatedtype/bugversion/v2

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions