perf(server): fork threads load faster when local turns fill the first page #20104
main fromrefs/pull/20104/head·merged by juliusmarminge View on GitHubOpening a fork whose own turns fill the first page still loaded and decoded inherited tool output that the bounded response discarded. This counts the parent's retained rows instead, preserving item positions and history cursors.
The payload read and count share the same retained-row query. The optimization applies only to an initial, unanchored read whose local user turns fill the page and whose parent is not itself a run fork. Partial pages, nested forks and anchored history retain the recursive read.
Fixes #18915. Original work by @bompus in #18071, continued on this maintainer-owned PR.
Verification#
- One regression in the existing
ProjectionStore.test.tscovers partial, filled and nested forks; the PR's added test code is reduced from 176 to 156 lines. All 43 tests from main are unchanged (44 total before and after takeover). - Before: the new regression against current main's implementation gives 43 passed / 1 failed, detecting parent payload parsing. After restoration: 44 passed.
ProjectionStore.test.ts,threadHistoryPaging.test.tsandThreadStream.test.ts: 82 passed. Touched-file lint and formatting pass.- Server
tsc-rs --noEmit -p apps/server/tsconfig.json: passed (Effect suggestions only). - One full-diff adversarial review round by Claude Opus 5.5 and GPT-6-Sol: no blockers. The optional suggestion to split the count-only helper was declined because the shared path already keeps the change small.
Performance proof#
Measured the actual in-process HTTP bounded-snapshot handler with SQLite and synthetic data: 14 parent turns and 14 fork turns, with two 64 KiB command outputs per turn. Three paired runs used 20 warmups and 60 requests per implementation. Every compared response body was identical, including cursors.
| Metric | Main | This PR |
|---|---|---|
| Median request time | 18.56 ms | 12.37 ms |
| Median CPU time per request | 19.78 ms | 13.25 ms |
| Parent payload bodies parsed per request | 24 | 0 |
About 33% less time and CPU in this fixture. Benchmark script · Full output. This is server work with synthetic data; no screenshots apply. Network latency, production data and client rendering were not measured.
Not verified on macOS, Windows, iOS, Android or Electron desktop.
Takeover tests: GPT-6-Astra (high); implementation: GPT-6.1-Sol (high), through the Codex harness in T3 Code. Adversarial review: Claude Opus 5.5 through Claude Code and GPT-6-Sol through Codex.
- 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
juliusmarminge added labelsmacroscope-review
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 +7 B (+0.1%) 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 +7 B (+0.6%) 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 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.2 KiB 21.2 KiB 0 B (0.0%) 29.3 KiB ✅ Claude Live turn messages 2 2 0 (0.0%) 8 ✅ Baseline:
293938b· PR result:a39bb76· 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
-
- Configuration used: Path: .coderabbit.config.ts
- Review profile: CHILL
- Plan: Team
- Run ID:
cb5bfb87-f8e6-424b-a853-3a2db7ca9796
📥 Commits
-
Reviewing files that changed from the base of the PR and between b2e45497248b1f51a2b5d56d7ea5d6d0d966d4ad and a39bb7660b31b5f131667f59cb3cb2c9cd4c885c.
📒 Files selected for processing: 2
-
apps/server/src/orchestration-v2/ProjectionStore.test.tsapps/server/src/orchestration-v2/ProjectionStore.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 0 remain after this review.
-
📝 Walkthrough
-
Bounded fork snapshots now count retained parent rows instead of decoding parent payloads when local turns fill the page. The count offsets local item positions. Tests cover partial pages, full pages, and nested forks.
Changes: Fork snapshot paging
Layer / File(s) Summary Retained-window selection
apps/server/src/orchestration-v2/ProjectionStore.tsA shared query selects retained rows for bounded projection reads and inherited-row counting. Fork row counting and positions
apps/server/src/orchestration-v2/ProjectionStore.ts,apps/server/src/orchestration-v2/ProjectionStore.test.tsEligible fork reads count retained source rows and use the count to position visible items. Tests compare bounded results with full snapshots across partial pages, full pages, and nested forks. Priority: ⬇️ Low
Estimated code review effort: 3 (Moderate) | ~20 minutes
Change: Refactor · Severity of issue fixed: Low
Suggested reviewers:
t3dotgg
Merge Risk: ⚪ Minimal · up to
a39bb-
The fork paging optimization is mergeable after normal checks; no confirmed behavior regression remains.
Pre-merge checks:
4-
Check name Status Explanation Title check The title clearly and concisely describes the primary performance improvement for fork threads whose local turns fill the first page. Description check The description explains the problem, implementation scope, linked issue, verification results, performance evidence, and unverified environments. It is mostly complete, although it does not use every… Linked Issues check Issue [ #18915] requires the filled, initial, unanchored fork page to avoid decoding discarded inherited tool-output payloads.ProjectionStore.tsreuses the retained-row SQL selection for an inherite…Out of Scope Changes check The changes stay within issue [ #18915]. They refactor the retained-row query, add inherited-row position handling, add the eligible count-only path, and add focused projection tests. These changes sup…Full details: Description check
-
Explanation
The description explains the problem, implementation scope, linked issue, verification results, performance evidence, and unverified environments. It is mostly complete, although it does not use every template heading and does not include an explicit maintainer approval comment.
Full details: Linked Issues check
-
Explanation
Issue [
#18915] requires the filled, initial, unanchored fork page to avoid decoding discarded inherited tool-output payloads.ProjectionStore.tsreuses the retained-row SQL selection for an inherited count and builds visible rows with the inherited offset. The recursive path remains for partial pages, anchored reads, nested forks, and run-forked parents. The added regression covers partial, filled, and nested forks, plus bounded output and cursor behavior.
Full details: Out of Scope Changes check
-
Explanation
The changes stay within issue [
#18915]. They refactor the retained-row query, add inherited-row position handling, add the eligible count-only path, and add focused projection tests. These changes support the requested server optimization and its behavior guarantees. No unrelated product changes are shown.
-
✨ 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
-
Taking over this one: merging current main, re-cutting the test to the minimum, and re-reviewing before it lands.
juliusmarminge assignedjuliusmarminge
juliusmarminge merged thisc7f8404
juliusmarminge closed this
Sign in to join this conversation.
Approvability#
Verdict: Needs Human Approval
Macroscope's review found this PR requires human approval — This production optimization adds an automatic fast path that skips recursive ancestor payload reads when a fork’s local turns fill the first page, while reconstructing positions and cursors from a SQL count. The behavior is narrowly tested, but the data-dependent suppression of existing processing warrants human review.
You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).