Skip to content
Source
Sign inSign up
pingdotgg/t3code

perf(server): very long threads open about 10x faster #34490

Mergedt3dotgg(GitHub profile, opens in a new tab)merged 0 commits intomain fromrefs/pull/34490/headmerged by t3dotgg(GitHub profile, opens in a new tab) View on GitHub

Opening 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:

  1. 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.
  2. 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:

BeforeAfter
First read2,230 ms31 ms
Warm read244 ms19 ms
Wire snapshot3.15 MB0.39 MB
Subagents in the window41328

Proof

  • Old and new getThreadSnapshotWindow return 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.ts fail on main: 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:changed passes.

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

    2. Approvability

      Verdict: Approved at 5c87054

      Macroscope'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).
    3. Thread transfer impact

      ✅ Thread transfer remains within every enforced ceiling.

      ProviderMetricMain baselineThis PRImpactPR ceiling
      CodexTotal thread wire5.0 KiB5.0 KiB0 B (0.0%)6.8 KiB✅
      CodexThread snapshot wire3.8 KiB3.8 KiB0 B (0.0%)4.9 KiB✅
      CodexLive turn WebSocket wire1.2 KiB1.2 KiB0 B (0.0%)2.0 KiB✅
      CodexLive turn WebSocket decoded21.5 KiB21.5 KiB0 B (0.0%)24.4 KiB✅
      CodexLive turn messages110 (0.0%)8✅
      ClaudeTotal thread wire5.0 KiB5.0 KiB0 B (0.0%)6.8 KiB✅
      ClaudeThread snapshot wire3.8 KiB3.8 KiB0 B (0.0%)4.9 KiB✅
      ClaudeLive turn WebSocket wire1.2 KiB1.2 KiB0 B (0.0%)2.0 KiB✅
      ClaudeLive turn WebSocket decoded21.9 KiB21.9 KiB0 B (0.0%)24.4 KiB✅
      ClaudeLive turn messages110 (0.0%)8✅

      Baseline: 60efd7c · PR result: 5c87054 · Source CI: success

      Scenario 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.

    4. coderabbitai[bot](GitHub profile, opens in a new tab)commented
      Explain Change →
      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.ts
      History-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.ts
      Windowed 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 to 5c870

      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: Passed 4

      Check nameStatusExplanation
      Title checkPassedThe title clearly and concisely describes the primary change: improving performance when opening very long threads.
      Description checkPassedThe 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 checkPassedCheck skipped because no linked issues were found for this pull request.
      Out of Scope Changes checkPassedCheck 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
    5. 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 #34014 also assigns ID 82, but to TurnItemInlineWorkOutput. If that migration runs first, this build records a different name for ID 82 and assertV2MigrationsCanRun rejects 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

      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.ts
      • apps/server/src/orchestration-v2/ProjectionStore.ts
      • apps/server/src/persistence/Migrations.ts
      • apps/server/src/persistence/Migrations/082_TurnItemConversationIndex.ts
      • apps/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.

    6. 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 main and fails on all six caps when todoListOfSettledRun is disabled.

Sign in to join this conversation.