Skip to content
Source
Sign inSign up
pingdotgg/t3code

perf(server): sending to a very long thread reads about 5x less of its history #35130

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

Sending a message to a very long thread could take 16 to 32 seconds, and status changes such as unsnooze waited behind it. Every message.dispatch reads its thread before it plans. On a thread with 59,000 turn items, that read fetched every finished tool call and node only to drop it: 417 MB read from SQLite to return 22,000 rows.

The read now seeks the rows it keeps:

  • Turn items. A type filter that names no tool type reads through the conversation index from migration 082. No new index.
  • Nodes. Settled leaf nodes are skipped through a new expression index.
  • Subagents. Settled tasks are dropped inside their existing index, so their rows (each with a full prompt) stay unread.
  • Context transfers. Commands load only pending ones, and each side seeks a (thread, status) index.
  • Message order. The separate ordering lookup does not run when the loaded items already give the order.

The rows a command gets are the same, except that it no longer loads context transfers that are not pending.

Measured

Copies of two real threads, read through the real store code:

ThreadRead per send, beforeAfterWarm time, beforeAfter
59,000 turn items, 54,000 nodes417 MB79 MB320 ms165 ms
75,000 turn items461 MB43 MB220 ms90 ms

On the 26 GB database these threads live in, the same send touched about 139,000 pages. The new plans touch about 22,000.

One-time cost

Migration 083 builds one index on the nodes table. A full scan of that table took 69 s on the 26 GB database, so the first start after this lands can pause for about that long on a database of that size.

Proof

Old and new store code returned identical JSON for 17 filter combinations on both real threads, apart from the context transfer change. The new plan assertions in ProjectionStore.test.ts fail on main and pass here. vp run check:changed passes.

Not measured: a real send on a live server.

Refs #29468. Builds on #29521 (node index, ordering skip) and #31851 (pending transfers and its test). Most of what a send still reads after this is history of finished subagent work; a follow-up PR will stop commands loading it.

Reviewed with sol-loop: 1 pass with GPT-6.1 Sol. Sol verdict: approved

Created with Claude Fable 5.2 in Claude Code.

🤖 Generated with Claude Code

    1. github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted

    2. Approvability

      Verdict: Approved at 384e41a

      Macroscope's review found this PR approvable — This reduces historical data read during command execution using narrower queries and SQLite indexes. The changes preserve stored conversation data and do not introduce product-default changes or new external effects.

      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.

      ℹ️ The exact PR base did not have a successful artifact. Baseline uses the latest successful main measurement shown below.

      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: b68aedf · PR result: 384e41a · 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.

Sign in to join this conversation.