Skip to content

perf(server): runs finish when the provider turn ends, not after checkpoint capture - #41362

Draft
juliusmarminge wants to merge 2 commits into
t3/remove-turn-changed-files-cardfrom
t3/async-turn-checkpoint-capture
Draft

juliusmarminge wants to merge 2 commits into
t3/remove-turn-changed-files-cardfrom
t3/async-turn-checkpoint-capture

Conversation

@juliusmarminge

@juliusmarminge juliusmarminge commented Nov 23, 2026 •

Copy link
Copy Markdown
Member

Problem

A run counted as finished about 1.5 s after the model's last byte. About 700 ms of that is turn-end checkpoint capture (about 10 sequential git commands, then ref lookups, the diff and the authored paths). RunExecutionService wrote a finished turn as waiting and flipped it to completed only after capture. Clients treat waiting as active, so the run looked busy throughout capture. With the files-changed card gone (#41317), nothing in the timeline needs the checkpoint when the turn ends.

Change

  • Run completion: a turn that ends normally is written as completed, with completedAt set to the turn end, in the same commit that enqueues the checkpoint.capture outbox effect. Interrupted and cancelled runs already worked this way.
  • Capture: capture accepts completed runs and only attaches the checkpoint to them. It adds the checkpoint, its turn item, and checkpointId on the run. It no longer moves status or completedAt, and it no longer touches the root node. Runs stored as waiting by older servers still use the old flip.
  • Ordering: commands still order behind the capture. Under main, waiting was a barrier: steers, queued turns and hand-off checks saw an active run until capture committed, so steer deliveries already queued on the thread's effect lane settled first. To keep that:
    • readCommandProjection presents the latest run as waiting to command decisions while its capture effect is pending or running.
    • requeueUnreadSteers and the run-end reactor wait for the capture commit, which repeats the run update.
    • Clients and projections only ever see completed.
  • Lane: the per-thread effect lane already serializes the next turn's start (and its baseline checkpoint), rollback and restore behind the capture. A new test pins it: a start enqueued while a capture is running cannot be claimed until that capture finishes.

Checkpoint readers while capture is pending

  • Diff panel, rewind targets, mobile review: built from checkpoint records, so a pending turn simply has no entry yet. Same as during waiting under main.
  • getTurnDiff: only receives turn counts that clients read from existing checkpoints.
  • Proactive diff panel: already defers until the checkpoint arrives.
  • Timeline (web and mobile): skips checkpoint turn items, so nothing shifts when capture lands.
  • MCP thread read: lists the checkpoint turn item once it exists. No MCP tool reads refs.
  • Rollback: its effect runs on the same lane, after the capture.
  • Fork and merge-back from latest_stable: this source needs a run with a checkpoint. The dispatch now waits for the source's pending capture before it takes any thread lock (capture commits under that lock), so a fork right after a turn starts from that turn.

Behavior changes

  • t3_thread_wait and delegate_task settle at turn end, before capture.
  • A delegated child whose turn ended reports waiting_for_children (not working) while its capture runs.
  • Cancelling a task whose child turn has ended settles it in the cancel's own commit.
  • A send that arrives during the capture window is queued behind the capture, as it was while the run was waiting.
  • If a capture fails permanently, the run stays completed without a checkpoint and the queue stays held. Under main the run stayed waiting.

Scope

Product decision by Julius and Maria: remove the files-changed card and capture turn-end checkpoints asynchronously. Layer 2 of 2, stacked on #41317.

Verification

metric main this PR change 95% interval
pipeline.turnEndMs.median (API stream end → finished run) 1335 ms 929 ms −30% −472 to −148 ms
pipeline.msPerTurn 4506 4542 +1% −406 to 511
pipeline.gcPauseMs 1343 2009 +50% 391 to 1216 (flagged worse)

