t3code icon indicating copy to clipboard operation
t3code copied to clipboard

[Bug]: A mid-turn Claude compaction that keeps most messages streams all of them into the thread again

Open Xyttra opened this issue 1 week ago • 2 comments

Before submitting

  • [x] I searched existing issues and did not find a duplicate.
  • [x] I included enough detail to reproduce or investigate the problem.

Area

apps/server

Steps to reproduce

  1. Use a Claude thread whose compaction keeps most of the transcript. Here that is a Claude Code plugin (fast-jev-compaction) whose hooks module answers session.compact with { messages }: old tool results are removed, every other message is handed back, and there is no summary.
  2. Let the thread pass its auto-compaction window in the middle of a turn, so the compaction runs with trigger auto.
  3. Watch the thread right after the compact_boundary.

Expected behavior

Messages that the thread already shows are reconciled or ignored when the SDK emits them again after a compaction. Only the boundary and what follows it are new.

Actual behavior

Right after an auto compact_boundary, the SDK emits every kept message again, and the thread streams them in again as new messages. The number grows with the thread.

Counts from one thread's provider event log (logs/provider/events.<thread>.log), assistant and user payloads between a compact_boundary and the next stream_event:

Trigger Compactions Messages emitted again after each Of those, assistant
auto (mid-turn) 18 43 to 290 32 to 200
manual (/compact between turns) 5 1 to 2 0

The same plugin code answers both triggers, so the difference is the trigger, not the compaction.

What the re-emitted messages look like:

  • Every re-emitted assistant payload has the same message.id (msg_…) and the same tool_use ids as its first delivery.
  • Its outer uuid is new in almost every case, and it carries no isReplay.
  • After a manual compaction, the one or two user payloads carry isReplay: true.

So an identity taken from the outer uuid does not recognise these messages, while message.id and the content block ids do.

I have not checked whether a built-in (summary) auto-compaction does the same. It keeps few messages, so the effect would be small there.

Impact

Minor bug or occasional failure

It happens at every mid-turn compaction in this setup, and each one adds up to a few hundred repeated messages to the thread.

Version or commit

T3 Code v0.1.10 (desktop)

Environment

Windows 11 Pro, Claude provider, Claude Code 2.1.326 (claude_code_version in the init payload).

Logs or stack traces

One compaction, with content left out:

system compact_boundary  compact_metadata: { trigger: "auto", pre_tokens: 158988, post_tokens: 27197, duration_ms: 403 }
assistant  message.id=msg_A (seen before)  uuid=<new>   x37
user       tool results (seen before)      uuid=<new>   x12
stream_event  (the turn goes on)

Workaround

Run /compact by hand between turns; nothing is emitted again then.

Related

#4930 reported the same kind of replay after /compact and was closed as obsolete when Orchestrator V2 replaced the old path, with a request for a fresh issue if it shows on V2.

Xyttra avatar Nov 18 '26 09:11 Xyttra

I tried to reproduce this on the current build and could not.

Not run in the live app: this VM has no first-party Claude sign-in, and a real mid-turn auto compaction needs ~150k tokens of Claude context plus the reporter's compaction plugin. Instead, on origin/main 316c3256a3, I added an adapter test in apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts ('does not repeat assistant messages Claude re-emits after a mid-turn compaction'). It feeds a live Claude turn the frame sequence from the reporter's log: an assistant snapshot (message.id msg_kept, uuid A), a system compact_boundary with trigger 'auto', the same assistant snapshot again (same message.id, new uuid B), then a result. Ran vp test run src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts -t "re-emits after a mid-turn compaction" in apps/server: it fails with 2 distinct assistant message.updated ids instead of 1. Control: with the re-emitted frame removed, the same test passes (1 message), so the duplicate comes only from the re-emit.

Closing as not planned. If it still happens for you, reply with the exact steps and the version you are on and it will be looked at again.

juliusmarminge avatar Nov 18 '26 09:11 juliusmarminge

Thanks for looking. I think the test in your comment is a reproduction, not a failure to reproduce: on origin/main 316c3256a3, fed the frame sequence from my log, it produces 2 distinct assistant message.updated ids where 1 is expected, and the control without the re-emitted frame passes. That is the bug as reported: the adapter treats an assistant payload the SDK emits again after a mid-turn compact_boundary (same message.id, new outer uuid) as a new message. So it is present on current main, not only on my build.

It still happens for me. What you asked for:

Version: T3 Code (Beta) 0.1.10, desktop, beta channel, Windows 11 Pro. Claude provider, Claude Code 2.1.326.

Exact steps:

  1. Install the plugin: claude plugin marketplace add Xyttra/fast-jev-compaction, then claude plugin install fast-jev-compaction@fast-jev-compaction. It needs CLAUDE_CODE_ENABLE_FUNCTION_HOOKS=1 and a TYPESAFE_API_KEY in the env of ~/.claude/settings.json.
  2. To get there sooner, set "autoCompactWindow": 100000 in ~/.claude/settings.json.
  3. In a T3 Code Claude thread, give one prompt that makes the model read many large files in a single turn (for example "read every file under src/ in full, one Read call per file, then list them"), so the context passes the window while the turn is still running.
  4. When the compaction notice appears mid-turn, the thread streams the earlier assistant messages of the conversation in again, above the turn's next output.

Any hooks module that answers session.compact (trigger auto) with most of e.messages should do the same; the plugin is only what I have. A summary compaction keeps almost nothing, which is likely why this does not show without such a plugin.

Where to look: dedupe on message.id (and the tool_use ids) rather than the outer uuid for assistant payloads that arrive after a compact_boundary. The test you wrote looks like the right regression test for it.

Could this be reopened?

Xyttra avatar Nov 18 '26 09:11 Xyttra