Skip to content

fix(opencode): suppress internal compaction output in ACP - #50274

Draft
IsaacGao wants to merge 1 commit into
anomalyco:devfrom
IsaacGao:acp-summary-filter
Draft

IsaacGao wants to merge 1 commit into
anomalyco:devfrom
IsaacGao:acp-summary-filter

Conversation

@IsaacGao

Copy link
Copy Markdown

Issue for this PR

Related to #40494. This does not close it: it takes a different (narrower) approach than the one suggested in the issue.

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Auto-compaction creates an internal assistant message with summary: true. The ACP layer forwarded its text and reasoning parts to chat clients as ordinary agent output because the ACP part-metadata cache never tracked the summary flag, so both live message.part.delta updates and session/load replay leaked internal compaction content.

This patch filters internal summaries directly, rather than passing a summary marker through ACP or adding lifecycle notifications as suggested in #40494. No public ACP protocol field is added, and compaction plus summary storage are unchanged.

  • packages/opencode/src/acp/session.ts: add an optional summary boolean to KnownMessagePartMetadata and RecordPartMetadataInput, and persist it in recordPartMetadata.
  • packages/opencode/src/acp/event.ts:
    • When part metadata is read from a full message, record summary = role === "assistant" && info.summary === true explicitly (false for other messages), so "known non-summary" is distinct from "not yet inspected".
    • Before forwarding a live delta, reuse cached metadata only when role, part type, and the summary decision are all known; otherwise fetch the owning message. Summary parts are never sent as agent_message_chunk or agent_thought_chunk. A reasoning part.updated still caches role: "assistant", so the summary decision is re-derived instead of trusted from that cache.
    • replayMessage keeps recording part metadata but skips replaying the content of a summary assistant message, so later deltas for those parts stay filtered.

#42316 fixes the same class of leak for CLI JSONL output; this patch covers the ACP path.

How did you verify your code works?

Added regression tests in packages/opencode/test/acp/event.test.ts:

  • live summary text deltas and reasoning deltas are suppressed;
  • suppression survives cache reuse and a later part.updated;
  • session/load replay suppresses summary text and reasoning;
  • normal assistant replies after compaction still stream (replayed text, replayed reasoning, and a live delta);
  • a normal reply whose body contains the word "summary" is not filtered;
  • summary filtering stays isolated per session.

Existing tests that build known normal part metadata directly now record summary: false, and the reasoning-delta service test provides a message fixture instead of weakening the filter.

On this machine with Bun 1.3.14 and locked dependencies:

  • bun test test/acp/ --timeout 30000 --only-failures -> 146 pass, 0 fail.
  • bun typecheck -> clean.
  • The new regression tests fail on the unpatched code and pass with the patch.
  • Prettier and git diff --check clean.

Not verified against a real chat client deployment (e.g. a bridge forwarding ACP updates).

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

Internal compaction summaries are assistant messages marked with summary: true. The ACP event layer forwarded their text and reasoning parts as ordinary agent output because part metadata did not track the summary flag.

Track summary on recorded part metadata, only reuse cached part metadata once the summary decision is known, and skip replaying the content of summary messages during session/load. Internal compaction and summary storage are unchanged.

Related to anomalyco#40494.
@github-actions

Copy link
Copy Markdown
Contributor

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

@github-actions

Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant