perf(server): sending to a very long thread reads about 5x less of its history #35130
main fromrefs/pull/35130/head·merged by t3dotgg(GitHub profile, opens in a new tab) View on GitHubSending 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:
| Thread | Read per send, before | After | Warm time, before | After |
|---|---|---|---|---|
| 59,000 turn items, 54,000 nodes | 417 MB | 79 MB | 320 ms | 165 ms |
| 75,000 turn items | 461 MB | 43 MB | 220 ms | 90 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.
Related#
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
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
Approvability#
Verdict: Approved at
384e41aMacroscope'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).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
mainmeasurement shown below.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:
b68aedf· PR result:384e41a· 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.
t3dotgg(GitHub profile, opens in a new tab) closed this
Sign in to join this conversation.
macroscopeapp[bot](GitHub profile, opens in a new tab) approved these changes