fix(server): long agent turns no longer load whole when a thread opens #24589
main fromrefs/pull/24589/head·merged by t3dotgg(GitHub profile, opens in a new tab) View on GitHubProblem#
A thread with any user turn loaded its last 10 user turns with no row or byte limit. One long agent turn could put thousands of rows into a single cold open: #24142 reports 10,454 rows (86 MB stored) that froze the client. No test capped what web and mobile actually load.
Fix#
- Every history window stops at the 1 MiB byte budget. A window that holds a user turn also stops at 10 user turns (20 on older pages) or 500 rows, so ordinary turns stay whole, as V1's 500-activity cap kept them. Inside one turn longer than 500 rows, the window pages with the existing 75-row budget. The snapshot query applies the same rule before it decodes payloads.
- Builds on #24169 by @luke2x, with their commits kept: budgets inside human turns, interrupt requests that travel with their results, targeted pages that keep their target, and the thread-cache version bump that drops oversized cached snapshots. This PR raises the in-turn cap from 75 to 500 rows so that ordinary threads still open whole.
- New CI cap on the real client path. The transfer budget test opens a thread whose last user turn holds 900 rows (reasoning, commands, file changes, MCP calls, progress messages, checkpoints, subagents) through
/bounded?compactTurnItems=1, then loads one older page. It caps decoded bytes (120 KB) and rows (75). On main this cold open carried all 920 rows, 1.07 MB decoded, and the test fails. - Removed
payloadBudgetExceeded. No client read it, and it cost an extra full encode for each bounded snapshot. The field was optional in the contract, so older clients do not notice, and newer clients drop it when an older server sends it. - The old-client
getThreadProjectionpath now strips tool bodies before it applies the byte budget. docs/internals/performance-regressions.mdnow describes the real window rules and lists the bodies that still ship.
Real data#
Compact bounded cold open (/bounded?compactTurnItems=1) for 1,321 threads in a maintainer's real database, measured with the real server code. Sizes are decoded JSON.
| Policy | p50 | p90 | p99 | max | max rows | over 1 MiB | opens with older history |
|---|---|---|---|---|---|---|---|
| main | 67 KB | 281 KB | 1.42 MB | 5.24 MB | 1,754 | 20 | 189 |
| 75 rows everywhere (#24169) | 67 KB | 262 KB | 338 KB | 1.77 MB | 75 | 1 | 302 |
| this PR | 67 KB | 281 KB | 768 KB | 2.35 MB | 286 | 3 | 218 |
This PR changes the rows of 33 threads (2.5%) and newly splits 29 of them. Every other thread keeps the same rows. The 75-row policy changes 154 threads and newly splits 113.
Known gap: control records (nodes, runs, checkpoints, subagents) follow the up to 502 rows the snapshot query loads, not the rows that ship. On the three largest split threads that leaves about 0.2 to 1 MB of extra control data. Pruning control records to the shipped window is a follow-up.
Verification#
vp run test:perf:v2-wire: 16 files, 242 tests passed.vp test run apps/server/integration/transferBudgetV2.integration.test.tspasses, and fails on main.vp run check:changedpasses.- Not run in a real client. Threads with a turn longer than 500 rows now open at their newest rows and load older rows on scroll, like agent-driven threads already do. Opening inside a folded "Worked for" group can still hit #21957.
Fixes #24142. Supersedes #24169.
Made with Claude Opus 5.5 in Claude Code, running in T3 Code.
🤖 Generated with Claude Code
- 1
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
Thread transfer impact#
✅ Thread transfer remains within every enforced ceiling.
Provider Metric Main baseline This PR Impact PR ceiling Codex Total thread wire 5.0 KiB 5.0 KiB 0 B (0.0%) 6.8 KiB ✅ Codex Thread snapshot wire 3.8 KiB 3.8 KiB 0 B (0.0%) 4.9 KiB ✅ Codex Live turn WebSocket wire 1.2 KiB 1.2 KiB 0 B (0.0%) 2.0 KiB ✅ Codex Live turn WebSocket decoded 20.9 KiB 20.9 KiB 0 B (0.0%) 29.3 KiB ✅ Codex Live turn messages 2 2 0 (0.0%) 8 ✅ Claude Total thread wire 5.0 KiB 5.0 KiB +24 B (+0.5%) 6.8 KiB ✅ Claude Thread snapshot wire 3.8 KiB 3.8 KiB 0 B (0.0%) 4.9 KiB ✅ Claude Live turn WebSocket wire 1.2 KiB 1.2 KiB +24 B (+2.0%) 2.0 KiB ✅ Claude Live turn WebSocket decoded 21.2 KiB 21.2 KiB +41 B (+0.2%) 29.3 KiB ✅ Claude Live turn messages 1 2 +1 (+100.0%) 8 ✅ Baseline:
3cc31ed· PR result:944fe09· Source CI: successScenario and decoded snapshot size
10 historical turns, 5 command tools per turn, 878.9 KiB retained MCP result per historical turn, and a 1.05 MiB retained result in the measured turn.
- Codex decoded thread snapshot: 108.5 KiB
- Claude decoded thread snapshot: 108.8 KiB
Updated in place by a trusted workflow. PR artifacts are strictly validated and never executed.
No actionable comments were generated in the recent review.
Recent review info-
Run configuration-
- Source mode: Auto
- Repository: pingdotgg/t3code
- Branch: t3/aa846120
- File: .coderabbit.config.ts
- Commit: 944fe09
- Layers: Repository TS config
- Review profile: CHILL
- Plan: Team
- Run ID:
f0784791-cdc7-450a-8b92-4ca1a5464248
Commits-
Reviewing files that changed from the base of the PR and between 3cc31ed27c8956b36cee35a50509fb7c6869592b and 944fe094a8c9c15d1e989f010c6efbd411b3ed2e.
Files selected for processing: 18-
apps/server/integration/TransferBudgetReport.integration.tsapps/server/integration/TransferBudgetV2Fixture.integration.tsapps/server/integration/transferBudgetV2.integration.test.tsapps/server/src/orchestration-v2/ProjectionStore.test.tsapps/server/src/orchestration-v2/ProjectionStore.tsapps/server/src/orchestration-v2/ThreadFind.test.tsapps/server/src/orchestration-v2/ThreadStream.test.tsapps/server/src/orchestration-v2/ThreadStream.tsapps/server/src/orchestration-v2/threadHistoryPaging.test.tsapps/server/src/orchestration-v2/threadHistoryPaging.tsapps/server/src/ws.tsdocs/internals/performance-regressions.mdpackages/client-runtime/src/platform/orchestrationCache.test.tspackages/client-runtime/src/platform/orchestrationCache.tspackages/client-runtime/src/state/boundedThreadSnapshotHttp.test.tspackages/client-runtime/src/state/threads-atoms.test.tspackages/client-runtime/src/state/threads-sync.test.tspackages/contracts/src/orchestrationV2.ts
Files with no reviewable changes: 5-
- packages/client-runtime/src/state/boundedThreadSnapshotHttp.test.ts
- apps/server/src/orchestration-v2/ThreadStream.test.ts
- packages/client-runtime/src/state/threads-atoms.test.ts
- apps/server/src/orchestration-v2/ThreadStream.ts
- packages/contracts/src/orchestrationV2.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.
-
Walkthrough
-
History snapshots and older pages now enforce row and encoded-byte bounds across human turns, while retaining cursor access to older items and required interrupt requests. The PR adds long-turn integration measurements, removes the
payloadBudgetExceededfield from snapshot contracts, and increments the client cache schema version.Changes: Bounded Thread History
Priority:Layer / File(s) Summary Paging limits and cursor rules
apps/server/src/orchestration-v2/threadHistoryPaging.ts,apps/server/src/orchestration-v2/threadHistoryPaging.test.ts,apps/server/src/orchestration-v2/ThreadFind.test.tsPaging now applies row and encoded-byte limits to user-turn windows and pages inside long turns. Older-page selection can widen its policy to reach a target. Tests cover long turns, oversized items, and paging limits. Snapshot and history selection
apps/server/src/orchestration-v2/ProjectionStore.ts,apps/server/src/orchestration-v2/ProjectionStore.test.tsSQL and in-memory projection paths cap snapshot rows and apply bounded policies to history pages. Pages include matching interrupt requests when needed. Tests cover byte-bounded traversal, targeted pages, and row limits. Snapshot contract and cache version
apps/server/src/ws.ts,apps/server/src/orchestration-v2/ThreadStream.ts,apps/server/src/orchestration-v2/ThreadStream.test.ts,packages/contracts/src/orchestrationV2.ts,packages/client-runtime/src/platform/orchestrationCache.ts,packages/client-runtime/src/platform/orchestrationCache.test.ts,packages/client-runtime/src/state/*Snapshot wire projection occurs before bounding. The snapshot contract no longer includes payloadBudgetExceeded, and the client cache schema version changes to 5. Client tests cover rejecting older cached snapshots and loading a fresh snapshot.Long-turn integration measurement
apps/server/integration/TransferBudgetV2Fixture.integration.ts,apps/server/integration/transferBudgetV2.integration.test.ts,apps/server/integration/TransferBudgetReport.integration.ts,docs/internals/performance-regressions.mdThe integration fixture adds a 900-row turn. The test measures its bounded snapshot and an older history page. The report checks decoded bytes and row counts against long-turn limits; the performance notes describe the bounds and wire contents. NormalEstimated code review effort: 4 (Complex) | ~45 minutes
Change: Bug fix · Severity of issue fixed: Medium
Sequence Diagram(s)#
sequenceDiagram participant TransferBudgetIntegrationTest participant HTTPServer participant ProjectionStore participant ThreadHistoryPaging TransferBudgetIntegrationTest->>HTTPServer: request bounded snapshot HTTPServer->>ProjectionStore: load bounded thread projection ProjectionStore-->>HTTPServer: snapshot and history cursor HTTPServer-->>TransferBudgetIntegrationTest: return snapshot TransferBudgetIntegrationTest->>HTTPServer: request older page with cursor HTTPServer->>ProjectionStore: load history page ProjectionStore->>ThreadHistoryPaging: select rows within page policy ProjectionStore-->>HTTPServer: page and hasMoreHistory HTTPServer-->>TransferBudgetIntegrationTest: return history pagePossibly related issues
- pingdotgg/t3code#24142 — The issue describes human-turn history bypassing row and byte limits, which this PR addresses in snapshot selection and history paging.
Suggested labels:
bugfix,size:LSuggested reviewers:
juliusmarminge,maria-rcks
Merge Risk:
Minimal · up to944fe-
No merge-blocking issue was established; the change is mergeable after normal checks.
Pre-merge checks:
4-
Check name Status Explanation Title check The title clearly and concisely describes the primary change: preventing long agent turns from loading completely when a thread opens. Description check The description covers the problem, implementation, scope, linked issues, measured impact, verification results, known gaps, and test limitations. The “Fix” heading serves the template’s Change sectio… Linked Issues check For open issue #24142, the PR applies row and encoded-byte limits to user-turn windows inthreadHistoryPaging.ts, including the 500-row in-turn limit and the 75-row limit inside longer turns. `Proje…Out of Scope Changes check The changes stay within #24142. The transfer-budget fixtures and tests verify the bounded client path. Cache schema invalidation addresses oversized snapshots created by the bypass. The wire-contract …Full details: Description check
-
Explanation
The description covers the problem, implementation, scope, linked issues, measured impact, verification results, known gaps, and test limitations. The “Fix” heading serves the template’s Change section.
Full details: Linked Issues check
-
Explanation
For open issue
#24142, the PR applies row and encoded-byte limits to user-turn windows inthreadHistoryPaging.ts, including the 500-row in-turn limit and the 75-row limit inside longer turns.ProjectionStore.tsapplies the corresponding limit before payload decoding for SQL and in-memory snapshots. The history path now applies the byte pass, preserves interrupt requests with their results, and preserves targeted-page reachability.ProjectionStore.test.tsverifies byte-bounded paging, exact recovery of 1,000 items without duplicates, targeted pages, and interrupt request retention. The transfer-budget integration test covers a 900-row turn on the client transfer path.
Full details: Out of Scope Changes check
-
Explanation
The changes stay within
#24142. The transfer-budget fixtures and tests verify the bounded client path. Cache schema invalidation addresses oversized snapshots created by the bypass. The wire-contract removal of unusedpayloadBudgetExceeded, old-client projection ordering, documentation updates, and related fixture updates support the same history-budget behavior. No unrelated product behavior is demonstrated.
-
Finishing Touches
-
📝 Generate docstrings
-
- Commit to this branch
- Create a new PR
🧪 Generate unit tests (beta)
-
- Commit to this branch
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
-
t3dotgg(GitHub profile, opens in a new tab) closed this
Sign in to join this conversation.
Approvability#
Verdict: Needs Human Approval
Macroscope's review found this PR requires human approval — This PR changes the default thread-history loading and pagination behavior across server snapshots, older-page requests, WebSocket responses, and client cache invalidation. The cross-cutting runtime change and new default row limits require human review.
You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).