Skip to content
Source
Sign inSign up
pingdotgg/t3code

[Bug]: Successful Claude /compact replays a preserved historical error as a new assistant message #4930

Closedreed-yang(GitHub profile, opens in a new tab) opened this issue 1 comment

[Bug]: Successful Claude /compact replays a preserved historical error as a new assistant message

Before submitting

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

Area

apps/server

Steps to reproduce

  1. Start a T3 thread using the Claude Agent provider and build enough context for /compact to run.
  2. Make one compaction attempt fail at the inference boundary, for example by making the selected upstream temporarily unreachable. Claude records the failure as a synthetic assistant/local-command error in its native transcript, and T3 renders it once.
  3. Let T3 soft-stop/reap the idle Claude provider session so the next turn resumes the same native Claude session.
  4. Restore the upstream and run /compact again in the same T3 thread.
  5. Wait until Claude emits a successful compact_boundary.

The first failure is only a convenient way to make a replayed historical tail message visually unambiguous. The underlying boundary is any assistant snapshot that the SDK re-emits after resume/compaction and T3 has already persisted.

Expected behavior

The successful compact boundary should be rendered once, and an SDK message that is already present in the T3 thread should be reconciled or ignored.

Provider-native UUIDs should act as idempotency keys across provider restarts and resume replay. A historical snapshot must not become a fresh assistant message merely because it was received again after compaction.

Actual behavior

The second /compact succeeds, but T3 immediately renders the first attempt's old error again as a new assistant message. This makes a completed compaction look like a second failure.

Sanitized event sequence from the observed thread:

t0          SDK assistant snapshot: uuid=A, timestamp=t0, text="Error during compaction: ... 502 ..."
t0          T3 appends assistant item X
t1          T3 soft-stops the idle Claude provider session
t2          manual /compact starts after the upstream recovers
t2+234s     compact_boundary: state=compacted, pre_tokens=678233, post_tokens=8266
t2+234s     SDK assistant snapshot: uuid=A, timestamp=t0, same historical error text
t2+234s     T3 appends a different assistant item Y

The second SDK snapshot retained both the original outer UUID and its original timestamp. T3 nevertheless assigned fresh canonical event/item IDs and sent a new visible message. The native transcript contains one error record and one later successful compact boundary; the duplicate exists in T3's projection, not as a second native failure.

This is a replay/idempotency defect rather than a compaction failure:

  • handleAssistantMessage() processes every SDK assistant snapshot and calls backfillAssistantTextBlocksFromSnapshot() without checking the raw SDK message UUID or timestamp.
  • Snapshot backfill can allocate a fresh synthetic item ID, so replayed input becomes a distinct T3 message.
  • Resume starts the SDK by native session ID while the persisted resumeSessionAt value is deliberately not passed to query(); the existing test asserts that options.resumeSessionAt is undefined. That makes replay reconciliation in the adapter/projection layer especially important.
  • The same behavior is still present on current main.

Related but distinct reports:

  • #3149 documents the same architectural class for Cursor ACP session/load replay, not the Claude Agent adapter or compaction.
  • #4650 is about incorrect post-compact token metering, not duplicate historical messages.

Impact

Major degradation or frequent failure

Version or commit

Observed on T3 Code v0.0.30 (60af905e). Relevant logic remains unchanged on main at 6efcf3e.

Environment

macOS; T3 Code Desktop v0.0.30; Claude Agent provider; Claude Code 2.1.220; Claude Opus 5 with a 1M context window. The selected upstream was reached through a loopback inference gateway; no gateway hostname, credential, private path, thread ID, or full provider session ID is included here.

Logs or stack traces

# First visible error (sanitized)
CANON assistant item=X raw.uuid=A raw.timestamp=t0
text="Error during compaction: API Error: 502 ..."

# Later manual compact succeeds
thread.state.changed state=compacted
compact_metadata.trigger=manual
compact_metadata.pre_tokens=678233
compact_metadata.post_tokens=8266
compact_metadata.duration_ms=234048

# The SDK then re-emits the historical snapshot; T3 appends it again
CANON assistant item=Y raw.uuid=A raw.timestamp=t0
text="Error during compaction: API Error: 502 ..."

Suggested regression test:

  1. Emit an SDK assistant snapshot with UUID A and persist its canonical assistant item.
  2. Stop and resume the adapter with the persisted Claude resume cursor.
  3. Emit a successful compact_boundary, then emit the same SDK assistant snapshot A again as resume replay.
  4. Assert that the compact boundary is processed but no second content delta, assistant item, or T3 message is emitted for A.

A robust fix should reconcile provider-native UUIDs across session restarts. At minimum, a resumed assistant snapshot matching the persisted resumeSessionAt UUID should not be appended again. Timestamp-only filtering is weaker because clocks and delayed background messages can be legitimate.

Screenshots, recordings, or supporting files

No response.

Workaround

After /compact, trust the context-compaction activity or native compact_boundary, not a replayed synthetic error row. If the boundary says state=compacted and reports a lower post_tokens value, do not run /compact again.

  1. Thanks for preserving the native message identity in the replay trace. Orchestrator V2 has merged in #2829.

    Claude message handling has been replaced with V2 native-item-derived identities and typed message updates. We are closing this report against the old synthetic-message and replay path as obsolete. We have not replayed the failed-then-successful compaction sequence on V2.

    If the problem persists on a build containing V2, please open a fresh issue with the T3 version, provider version, reproduction steps, and relevant logs, and link this report.

  2. juliusmarminge closed this

Sign in to join this conversation.