Skip to content
Source
Sign inSign up
pingdotgg/t3code

perf(server): fork threads load faster when local turns fill the first page #20104

Mergedjuliusmarmingemerged 11 commits intomain fromrefs/pull/20104/headmerged by juliusmarminge View on GitHub

juliusmarmingecommented

Opening 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.ts covers 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.ts and ThreadStream.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.

MetricMainThis PR
Median request time18.56 ms12.37 ms
Median CPU time per request19.78 ms13.25 ms
Parent payload bodies parsed per request240

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

    2. juliusmarminge added labelsmacroscope-review

    3. macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      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).
    4. github-actions[bot](GitHub profile, opens in a new tab)commented

      Thread transfer impact

      ✅ Thread transfer remains within every enforced ceiling.

      ProviderMetricMain baselineThis PRImpactPR ceiling
      CodexTotal thread wire5.0 KiB5.0 KiB+7 B (+0.1%)6.8 KiB✅
      CodexThread snapshot wire3.8 KiB3.8 KiB0 B (0.0%)4.9 KiB✅
      CodexLive turn WebSocket wire1.2 KiB1.2 KiB+7 B (+0.6%)2.0 KiB✅
      CodexLive turn WebSocket decoded20.9 KiB20.9 KiB0 B (0.0%)29.3 KiB✅
      CodexLive turn messages220 (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.2 KiB21.2 KiB0 B (0.0%)29.3 KiB✅
      ClaudeLive turn messages220 (0.0%)8✅

      Baseline: 293938b · PR result: a39bb76 · 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.

    5. coderabbitai[bot](GitHub profile, opens in a new tab)commented
      Review in Change Stack →

      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.ts
      • apps/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.ts
      A 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.ts
      Eligible 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: Passed 4
      Check nameStatusExplanation
      Title checkPassedThe title clearly and concisely describes the primary performance improvement for fork threads whose local turns fill the first page.
      Description checkPassedThe 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 checkPassedIssue [#18915] requires the filled, initial, unanchored fork page to avoid decoding discarded inherited tool-output payloads. ProjectionStore.ts reuses the retained-row SQL selection for an inherite…
      Out of Scope Changes checkPassedThe 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.ts reuses 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
      Comment `@coderabbitai help` to get the list of available commands.
    6. Taking over this one: merging current main, re-cutting the test to the minimum, and re-reviewing before it lands.

    7. juliusmarminge assignedjuliusmarminge

    8. juliusmarminge merged thisc7f8404

    9. juliusmarminge closed this

Sign in to join this conversation.