Repository navigation
perf(worktrees): speed up concurrent partial-clone creation - #167944
Conversation
Share hydration through the existing default-base preparation and bounded Git-worker cache, with a fresh key for each creation group. Preserve checks for changed commits, replacement refs, and later preparation groups. Hydrate before local-main fast-forward and disable checkout lazy fetching. A 40-create synthetic partial-clone run with 52,000 files and 4,700 packs reduced missing-object scans from 40 to 1 and median creation from 113.4s to 66.0s. Cover partial-clone fast-forward and preparation invalidation; validate focused suites and the complete changed-file gate remotely.
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs changes before merge. What this changesManaged worktrees are isolated Git checkouts for agent sessions; this PR shares missing-object preparation across concurrent creations and downloads required files before advancing the local default branch. Example: Create a default-base worktree from a partial clone whose remote main adds large.txt.
Review scores
ProductKind: Performance · Worth it: Yes Merge readiness⛔ Needs changes before merge - 1 item remains This PR provides a measured, distinct improvement that current main still needs. The production approach is coherent, but one existing test fails because the preparation result gained a private field. Priority: P2 Before merge
Findings
Tests
Agent review detailsHow this fits togetherManaged worktree creation turns repository and session requests into isolated, owned Git checkouts. Its preparation path selects a base, downloads required objects, checks capacity, registers the branch, and materializes files. flowchart TD
A[Concurrent creation requests] --> B[Shared default-base preparation]
B --> C[Git worker downloads missing objects]
C --> D[Safely advance local default]
D --> E[Register checkout and capture commit]
E --> F{Same prepared commit?}
F -->|Yes| G[Reuse preparation and materialize files]
F -->|No| C
Technical reviewBest possible solution: Keep generation-scoped sharing within the existing preparation and Git-worker owners, with registration determining the final checkout commit. Do we have a high-confidence way to reproduce the issue? Yes: current-main source advances the local default before hydrating missing blobs, and the supplied native-Git negative control fails at the local-main commit assertion. This review inspected the source and CI evidence without executing target code. Is this the best way to solve the issue? Yes: the patch reuses existing preparation and sizing owners, preserves commit-specific admission and replacement-ref checks, and leaves explicit-base and restore hydration intact. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against d6158cc48033. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceAcceptance criteria:
What I checked:
Likely related people:
PR surfaceSource +31, Tests +25, Docs 0. Total +56 across 10 files. Added test files: 0. View PR surface stats
Review metrics
LabelsLabel changes:
Label justifications:
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment HistoryReview history (1 earlier review cycle)
Reviewed October 9, 2026, 4:04 PM ET / 20:04 UTC (Revision 2). |
…#167944) * perf(worktrees): speed up concurrent partial-clone creation Share hydration through the existing default-base preparation and bounded Git-worker cache, with a fresh key for each creation group. Preserve checks for changed commits, replacement refs, and later preparation groups. Hydrate before local-main fast-forward and disable checkout lazy fetching. A 40-create synthetic partial-clone run with 52,000 files and 4,700 packs reduced missing-object scans from 40 to 1 and median creation from 113.4s to 66.0s. Cover partial-clone fast-forward and preparation invalidation; validate focused suites and the complete changed-file gate remotely. * test(worktrees): allow private base preparation metadata
What Problem This Solves
Concurrent worktree creations in a partial clone repeatedly scan the same missing-object inventory. In a synthetic repository with 52,000 files and 4,700 packs, 40 creations spent 88.6 seconds of Git process time repeating that scan. Local main also tried to fast-forward before the new base's blobs were available.
Related: #167691.
User Impact
Concurrent default-base creations share object preparation before local main advances. Worktree materialization cannot start a lazy fetch. Failed prefetches report the missing-object count. Existing explicit-base and restore behavior stays under the same capacity owner; no configuration or schema migration is required.
Why This Change Was Made
The existing shared base preparation assigns a fresh generation key. The existing bounded Git-worker cache reuses hydration only for that generation, repository identity, and commit, with replacement refs still checked on each call. New generations and changed commits recheck missing objects; replacement refs retain full preparation. Registration continues to own the actual checkout commit.
Production LOC: +31 (excluding tests and docs). The growth threads the creation generation through the existing worker contract and preserves new-generation missing-object detection and replacement-ref sizing, plus the requested failure warning and no-lazy-fetch boundary. There is no second hydration implementation, queue, cache, or persistent state.
Evidence
Blacksmith Testbox (
blacksmith-testbox, profileopenclaw-check), leasetbx_01m4gwng8xdg3wavd47gv6gjmd, Git 2.55.0 / Node 24.19.0. Both runs used 40 simultaneous calls to the realManagedWorktreeService.create, 52,000 tracked files, 4,700 initial packs, and a base move leaving 130 blobs missing. Every checkout's commit and representative changed/unchanged contents were verified.Median creation improved 1.72× and p95 1.78×. Parent Node peak RSS was approximately 8.34 → 7.98 GiB (cumulative process high-water marks; Git children excluded). This is a synthetic
file://promisor remote, not a WAN or saturated production-host reproduction. Neither measured version hit the reported 300-second timeout. The measured win is eliminating repeated inventory work; filesystem checkout and lifecycle waits remain.The partial-clone regression fails on the original code because local main remains at the old commit after successful worktree creation. The final candidate passed eight focused suites (181 passed, one platform skip), including shared fetch/cancellation, capacity, creation, profiles, source-only filters, missing-tip recovery, and Git-worker lifecycle. Independent autoreview found no actionable P0–P2 findings. The moved regression was also confirmed failing at the intended local-main commit assertion against unchanged production source. Final gate and cost evidence:
node scripts/check-changed.mjs --stagedpassed on AWS Crabbox (aws), leasecbx_c8b301d7d065, including all 27 core-test TypeScript graphs, lint, dead-code, docs, and ownership guards. The combined gate/timing payload completed successfully in 37m41s. Testbox had disconnected with exit 255 after 26 graphs; the entire gate was rerun on AWS.pnpm test src/agents/worktrees/service-branches.test.ts --maxWorkers=1: 54 passed, one platform skip; 78.87 s wall time, 58.94 s Vitest duration. This existing real-Git integration suite exceeds 30 seconds; the change only allows the new private preparation fact in its result assertion.pnpm test src/agents/worktrees/capacity.test.ts --maxWorkers=1: 17 passed; 29.13 s wall time, 26.28 s Vitest duration. The new regression reuses the partial-clone fixture and exercises actual Git hydration and fast-forward behavior.The 40-creation benchmark ran with
node --import ./scripts/tsx.mjs .local/lane715/benchmark.mts. Focused proof usednode scripts/run-vitest.mjsforservice-branches,capacity,service,service.source-only-filters,service.profiles,service.capacity,git-fetch, andsrc/infra/git-worker.lifecycle.test.ts.Remote validation used base
3e9038981322; the publication rebase was patch-identical (git range-diffmatched), with no overlapping production changes in this patch.CI found one additional exact-object assertion in
git.test.tsthat rejected the new private preparation key. It now matches the four meaningful base fields while retaining serialization, exact fetch arguments/count, and unrelated-ref preservation checks. No production code changed in this correction.Repair proof on AWS lease
cbx_85be33641150(Git 2.53.0, Bun 1.4.0):OPENCLAW_VITEST_RUNTIME=bun node scripts/run-vitest.mjs src/agents/worktrees/checkout-apfs.test.ts src/agents/worktrees/git.test.ts src/agents/worktrees/service.gc-performance.test.ts: 37 passed, 9 platform skips; 44.52 s. Bun emitted a nonfatal directory-mismatch diagnostic during teardown; the runner exited 0.pnpm test src/agents/worktrees/git.test.ts --maxWorkers=1: 24 passed, one platform skip; 27.74 s wall time.node scripts/check-changed.mjs --staged: passed for the assertion-only correction, with zero lint warnings/errors. Fresh independent autoreview also passed through P2.Final exact-head CI run passed on
ce2049bcef1ead37d90434e09fd6039c4bf020cain 635 seconds wall time. Summed reported CI test-case times, excluding shared startup:capacity.test.ts3.832 s (17 cases),service-branches.test.ts34.687 s (54 cases), andgit.test.ts0.977 s (24 cases). The landed squash patch matches the reviewed branch patch exactly.