fix(server): long streams no longer store a full copy per paragraph #24700
main fromrefs/pull/24700/head·opened View on GitHubProblem#
In paragraph streaming mode, every streaming snapshot the server lets through becomes a durable turn-item.updated event that holds the item's full text so far. A reasoning block that streams for minutes writes one row per paragraph, each longer than the last, so its storage grows with the square of its length. #23365 measured 93,095 rows and 2.2 GB of OpenCode reasoning snapshots in one day on one install, with a single item at 612 rows and 69 MB. Turn mode avoids it, but only by giving up live streaming for every provider.
Change#
makeAssistantStreamingFilter keeps its 400 ms gate and paragraph boundaries. Once the last passed snapshot of an item reaches 8,000 characters, a snapshot that extends it passes only when its text is at least a quarter longer. Past that point the passed snapshots grow geometrically, so their combined size stays within a few times the final text instead of growing with its square. From 8,000 to 225,000 characters that is at most 15 more snapshots. A snapshot that does not extend the last passed one, such as a provider replacing the item's text, still passes under the 400 ms gate as on main.
Items under 8,000 characters stream exactly as before. The median reasoning item in the issue was about 1,700 characters. The final, non-streaming event is untouched, so when it arrives the stored text a thread ends with is the same.
The trade-off shows in two places. While a long item streams, paragraphs past 8,000 characters arrive in larger steps; the screenshots below show it. If an item never gets its final event, for example when the server restarts mid-stream or a Stop finds the session already gone, it is settled from its last stored snapshot, so a long item can lose up to about a fifth of its text there instead of up to one paragraph.
Scope and approval#
Fixes #23365. The issue is open and has no maintainer reply yet. It lists three directions, and this PR takes the second: bound how many intermediate snapshots each item stores. This change awaits maintainer review. Maintainers may want to confirm:
- the 8,000-character threshold and the 1.25 growth factor, both module constants;
- applying the rule to assistant messages too, not only reasoning. The filter treats both the same way and a long reply has the same growth. If you prefer reasoning only, it is a one-line condition.
- the text a long item can lose when it is settled without its final event (server restart, or a Stop after the session died): up to about a fifth of the item, against one paragraph today.
The issue's first direction, live delivery without durable intermediate events, would need a non-durable event path through the live stream and its resume cursors. That is a larger change, so I left it alone.
Verification#
- New test in
assistantStreaming.test.tsstreams a 100,000-character item one 500-character paragraph per event past the 400 ms gate. On main it stores 10,050,000 characters of snapshots and fails the< 8 × final lengthbound. On this branch it passes. A second test checks that an 8-paragraph item still passes every paragraph, and a third that a 9,000-character replacement of a 10,000-character snapshot passes at the next 400 ms boundary. vp test runonassistantStreaming.test.ts,RunExecutionService.test.tsandSteeringCompletion.integration.test.ts: 61 passed.vp fmt --checkandvp linton both changed files, and the server package typecheck: pass.- Real app, web client, isolated dev state on a disk-backed SQLite database. A local ACP agent configured through the ACP Registry "Local command" source streamed one 100-paragraph reasoning block (about 50,000 characters) at 450 ms per paragraph, pausing after paragraph 60. The same agent and prompt ran against main and this branch:
| streaming reasoning rows | payload bytes | final row | |
|---|---|---|---|
| main | 100 | 2,635,386 | 51,178 bytes |
| this branch | 24 | 272,301 | 51,178 bytes |
Both final rows hold the same 49,891-character text, and the finished thread on this branch shows all 100 paragraphs.
- Real app, mobile clients: debug builds on an iOS 26.5 simulator and an Android 16 emulator, each paired with its own server built from main or from this branch. The prompt was sent from the mobile composer to the same agent, with a longer pause after paragraph 60 so the screen could be captured. On both platforms main stored 100 streaming reasoning rows (2,630,886 bytes) and this branch stored 24 (271,221 bytes), with the same 49,891-character final text.
Not checked:
- the desktop (Electron) app. It wraps the web client checked above;
- a real OpenCode session with local models, the provider in the issue;
- the reporter's own database.
Main at this base has no conflicts. #24432 rewrites the same few lines of this filter for a different cause, so whichever lands second needs a small rebase. The growth check then returns null after storing the advanced scan with the previous delivery, as #24432 already does for its other early return.
Screenshots#
Test on main with only the new tests added: the long-item test fails at 10,050,000 stored characters.

Same tests on this branch: all five pass.

Main, during the agent's pause after paragraph 60: the live reasoning shows paragraph 60.

This branch, same moment: the live reasoning shows paragraph 55, the last snapshot that grew by a quarter. The rest appears with the next passed snapshot or the final event.

Android, main, during the same pause: the expanded reasoning ends at paragraph 60.

Android, this branch, same moment: the expanded reasoning ends at paragraph 55.

iOS, main, during the same pause: the expanded reasoning ends at paragraph 60.

iOS, this branch, same moment: the expanded reasoning ends at paragraph 55.

