opencode icon indicating copy to clipboard operation
opencode copied to clipboard

ACP session replay drops file attachment metadata and binary/text attachment handling

Open liorshk opened this issue 1 day ago • 1 comments

Description

Summary
When reloading an ACP session, file attachments are not replayed correctly, causing missing files, lost filenames, and incorrect rendering of text/binary content.

Problem
During session replay:

  • File parts in stored messages aren’t replayed to ACP clients.
  • Images lose their original filenames (always shown as “image”).
  • Binary files (PDFs, etc.) aren’t replayed.
  • Text files appear as inline text instead of attachments.
  • Synthetic text parts (LLM context) are incorrectly sent to ACP clients.

Expected
Attachments should be replayed with preserved filenames and correct ACP content block types, and synthetic text should be filtered out.

Actual
Attachments are missing or mis-typed, filenames are lost, and synthetic text is replayed.

Steps to Reproduce

  1. Start an ACP session and attach:
    • an image (e.g., photo.png),
    • a PDF (e.g., doc.pdf),
    • a text file (e.g., notes.txt).
  2. End the session.
  3. Reload the ACP session.
  4. Observe replayed content in the ACP client.

Proposed Solution
Update processMessage() in packages/opencode/src/acp/agent.ts to handle file parts during session replay:

  • file:// URLs → replay as resource_link
  • image/* → replay as image blocks, preserving original filename
  • text/* and application/json → replay as resource with decoded text
  • binary files → replay as resource with blob

Also update prompt() to:

  • Preserve filenames from resource_link.name and image.uri
  • Handle resource.blob by storing file parts with data URLs
  • Check resource.text truthiness (not just property existence)
  • Filter !part.synthetic when replaying text

Changes Outline

  • Add file part handling in processMessage() for replay
  • Filter synthetic text parts (!part.synthetic)
  • Preserve filename from resource_link.name in prompt conversion
  • Handle binary resource.blob in prompt()

Plugins

No response

OpenCode version

No response

Steps to reproduce

  1. Start an ACP session and attach:
  • an image (e.g., photo.png),
  • a PDF (e.g., doc.pdf),
  • a text file (e.g., notes.txt).
  1. End the session.
  2. Reload the ACP session.
  3. Observe replayed content in the ACP client.

Screenshot and/or share link

No response

Operating System

No response

Terminal

No response

liorshk avatar Jan 18 '26 08:01 liorshk