gcPauseMs is flagged worse with 3 rounds a side. I have not explained it; capture now overlaps the harness's next send. Per-turn time is unchanged.

  • Real web client: dev server with the Replay (dev) provider, in a throwaway git repo with 20k untracked files to make capture slow. The run's completedAt was 08:23:25.563. The client dropped "Stop generation" at 25.977 (about 0.4 s of client latency). Capture then ran for about 30 s in the background and hit the existing 30 s VCS timeout (an error checkpoint, old behavior). The client recorded no timeline layout change after the completion frame.
  • Tests: a new lane-ordering test in RunFinalizationQueue.test.ts. The capture tests now cover a completed run (status and completedAt kept, no node.updated); the legacy waiting cases still cover the flip. Tests and replay-fixture assertions that waited for the waiting event now wait for completed. The replay scenario harness counts a completed run as busy until its checkpoint lands. 18 affected server files pass in an isolated PID namespace (774 tests). vp run check:changed passes: format, lint, knip, typecheck (9 packages), tests (26 files) and the react compiler check.
  • Docs: docs/internals/overview.md "Turn completion and checkpoints" now describes completion before capture and the command-side hold.

Model: Claude Opus 5.5 in Claude Code (T3 Code).

🤖 Generated with Claude Code

…kpoint capture

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot added vouch:trusted Author is trusted by repo permissions or the VOUCHED list. size:L 100-499 changed lines (additions + deletions). labels Nov 23, 2026
@github-actions

github-actions Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Thread transfer impact

✅ Thread transfer remains within every enforced ceiling.

ℹ️ No successful main baseline artifact is available yet. This run establishes the initial measurement.

Provider Metric Main baseline This PR Impact PR ceiling
Codex Total thread wire — 5.0 KiB — 6.8 KiB ✅
Codex Thread snapshot wire — 3.8 KiB — 4.9 KiB ✅
Codex Live turn WebSocket wire — 1.2 KiB — 2.0 KiB ✅
Codex Live turn WebSocket decoded — 21.5 KiB — 24.4 KiB ✅
Codex Live turn messages — 1 — 8 ✅
Claude Total thread wire — 5.0 KiB — 6.8 KiB ✅
Claude Thread snapshot wire — 3.8 KiB — 4.9 KiB ✅
Claude Live turn WebSocket wire — 1.2 KiB — 2.0 KiB ✅
Claude Live turn WebSocket decoded — 21.9 KiB — 24.4 KiB ✅
Claude Live turn messages — 1 — 8 ✅

Other scenarios

No main baseline exists yet for these 64 scenario measurements.