Prior PRs#
- #24267 by juliusmarminge coalesces superseded streaming updates for live delivery. It does not change what is stored.
- #20990 by JustYannicc compacts superseded turn-item snapshots after the fact. It bounds what is kept, not what is written. This PR is complementary.
- #22548 by t3dotgg compacts superseded
provider-turn.updatedevents, a different event type. - #24432 by juliusmarminge makes the same filter resume its Markdown scan instead of reparsing. Different cause, same lines (see above).
- vifar measured the problem and proposed these directions in #23365.
Production fix, tests, PR description and images written with Claude Opus 5.5 in T3 Code Nightly.
🤖 Generated with Claude Opus 5.5 in T3 Code Nightly
- 1
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:S
Approvability#
Verdict: Approved at
62bb46dMacroscope's review found this PR approvable — This is a focused server-side fix that bounds durable snapshot growth for long paragraph streams while preserving short-stream behavior, replacements, and final text. Its only product impact is less frequent intermediate updates for very long streams, which is covered by focused tests.
You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).No actionable comments were generated in the recent review.
Recent review info-
Run configuration-
- Source mode: Auto
- Repository: pingdotgg/t3code
- Branch: main
- File: .coderabbit.config.ts
- Commit: 8045537
- Layers: Repository TS config
- Review profile: CHILL
- Plan: Advanced
- Run ID:
74fe5767-7df0-4f56-ac2a-4844795d62cc
Commits-
Reviewing files that changed from the base of the PR and between 80455376f01f19c10a06dc08b0629486c017bf79 and 62bb46d961929ebb14da3f2d036897b31b254029.
Files selected for processing: 2-
apps/server/src/orchestration-v2/assistantStreaming.test.tsapps/server/src/orchestration-v2/assistantStreaming.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 1 remain after this review.
-
Walkthrough
-
The streaming filter now suppresses some small extensions to cumulative text after the prior snapshot reaches 8,000 characters. Tests cover long and short streams, plus a replacement that is shorter than the previous snapshot.
Changes: Streaming snapshot bounds
Priority:Layer / File(s) Summary Filter long cumulative snapshots
apps/server/src/orchestration-v2/assistantStreaming.tsThe filter suppresses an extending snapshot when the previous text is at least 8,000 characters and the new text is less than 1.25 times its length. Test snapshot filtering
apps/server/src/orchestration-v2/assistantStreaming.test.tsTests check cumulative snapshot volume, retention of short-stream snapshots, and passage of replacement text. NormalEstimated code review effort: 2 (Simple) | ~10 minutes
Change: Bug fix · Severity of issue fixed: Medium
Possibly related issues
pingdotgg/t3code#24120— Fewer long streamed snapshots may reduce the frequency of timeline derivation, but this change does not remove the client-side full rebuild.
Possibly related PRs
- pingdotgg/t3code#24432 — Changes the same streaming filter path and can be combined with this filter behavior.
- pingdotgg/t3code#24145 — Reduces orchestration writes through batching and projection-write changes, complementing this reduction in streamed snapshots.
- pingdotgg/t3code#24663 — Coalesces Cursor text deltas before they reach the server filter, complementing this filter’s snapshot suppression.
Suggested labels:
bugfix,size:SSuggested reviewers:
t3dotgg,maria-rcks
Merge Risk:
Minimal · up to62bb4-
The change bounds intermediate snapshots without established impact to final streamed content or availability.
Pre-merge checks:
4-
Check name Status Explanation Title check The title is concise, specific, and accurately describes the main server change: reducing durable full-text snapshots during long streams. Description check The description includes all required sections and provides detailed problem context, implementation scope, verification results, screenshots, limitations, and related issue references. It clearly sta… Linked Issues check Issue #23365requires bounded durable snapshots for paragraph streaming.assistantStreaming.tskeeps the 400 ms gate and paragraph boundaries, then suppresses prefix-growing snapshots below 1.25 tim…Out of Scope Changes check The reviewed changes are limited to assistantStreaming.tsand its focused test file. The production change modifies assistant and reasoning streaming snapshot filtering. The tests verify the request…Full details: Description check
-
Explanation
The description includes all required sections and provides detailed problem context, implementation scope, verification results, screenshots, limitations, and related issue references. It clearly states that maintainer approval is still pending.
Full details: Linked Issues check
-
Explanation
Issue
#23365requires bounded durable snapshots for paragraph streaming.assistantStreaming.tskeeps the 400 ms gate and paragraph boundaries, then suppresses prefix-growing snapshots below 1.25 times the previous delivered text after 8,000 characters. Non-streaming events still clear the filter state and pass unchanged. The new tests cover linear stored snapshot size, unchanged short-item behavior, and non-prefix replacement behavior. These changes implement the issue's bounded-intermediate-persistence direction.
Full details: Out of Scope Changes check
-
Explanation
The reviewed changes are limited to
assistantStreaming.tsand its focused test file. The production change modifies assistant and reasoning streaming snapshot filtering. The tests verify the requested storage bound and existing streaming behavior. No unrelated change is demonstrated.
-
Finishing Touches
-
🧪 Generate unit tests (beta)
-
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
-
juliusmarminge added labelsbugfix
juliusmarminge added labelspr:needs-julius
closing at @StiensWout's request under Establish the problem and scope first.
Intentionally changes paragraph streaming and interrupted-stream durability: after 8,000 characters, snapshots wait for 25 percent growth, and a missing final event can lose up to a fifth of the item. The linked issue has no maintainer triage or approval for this substantive behavioral tradeoff.
Have maintainers triage the storage failure and explicitly agree on streaming cadence and missing-final-event durability, then link that approved scope.
thanks for trying to help improve t3 code. if you think this closure was a mistake, please open a fresh pr addressing the requirement above, and link back to this one.
juliusmarminge removed labelspr:needs-julius
Sign in to join this conversation.
macroscopeapp[bot](GitHub profile, opens in a new tab) approved these changes