Skip to content

ACP: attachment filenames stay URL-encoded #59792

Done

Description

@andreivince

Description

Attachment names that come in over ACP keep their URL encoding. If an image is sent with uri: "file:///tmp/photo%201.png", the part ends up with filename: "photo%201.png" instead of photo 1.png. Same for names with spaces, accented letters, # or %.

Embedded attachments get it twice. On replay the URI is rebuilt with pathToFileURL(filename) from the already encoded name, so photo%201.png turns into photo%25201.png in the URI.

Plugins

None

OpenCode version

2.2.0 (dev at 76e1f5b)

Steps to reproduce

From the repo root, run this with Bun:

import { promptContentToParts } from "./packages/cli/src/acp/content"
console.log(promptContentToParts([
  { type: "image", data: "", mimeType: "image/png", uri: "file:///tmp/photo%201.png" },
]))

It prints filename: "photo%201.png".

You can also see it in the prompt wire test (packages/cli/test/acp/prompt.test.ts) by renaming its local image to local #1 100% café.png: the URI that reaches the server is fine, but the name is local%20%231%20100%25%20caf%C3%A9.png.

Expected: photo 1.png. One thing to keep in mind for a fix: Zed's ?path= query paths are already decoded, so those shouldn't be decoded again.

Screenshot

N/A, protocol only.

Operating System

macOS 26.6.2 (arm64), Bun 1.4.4

Terminal

N/A, not a TUI issue.

Activity

  1. opencodejr commented on Oct 28, 2026

    @opencodejr
    Contributor

    Thanks for the detailed report. I reproduced this on the latest dev (86ce19d). content.ts hasn't changed since v2.2.0, so that release behaves the same way.

    The script below calls promptContentToParts with an image (file:///tmp/photo%201.png) and an embedded blob (file:///tmp/caf%C3%A9%20%231.bin). The parts end up with filename: "photo%201.png" and "caf%C3%A9%20%231.bin". Passing the data parts through partsToContentChunks then gives double-encoded replay URIs such as .../photo%25201.png.

    The cause appears to be filenameFromUri, which takes the basename of url.pathname without decoding it. As you noted, the Zed ?path= branch is already decoded and should stay that way. Your PR #59793 addresses this.

    Reproduction script (repro.ts)
    // Run from an opencode checkout: bun /workspace/repro/repro.ts [/path/to/repo]
    const repo = process.argv[2] ?? "/workspace/repo"
    const { promptContentToParts, partsToContentChunks } = await import(`${repo}/packages/cli/src/acp/content.ts`)
    
    const parts = promptContentToParts([
      { type: "image", data: "", mimeType: "image/png", uri: "file:///tmp/photo%201.png" },
      { type: "image", data: "AAAA", mimeType: "image/png", uri: "file:///tmp/photo%201.png" },
      { type: "resource", resource: { uri: "file:///tmp/caf%C3%A9%20%231.bin", mimeType: "application/octet-stream", blob: "AAAA" } },
    ])
    for (const p of parts) console.log("part filename:", JSON.stringify(p.filename), "url:", p.url.slice(0, 40))
    
    const replay = partsToContentChunks(parts.filter((p: any) => p.url.startsWith("data:")))
    for (const c of replay) console.log("replay uri:", (c.content as any).uri ?? (c.content as any).resource?.uri)

    Run it: bun repro.ts

  2. Vaili commented on Oct 30, 2026

    @Vaili

    I reproduced this on dev (958f965). file:///tmp/photo%201.png yields filename: photo%201.png, and replay double-encodes embedded names (caf%25C3%25A9...). I'd like to take it.

    Plan: decode file: basenames with fileURLToPath, decode HTTP(S) path segments safely, and add regression tests for spaces, #, %, and Unicode. No open PR found.

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions