[PR #6342] fix(acp): preserve file attachment metadata during session replay #11848

Closed
opened 2026-02-16 18:16:47 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/6342

State: closed
Merged: Yes


Problem

Fixes #9217 https://github.com/anomalyco/opencode/issues/9217

When reloading an ACP session, file attachments were not being replayed correctly:

  • file type parts in stored messages were not being sent to ACP clients at all
  • Images lost their original filenames (always showed as "image")
  • Binary files (PDFs, etc.) were not replayed
  • Text files appeared as inline text instead of as file attachments
  • Synthetic text parts (injected for LLM context) were incorrectly sent to ACP clients

Solution

Updated processMessage() in agent.ts to properly handle file parts during session replay:

  • file:// URLs → Replayed as resource_link blocks
  • Images → Replayed as image blocks with preserved original filename
  • Text files (text/*, application/json) → Replayed as resource blocks with decoded text
  • Binary files → Replayed as resource blocks with blob data

Also updated the prompt() method to:

  • Preserve original filenames from resource_link.name and image.uri
  • Handle binary resource blocks (PDFs, etc.) by storing them as file parts with data URLs
  • Check for truthy resource.text instead of just property existence

Changes

  • Add file part handling in processMessage() for session replay
  • Filter synthetic text parts from ACP output (!part.synthetic)
  • Preserve filename from resource_link.name when converting to internal parts
  • Handle binary resource.blob blocks in prompt()
**Original Pull Request:** https://github.com/anomalyco/opencode/pull/6342 **State:** closed **Merged:** Yes --- ## Problem Fixes #9217 https://github.com/anomalyco/opencode/issues/9217 When reloading an ACP session, file attachments were not being replayed correctly: - `file` type parts in stored messages were not being sent to ACP clients at all - Images lost their original filenames (always showed as "image") - Binary files (PDFs, etc.) were not replayed - Text files appeared as inline text instead of as file attachments - Synthetic text parts (injected for LLM context) were incorrectly sent to ACP clients ## Solution Updated `processMessage()` in `agent.ts` to properly handle `file` parts during session replay: - **`file://` URLs** → Replayed as `resource_link` blocks - **Images** → Replayed as `image` blocks with preserved original filename - **Text files** (`text/*`, `application/json`) → Replayed as `resource` blocks with decoded text - **Binary files** → Replayed as `resource` blocks with blob data Also updated the `prompt()` method to: - Preserve original filenames from `resource_link.name` and `image.uri` - Handle binary `resource` blocks (PDFs, etc.) by storing them as file parts with data URLs - Check for truthy `resource.text` instead of just property existence ## Changes - Add `file` part handling in `processMessage()` for session replay - Filter synthetic text parts from ACP output (`!part.synthetic`) - Preserve filename from `resource_link.name` when converting to internal parts - Handle binary `resource.blob` blocks in `prompt()`
yindo added the pull-request label 2026-02-16 18:16:47 -05:00
yindo closed this issue 2026-02-16 18:16:47 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#11848