perf(server): very long threads open about 10x faster #34490
main fromrefs/pull/34490/head·merged by t3dotgg(GitHub profile, opens in a new tab) View on GitHubOpening a very long thread was slow. One real thread (230 turns, 41,000 items, still running) showed "Loading messages..." for a long time. The server read for its first page walked thousands of tool-call rows and sent 3.15 MB for 77 visible rows.
Two causes:
- The window search walked every tool call. To find the newest conversation rows, the read scanned all rows since the last boundary. Migration 082 adds a partial index over conversation rows, and the search reads from it. A running turn is read from the run index.
- Old todo lists pulled the whole history into every window. A todo list is never closed when its run ends. Each one counted as live work, so every window carried the nodes, subagents, provider turns, plans and checkpoints of old runs. A todo list of a run that is no longer live does not count now.
The window also keeps the newest ready checkpoint always, so the diff of the last finished turn stays available during a long run.
Result#
Measured on a copy of a real 3.7 GB database, old code against this branch, for that thread:
| Before | After | |
|---|---|---|
| First read | 2,230 ms | 31 ms |
| Warm read | 244 ms | 19 ms |
| Wire snapshot | 3.15 MB | 0.39 MB |
| Subagents in the window | 413 | 28 |
Proof#
- Old and new
getThreadSnapshotWindowreturn the same timeline rows for all 625 threads in that database (1,875 reads: cold, cold without deferral, one older page; 0 mismatches). - New assertions in
ProjectionStore.test.tsfail onmain: the VM step count of the tail search stays flat when rows are added, the query plan uses the new index, and stale todo lists do not retain old runs. vp run check:changedpasses.
Visible changes#
- The window no longer carries records that were present only because of a stale todo list. For the thread above, the turn list in the diff panel and in mobile Review shows the turns in the loaded window plus the last finished turn, not 57 older turns. Threads without todo lists already behaved this way.
- A wire page can hold more rows than before, because the other records in it are smaller.
Notes#
- Migration 082 has the same number as the one in #34014. The PR that lands second must take the next number. The two changes do not overlap otherwise.
- Not in this PR: paging to older history and transcript export are still slow on a thread of this size.
Reviewed with sol-loop: 2 passes with GPT-6.1 Sol. Sol verdict: approved
Created with Claude Fable 5.2 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
Approvability#
Verdict: Approved at
5c87054Macroscope's review found this PR approvable — This speeds up long-thread history loading through indexed, bounded reads and avoids pulling settled todo-list runs into every window. The migration only adds an index; stored history and product defaults are unchanged.
You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).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 21.5 KiB 21.5 KiB 0 B (0.0%) 24.4 KiB ✅ Codex Live turn messages 1 1 0 (0.0%) 8 ✅ Claude Total thread wire 5.0 KiB 5.0 KiB 0 B (0.0%) 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 0 B (0.0%) 2.0 KiB ✅ Claude Live turn WebSocket decoded 21.9 KiB 21.9 KiB 0 B (0.0%) 24.4 KiB ✅ Claude Live turn messages 1 1 0 (0.0%) 8 ✅ Baseline:
60efd7c· PR result:5c87054· 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.
Walkthrough
-
The projection store changes bounded history selection and windowed snapshot contents. Migration 82 adds a partial conversation index, and migration tests include it in the expected sequence.
Changes: Projection Reads
Layer / File(s) Summary Bounded history selection and index
apps/server/src/orchestration-v2/ProjectionStore.ts,apps/server/src/orchestration-v2/ProjectionStore.test.ts,apps/server/src/persistence/Migrations.ts,apps/server/src/persistence/Migrations/082_TurnItemConversationIndex.ts,apps/server/src/persistence/reconcileV2PreviewMigration.test.tsHistory-window selection accounts for live runs and oversized newest turns. Migration 82 adds and registers a partial conversation index. Tests cover bounded reads and migration expectations. Windowed snapshot contents
apps/server/src/orchestration-v2/ProjectionStore.ts,apps/server/src/orchestration-v2/ProjectionStore.test.tsWindowed reads exclude todo-list nodes from settled runs and adjust message, plan, and checkpoint selection. Tests cover settled and active todo-list nodes, plans, and checkpoints. Estimated code review effort: 3 (Moderate) | ~25 minutes
Change: Bug fix
Possibly related issues
pingdotgg/t3code#29468— Reports slow commands on very long threads. This change optimizes long-thread projection reads, but command-specific reads remain outside its stated scope.pingdotgg/t3code#20427— Reports slow older-history paging. This change adjusts initial long-thread window selection but does not address the reported older-page rebuilding.pingdotgg/t3code#23000— Reports slow thread-shell and recovery reads on large V2 databases. This change modifies projection reads and adds an index for conversation-row tail searches, which partially overlaps that read-performance area.
Suggested reviewers:
juliusmarminge
Merge Risk:
Low · up to5c870-
This change adds an index and narrows what long-thread reads load, with no defect found at this head. The only concern is a migration number clash with another open PR, which the PR description already flags. Whichever PR merges second must take the next free number, or databases upgraded by the first build will fail the second build's migration-history check.
Pre-merge checks:
4-
Check name Status Explanation Title check The title clearly and concisely describes the primary change: improving performance when opening very long threads. Description check The description clearly covers the problem, implementation changes, measured results, verification, visible behavior, and out-of-scope work. It does not include a direct triaged issue or maintainer ap… Linked Issues check Check skipped because no linked issues were found for this pull request. Out of Scope Changes check Check skipped because no linked issues were found for this pull request. Full details: Description check
-
Explanation
The description clearly covers the problem, implementation changes, measured results, verification, visible behavior, and out-of-scope work. It does not include a direct triaged issue or maintainer approval link, but the overall description is detailed and mostly complete.
-
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
-
Additional comments: 1-
apps/server/src/persistence/Migrations.ts-172-172: 1
-
172-172: Major · Data Integrity & Integration · Quick win **Unverified finding** Verification ran but could not confirm this finding. It is shown for review, not as a verified issue.Resolve the competing migration ID before merge.
PR
#34014also assigns ID 82, but toTurnItemInlineWorkOutput. If that migration runs first, this build records a different name for ID 82 andassertV2MigrationsCanRunrejects the database before applying this index. The opposite merge order creates the same conflict for the other build. Assign the second migration the next unused ID and update its sequence assertions. (github.com)
-
Review info-
Run configuration-
- Source mode: Auto
- Repository: pingdotgg/t3code
- Branch: t3/fix-slow-thread-loading
- File: .coderabbit.config.ts
- Commit: 5c87054
- Layers: Repository TS config
- Review profile: CHILL
- Plan: Team
- Run ID:
3b91c940-4432-4fe2-b528-9e4b61b52ee1
Commits-
Reviewing files that changed from the base of the PR and between 60efd7c8697d409a629672966f523f33f51aac4f and 5c870548c45f506093b9210cae53c99b68d93593.
Files selected for processing: 5-
apps/server/src/orchestration-v2/ProjectionStore.test.tsapps/server/src/orchestration-v2/ProjectionStore.tsapps/server/src/persistence/Migrations.tsapps/server/src/persistence/Migrations/082_TurnItemConversationIndex.tsapps/server/src/persistence/reconcileV2PreviewMigration.test.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
-
-
t3dotgg(GitHub profile, opens in a new tab) closed this
Note
🤖 Claude Fable 5.2 responding on behalf of Theo
The wire-level regression test for this fix is merged: https://github.com/pingdotgg/t3code/pull/34522 (merge commit 06bd84623b). The transfer budget test now caps the bounded snapshot of a long thread whose finished runs left their todo lists open. I verified it before the merge: the case passes on
mainand fails on all six caps whentodoListOfSettledRunis disabled.
Sign in to join this conversation.
macroscopeapp[bot](GitHub profile, opens in a new tab) approved these changes