Skip to content
Source
Sign inSign up
pingdotgg/t3code

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

Mergedjuliusmarmingemerged 2 commits intot3/remove-turn-changed-files-card fromrefs/pull/41362/headmerged by juliusmarminge View on GitHub

juliusmarmingecommented

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

  • Pipeline A/B (node scripts/server-metrics.ts ab --only pipeline --rounds 3, harness at #41282 head 996169f, A = main 65cd644, B = this branch b46422c; the later fork-wait commit does not touch the pipeline path, cups linux-x64):
metricmainthis PRchange95% interval
pipeline.turnEndMs.median (API stream end → finished run)1335 ms929 ms−30%−472 to −148 ms
pipeline.msPerTurn45064542+1%−406 to 511
pipeline.gcPauseMs13432009+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

    1. Pushed60dee93

    2. juliusmarminge merged thise3ac310

    3. juliusmarminge closed this

Sign in to join this conversation.