All 64 scenario measurements
Provider Scenario Metric Main baseline This PR Impact PR ceiling
Codex short turn resume WebSocket decoded — 10.5 KiB — 12.7 KiB ✅
Codex short turn resume WebSocket messages — 2 — 2 ✅
Codex long turn running, cold open HTTP decoded — 281.7 KiB — 302.7 KiB ✅
Codex long turn running, cold open rows — 75 — 75 ✅
Codex long turn running, history page HTTP decoded — 92.4 KiB — 107.4 KiB ✅
Codex long turn running, history page rows — 75 — 75 ✅
Codex long turn finished, cold open HTTP decoded — 381.5 KiB — 410.2 KiB ✅
Codex long turn finished, cold open rows — 151 — 151 ✅
Codex long turn finished, socket cold open WebSocket decoded — 381.6 KiB — 410.2 KiB ✅
Codex long turn finished, socket cold open WebSocket messages — 2 — 2 ✅
Codex long turn finished, socket cold open rows — 151 — 151 ✅
Codex long turn finished, work page HTTP decoded — 186.2 KiB — 200.2 KiB ✅
Codex long turn finished, work page rows — 150 — 150 ✅
Codex idle thread resume WebSocket decoded — 65 B — 200 B ✅
Codex idle thread resume WebSocket messages — 1 — 1 ✅
Codex fleet shell snapshot HTTP decoded — 42.4 KiB — 53.7 KiB ✅
Codex fleet shell snapshot rows — 27 — 27 ✅
Codex fleet shell subscribe WebSocket decoded — 65 B — 200 B ✅
Codex fleet shell subscribe WebSocket messages — 1 — 1 ✅
Codex fleet shell resume check HTTP decoded — 18 B — 100 B ✅
Codex fleet shell resume check rows — 0 — 0 ✅
Codex stale shell reload HTTP decoded — 42.4 KiB — 53.7 KiB ✅
Codex stale shell reload rows — 27 — 27 ✅
Codex stale shell resume WebSocket decoded — 140 B — 400 B ✅
Codex stale shell resume WebSocket messages — 2 — 2 ✅
Codex stale todo list cold open HTTP decoded — 72.4 KiB — 83.0 KiB ✅
Codex stale todo list cold open rows — 75 — 75 ✅
Codex stale todo list cold open nodes — 2 — 4 ✅
Codex stale todo list cold open subagents — 2 — 4 ✅
Codex stale todo list cold open plans — 1 — 2 ✅
Codex stale todo list cold open providerTurns — 1 — 2 ✅
Codex stale todo list cold open checkpoints — 1 — 2 ✅
Claude short turn resume WebSocket decoded — 10.6 KiB — 12.7 KiB ✅
Claude short turn resume WebSocket messages — 2 — 2 ✅
Claude long turn running, cold open HTTP decoded — 283.3 KiB — 302.7 KiB ✅
Claude long turn running, cold open rows — 75 — 75 ✅
Claude long turn running, history page HTTP decoded — 93.4 KiB — 107.4 KiB ✅
Claude long turn running, history page rows — 75 — 75 ✅
Claude long turn finished, cold open HTTP decoded — 384.2 KiB — 410.2 KiB ✅
Claude long turn finished, cold open rows — 151 — 151 ✅
Claude long turn finished, socket cold open WebSocket decoded — 384.3 KiB — 410.2 KiB ✅
Claude long turn finished, socket cold open WebSocket messages — 2 — 2 ✅
Claude long turn finished, socket cold open rows — 151 — 151 ✅
Claude long turn finished, work page HTTP decoded — 188.1 KiB — 200.2 KiB ✅
Claude long turn finished, work page rows — 150 — 150 ✅
Claude idle thread resume WebSocket decoded — 66 B — 200 B ✅
Claude idle thread resume WebSocket messages — 1 — 1 ✅
Claude fleet shell snapshot HTTP decoded — 43.0 KiB — 53.7 KiB ✅
Claude fleet shell snapshot rows — 27 — 27 ✅
Claude fleet shell subscribe WebSocket decoded — 66 B — 200 B ✅
Claude fleet shell subscribe WebSocket messages — 1 — 1 ✅
Claude fleet shell resume check HTTP decoded — 18 B — 100 B ✅
Claude fleet shell resume check rows — 0 — 0 ✅
Claude stale shell reload HTTP decoded — 43.0 KiB — 53.7 KiB ✅
Claude stale shell reload rows — 27 — 27 ✅
Claude stale shell resume WebSocket decoded — 140 B — 400 B ✅
Claude stale shell resume WebSocket messages — 2 — 2 ✅
Claude stale todo list cold open HTTP decoded — 73.4 KiB — 83.0 KiB ✅
Claude stale todo list cold open rows — 75 — 75 ✅
Claude stale todo list cold open nodes — 2 — 4 ✅
Claude stale todo list cold open subagents — 2 — 4 ✅
Claude stale todo list cold open plans — 1 — 2 ✅
Claude stale todo list cold open providerTurns — 1 — 2 ✅
Claude stale todo list cold open checkpoints — 1 — 2 ✅

Baseline: unavailable · PR result: 804a974 · 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.

…ttle after capture

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@juliusmarminge

Copy link
Copy Markdown
Member Author

Rerun of the pipeline A/B on an idle cups (load ~1–2), with the merged noise floors from #41370. Merge base 9f24cac vs this head 804a974, ab --only pipeline --rounds 5:

metric before after change 95% interval
pipeline.toRequestMs.median 2618 2640 +1% -57 to 114
pipeline.toRequestMs.p90 2776 2786 +0% -59 to 184
pipeline.turnEndMs.median 1122 812 -28% -368 to -268
pipeline.turnEndMs.p90 1270 1133 -11% -172 to -63 noisy
pipeline.msPerTurn 3985 3734 -6% -383 to -100
pipeline.loopDelayP99Ms 22.2 23.1 +4% -0.7 to 1.7
pipeline.loopDelayMaxMs 47.3 48.1 +2% -113.7 to 36.5 noisy
pipeline.gcPauseMs 1102.7 1051.5 -5% -229 to 164 noisy

The +50% GC pause from the first run does not reproduce: −5%, and the A/A runs mark GC pause too noisy to gate on. Turn end (reply's last byte → finished run) is 28% faster with an interval well clear of zero, and time per turn drops 6%.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:L 100-499 changed lines (additions + deletions). vouch:trusted Author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant