# fix\(server\): avoid reparsing streamed replies from the beginning · PR \#24432 · pingdotgg/t3code

[View on GitCafe](https://git.cafe/pingdotgg/t3code/pull/24432)

Repository: [pingdotgg/t3code](https://git.cafe/pingdotgg/t3code)

Visibility: public

State: open

Source repository: pingdotgg/t3code

Source branch: fix/issue-19992

Target branch: main

Head commit: 8de253eebffb79842ddaf2457b98142ce77931d4

[Discussion and reviews](https://git.cafe/pingdotgg/t3code/pull/24432)

[Commits](https://git.cafe/pingdotgg/t3code/pull/24432/commits?format=markdown)

[Files changed](https://git.cafe/pingdotgg/t3code/pull/24432/diffs?format=markdown)

## Description

---

## Problem

Long assistant replies inside an unfinished code fence or paragraph repeatedly parse the accumulated text while waiting for a Markdown boundary. Asking an agent for a 1,500-line fenced reply reproduced repeated full scans in the real app; the deterministic regression test performs 81,800 newline searches for 400 appended lines on main.

## Change

Keep scan progress per active assistant message and resume newline, fence, and partial-line checks from the previous offsets. Reset that progress when a provider replaces text, and discard it when streaming ends. Delivery boundaries and the 400 ms delivery gate stay the same.

## Scope and approval

Fixes https://github.com/pingdotgg/t3code/issues/19992
GitCafe: https://git.cafe/pingdotgg/t3code/issues/19992

Triaged bug via the automated issue flow. Focused server performance fix with unchanged delivered output, contracts, settings, and clients.

## Verification

- Red regression: 81,800 newline searches on main; 803 at the fix for 400 appended lines. The closing-fence output assertion passes.
- `vp test run apps/server/src/orchestration-v2/assistantStreaming.test.ts apps/server/src/orchestration-v2/RunExecutionService.test.ts`: 47 tests passed.
- Targeted lint and formatting on both changed files pass; server typecheck passes.
- Two independent reviews found no blockers. Differential streams exercised appends, truncations, replacements, partial Markdown, throttling, and final events without output mismatches.
- [Before runtime transcript and red failure](https://gh-file-drop-api-prod-mi5fy3sowv63ufte.pinglabs.workers.dev/f/9a83a4b729af09df/reproduction.txt). Live baseline measured 345 splitter calls over 44.9 seconds and 14.7M input characters for 13.8K new characters. Separate profiles measured modest splitter CPU cost, not a severe bottleneck.
- [Proof matrix](https://gh-file-drop-api-prod-mi5fy3sowv63ufte.pinglabs.workers.dev/f/dac7e2d286068913/matrix.md): empty render matrix; server-only change, no changed visual surface.

- [After runtime transcript](https://gh-file-drop-api-prod-mi5fy3sowv63ufte.pinglabs.workers.dev/f/ef6ee41feaa2f952/after-runtime.txt), [measurements](https://gh-file-drop-api-prod-mi5fy3sowv63ufte.pinglabs.workers.dev/f/5e2fdcbde4f16ac7/measurements.json), and [sanitized snapshots and measurement drivers](https://gh-file-drop-api-prod-mi5fy3sowv63ufte.pinglabs.workers.dev/f/75c1e8939ea48e11/runtime-evidence-and-drivers.zip): 1,788 sampled live updates parsed 749 newly completed lines with 2,537 newline searches. Final delivery and persistence exactly matched all 1,500 rows (112,910 characters).
- Proof audit independently validated all published snapshots, exact final text, and the base/head regression counts: `SUFFICIENT`.

Runtime evidence was captured at `0f25149cef` against `a46f80ee28`. The subsequent main merge changes client files only; the scanner and tests are identical. No affected visual surface is unverified. The provider omitted a trailing newline after the closing fence: natural newline-terminated closure was not observed, and the supplemental inspector probe is explicitly labelled. Initial scan and gaps between capture windows were not measured. Server exit during inspector cleanup occurred after evidence capture; its cause is unconfirmed.

The native prefix comparison remains O(n) per processed update so provider replacements can be detected. This removes repeated Markdown parsing; it does not make total work strictly linear across every update.

Implemented with Claude Opus 5.5 through the Claude harness in T3 Code; reviewed with GPT-6.1-Sol and Claude Opus 5.5. Issue lead: GPT-6.1-Sol through the Codex harness in T3 Code.

