Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(server): backfill assistant text from the snapshot when a stalled stream never closes its block #7142

ClosedKiri110K(GitHub profile, opens in a new tab)wants to merge 2 commits intomain fromrefs/pull/7142/headopened View on GitHub

One of two alternative fixes for #7137 — this is the small one. The deeper alternative is #7143: it keys blocks by message id instead of repairing the positional matching, and fixes three adjacent defects along the way. Pick one, they are not meant to be merged together.

What changed

ClaudeAdapter assembles assistant text from stream deltas and uses the claude/assistant snapshot as a safety net when deltas go missing. Two defects made that net miss:

  1. backfillAssistantTextBlocksFromSnapshot aligned snapshot text blocks against the turn-long block list by position from the start. A snapshot describes one message, but the list accumulates across the whole turn — so in any turn with an earlier text message, the snapshot text landed on the wrong, already-completed block.
  2. The backfill only filled a block whose accumulated text was empty, and only completed one whose stream was already closed. A stream that dies mid-message satisfies neither.

This PR aligns snapshot blocks to the tail of the block list (last N open blocks, N = text blocks in the snapshot), and lets the backfill extend an open block when the snapshot text extends the streamed prefix. If the snapshot does not extend what was already shown to the user, nothing is overwritten and a warning is logged.

Why

Hit organically (full event log in #7137): a stream emitted one text_delta — the letter P — then went silent for 3m16s and never sent content_block_stop. The finished 2.4 KB message arrived as a single snapshot. The snapshot text was written onto the wrong block, the dangling block was force-completed empty, and the message was persisted as P. Unrecoverable by restart: the event store never contained the text.

Tests

  • New regression test replays the exact incident event sequence; it fails without the fix (message persisted as P) and passes with it.
  • Full server suite: 230 files passed, 2507 tests passed, 7 skipped, on top of current main.

🤖 Generated with Claude Code

Note

Fix stalled assistant stream repair to backfill only the unstreamed suffix from the snapshot

  • AssistantTextBlockState replaces the emittedTextDelta boolean with a streamedText string that accumulates all text already sent to the client, enabling suffix-only repairs.
  • completeAssistantTextBlock now emits only the missing suffix (snapshot text minus already-streamed prefix) instead of re-sending the full fallback text, preventing duplicate deltas.
  • The assistant snapshot handler aligns snapshot text blocks to open turn blocks by streamed prefix match rather than tail position, avoiding mis-assignment when stalls occur before later blocks arrive.
  • Never-streamed paragraphs in a snapshot are synthesized as new blocks with distinct item IDs.
  • Behavioral Change: blocks that stalled mid-stream now receive a partial delta repair rather than a full-text retransmission.
Macroscope summarized c0d7a59.

Note

Medium Risk Changes assistant text projection and persistence in the Claude adapter—a user-visible runtime path—but the behavior is narrowly scoped to stalled-stream repair with dedicated regression tests.

Overview Fixes lost or truncated assistant messages when the Claude stream stalls mid-text and the finished content arrives only as a claude/assistant snapshot.

ClaudeAdapter now tracks streamedText per text block (replacing a boolean “had a delta” flag) and, on completion/backfill, emits content.delta only for the suffix the client has not already seen—so repairs do not duplicate partial stream output.

Snapshot blocks are aligned to the correct assistant message in a multi-message turn by choosing a shift into the turn-wide block list that best matches open blocks whose streamed prefixes extend the snapshot text, instead of matching from the head of the list. Undelivered snapshot paragraphs can be synthesized as new blocks; fallbackText is treated as authoritative for open blocks.

Tests add regressions for a stalled second message in a turn and for multi-block snapshots when streaming dies before later paragraphs start.

Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit c0d7a59634d7c19b522daf3e7e18a15db1258e51. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).
    1. coderabbitai[bot](GitHub profile, opens in a new tab)commented

      Important

      Review skipped

      Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

      ⚙️ Run configuration

      Configuration used: Repository UI

      Review profile: CHILL

      Plan: Pro Plus

      Run ID: a225404a-50c1-4e6f-bd97-2196434e1ede

      You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

      Use the checkbox below for a quick retry:

      • 🔍 Trigger review

      Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

      ❤️ Share
      Comment `@coderabbitai help` to get the list of available commands.
    2. github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched

    3. Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

      Fix All in Cursor ❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the [Cursor dashboard](https://www.cursor.com/dashboard/bugbot).

      Want fixes drafted automatically? Bugbot Autofix can create code changes for findings. A team admin can enable Autofix in the Cursor dashboard.

      Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit de2a8e7659c0bf3beffde3dd756b37431b9dc091. Configure [here](https://www.cursor.com/dashboard/bugbot).
    4. macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      Approvability

      Verdict: Needs human review

      This bug fix modifies the core streaming path with a moderately complex alignment algorithm for matching snapshot blocks to partially-streamed content. Changes affect real-time text delivery to clients and warrant verification from someone familiar with the Claude adapter's streaming internals.

      You can customize Macroscope's approvability policy. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).
    5. Note

      🤖 GPT-5.6 Sol responding on behalf of Theo

      We're closing this PR as we clean up the T3 Code backlog. Thank you for taking the time to put this together.

      We are keeping OPEN #7143 as the review path for incomplete Claude assistant text. This branch's snapshot-backfill approach remains useful reference.

      If you believe we closed this in error, please reopen the PR and leave a comment explaining what we missed.

Sign in to join this conversation.