perf(server): checkpoint captures run fewer git commands #42473
main fromrefs/pull/42473/head·merged by juliusmarminge View on GitHubProblem#
A turn-end checkpoint capture runs while the run holds one of the 4 EffectWorker slots, so under many concurrent working threads new turns queue behind captures. A typical root capture ran 15 git processes, and the previous checkpoint was resolved five times along the way: the capture's own log --no-walk, the summary's rev-parse (hasCheckpointRef), then resolveTurnStart once in diffCheckpoints and again in listAuthoredPaths, plus a log --format=%ct %P for the heads. A turn that changed nothing ran all 15, including an empty numstat diff.
Fix#
captureCheckpointnow reads the previous checkpoint once, whether or not a branch switch is being replayed. It returns aVcsCheckpointRangebuilt from what it already knows: where the turn started (the previous commit or its branch-switch turn start), the new commit, the start's commit time, both first-parent heads, and whether the new tree equals the start's tree.CheckpointService.captureSummarizeduses the range in place ofhasCheckpointRef. It also passes the range todiffCheckpointsandlistAuthoredPaths, which then skipresolveTurnStartand the headslog. Callers that pass no range, likeCheckpointDiffQueryand the clean-HEAD repository path, behave exactly as before.- No-change early exit: when the tree equals the start's tree, the diff and authored-paths reads are skipped and the checkpoint records
files: [], as before. - Kept on purpose: the no-change path still runs
commit-treeandupdate-ref. Every turn keeps its own ordinal ref, which restore, rollback, stale-ref cleanup and turn diffs depend on. A fresh commit also keeps that ref's committer time. Pointing the ref at the previous commit would back-date the next turn's start:listAuthoredPathsreads "own commits" as those newer than the start's%ct, so commits made elsewhere during the empty turn would be credited to the next one. The saving would be one process. - Old Git (before 2.31) does not return HEAD from the combined
rev-parse. On that path the parent is resolved explicitly, and only when a range is returned.
Git processes per root capture#
Counted in a new real-git test (CheckpointCaptureService.test.ts, "captures a turn without re-reading the previous checkpoint"). The test wraps VcsProcess and counts commands from after the turn's edits.
| Turn | Before | After |
|---|---|---|
| Edits files, HEAD unchanged | 15 | 11 |
| Changed nothing | 15 | 10 |
| Agent committed (HEAD moved) | 4 more than after | rev-parse and 3 logs fewer |
The test fails on main (it reports the extra rev-parse, log, log, log) and passes with this change.
Verified: the src/orchestration-v2, src/checkpointing and src/vcs suites pass (140 files, 4150 tests), and so do typecheck and vp run check:changed.
🤖 Generated with Claude Code (Claude Opus 5.5, T3 Code)