Repository navigation
fix(worktrees): parallel New Session worktrees are created one at a time - #166060
Conversation
Reserve names, owners, and live-plus-pending capacity under short allocation custody; materialize and set up checkouts under their own mutation leases. Publish atomically and retain custody until rollback settles. Give templates independent persisted build and reader custody, and preserve uncertain native artifacts through existing GC recovery. Reuse state_leases without a schema migration. Existing state loads unchanged. Deterministic owner regressions fail on the original global-lease path; local Git, SQLite, acceleration, source, restore, and eviction checks pass. Five-create isolated sample improves from 24.272s to 9.652s with higher peak RSS. Recovery retains uncertain paths and template readers rather than deleting potentially active native work.
Reclaim dead pending admissions before allocation and reap dead template readers without waiting for another OS boot. Preserve incomplete checkout paths and reject retained explicit names with recovery guidance. Share the existing contention budget across create retries. Keep parallel materialization outside the global lease. Cover restart, owner/name reuse, deadline exhaustion, and the checkout mutation lease used by W16 fault injection tests. No schema or configuration migration.
Preserve current-main index cloning, pack-index repair, and complete cleanup outcomes. Recover dead pending admissions after queued contenders release checkout custody, without changing live-owner refusal or lease ordering. Remove the superseded template touch path, bind stale-GC proof to template custody, and include reservation dependencies in extracted PR wrappers. Existing owner and downstream suites pass; new waiter cases fail before the repair. Core types retain the pinned-main missing gatewayLog error outside this owner.
|
🦞👀 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 maintainer review before merge. Reviewed October 6, 2026, 8:57 PM ET / October 7, 2026, 00:57 UTC (Revision 5). ClawSweeper reviewWhat this changesThe branch allows managed session worktrees to prepare concurrently using persisted capacity reservations, shared template custody, and crash recovery. Merge readiness✅ Ready for maintainer review The PR remains useful and has no actionable findings. The maintainer’s explicit merge approval resolves the previous review’s final decision blocker. Priority: P2 Review scores
Verification
How this fits togetherManaged worktrees give agent sessions separate Git checkouts. Session creation feeds repository and owner selections into this service, which allocates capacity, prepares files, and publishes the checkout for the session. flowchart TD
A[New session requests] --> B[Reserve capacity and identity]
B --> C[Shared source template]
C --> D[Parallel checkout preparation]
D --> E[Atomic publication]
E --> F[Session ready]
D --> G[Failure or crash recovery]
G --> B
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +779, Tests +1143, Docs +4, Other +2. Total +1928 across 46 files. View PR surface stats
Review metrics
Technical reviewBest possible solution: Retain one capacity owner with short reservation and publication custody, independent checkout preparation, and conservative recovery of uncertain artifacts. Do we have a high-confidence way to reproduce the issue? Yes: fetched main holds the global allocation lease around the full creation callback, and the supplied live Gateway comparison demonstrates sequential readiness. This reviewer did not execute a reproduction. Is this the best way to solve the issue? Yes: the patch keeps the existing capacity and worker settlement owners while moving preparation outside global custody; the prior contention defect is repaired. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 7880834c1961. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (4 earlier review cycles)
|
Use the admitted worker database for template reads, writes, and reader custody. Remove the synchronous registry implementation and its nested transaction; migrate test callers to the async owner. Keep transaction and commit admission and native settlement intact. The SQLite worker ratchet falls from 850 T1 operations to 838 (base: 846). A real broker regression fails on the previous implementation when an explicit database differs from the environment default, and passes through the selected worker database after the cutover. Existing schema and retention contracts are unchanged.
Keep allocation recovery available in the extracted PR wrapper without loading the application command runtime. Reuse the existing run-end transaction, lease validation, and recovery kernel; remove the superseded dispatcher registration and consume the central command contract. Exercise allocation recovery in the extracted bootstrap regression and align the GC ranking fixture with its synthetic slot inventory. Both the native PR flow and the upgraded bootstrap test failed on the previous routing; the bootstrap passes after the cutover. No schema, retention, or public command changes.
Share cumulative acquisition time across admission, checkout, and template lease waits. Completed preparation can acquire a free publication lease even after exhausting its contention budget; further contention retains actionable timeout diagnostics. Preserve create cleanup operation diagnostics and the branch-exists refusal for retained sparse checkouts. Correct provisioning test ownership and isolate recovery settlement in project cancellation fixtures without weakening outcome assertions. Add fake-clock regressions that fail before the repair.
|
@clawsweeper approve Maintainer approval: merge this. The design was approved on 2026-10-05; the exact head has a clean ClawSweeper review and green required CI. |
|
🦞👀 Command router queued. I will update this comment with the next step. |
|
Merged via squash.
|
…ime (openclaw#166060) * fix(worktrees): reserve pending slots for parallel creation Reserve names, owners, and live-plus-pending capacity under short allocation custody; materialize and set up checkouts under their own mutation leases. Publish atomically and retain custody until rollback settles. Give templates independent persisted build and reader custody, and preserve uncertain native artifacts through existing GC recovery. Reuse state_leases without a schema migration. Existing state loads unchanged. Deterministic owner regressions fail on the original global-lease path; local Git, SQLite, acceleration, source, restore, and eviction checks pass. Five-create isolated sample improves from 24.272s to 9.652s with higher peak RSS. Recovery retains uncertain paths and template readers rather than deleting potentially active native work. * fix(worktrees): recover custody after creator crashes Reclaim dead pending admissions before allocation and reap dead template readers without waiting for another OS boot. Preserve incomplete checkout paths and reject retained explicit names with recovery guidance. Share the existing contention budget across create retries. Keep parallel materialization outside the global lease. Cover restart, owner/name reuse, deadline exhaustion, and the checkout mutation lease used by W16 fault injection tests. No schema or configuration migration. * fix(worktrees): complete reservation recovery integration Preserve current-main index cloning, pack-index repair, and complete cleanup outcomes. Recover dead pending admissions after queued contenders release checkout custody, without changing live-owner refusal or lease ordering. Remove the superseded template touch path, bind stale-GC proof to template custody, and include reservation dependencies in extracted PR wrappers. Existing owner and downstream suites pass; new waiter cases fail before the repair. Core types retain the pinned-main missing gatewayLog error outside this owner. * fix(worktrees): consolidate template SQL in worker owner Use the admitted worker database for template reads, writes, and reader custody. Remove the synchronous registry implementation and its nested transaction; migrate test callers to the async owner. Keep transaction and commit admission and native settlement intact. The SQLite worker ratchet falls from 850 T1 operations to 838 (base: 846). A real broker regression fails on the previous implementation when an explicit database differs from the environment default, and passes through the selected worker database after the cutover. Existing schema and retention contracts are unchanged. * test(worktrees): route provisioning proof through database broker * fix(worktrees): route pending recovery through provisioning worker Keep allocation recovery available in the extracted PR wrapper without loading the application command runtime. Reuse the existing run-end transaction, lease validation, and recovery kernel; remove the superseded dispatcher registration and consume the central command contract. Exercise allocation recovery in the extracted bootstrap regression and align the GC ranking fixture with its synthetic slot inventory. Both the native PR flow and the upgraded bootstrap test failed on the previous routing; the bootstrap passes after the cutover. No schema, retention, or public command changes. * fix(worktrees): exclude preparation from contention waits Share cumulative acquisition time across admission, checkout, and template lease waits. Completed preparation can acquire a free publication lease even after exhausting its contention budget; further contention retains actionable timeout diagnostics. Preserve create cleanup operation diagnostics and the branch-exists refusal for retained sparse checkouts. Correct provisioning test ownership and isolate recovery settlement in project cancellation fixtures without weakening outcome assertions. Add fake-clock regressions that fail before the repair. * fix(worktrees): keep template validation index read-only
What Problem This Solves
Fixes: managed worktree creation was fully serialized. Every New Session with a worktree held one global
create/capacitylease, across all repositories, for its whole creation: template preparation, materialization, provisioning, publication, and cleanup. Five parallel worktree sessions became ready one after another, at 10 / 18 / 28 / 40 / 55 s with a warm template (31 to 99 s cold), although each native clone takes 1 to 2 s.User Impact
User impact: several worktree sessions started together now prepare in parallel; the last one is ready in about 20 s instead of 55 s. Capacity limits, name and owner dedup, rollback on failure, and eviction protection still hold. After a Gateway crash during creation, abandoned reservations and template readers are reclaimed and later creates proceed. Partially created checkouts are kept for manual recovery.
Why This Change Was Made
allocation.tsheld the global lease through the entire create, and capacity counted only completed live records. Creates now reserve a persisted pending slot under a short lease (capacity counts live and pending slots; name and owner dedup happen at reservation), materialize outside the lease, then publish atomically (pending to live) or roll the slot back. Template preparation has its own build and reader custody, so one cold build serves concurrent waiters. Allocation reclaims pending slots whose owner process is dead, and template acquisition reaps dead readers, through the existing process-liveness and lease owners. A create's contention budget counts only time spent waiting to acquire allocation, checkout and template custody, never admitted preparation, so a create that finished preparing can always publish. A create that cannot acquire custody within the budget fails with an actionable error instead of waiting forever. All template SQL lives in a worker-thread owner (template-registry.worker.ts); the main-thread SQLite ratchet drops from 846 on main to 838. Existing state needs no migration (schema version unchanged). Main's fs-safe index cloning, stale pack-index rebuild, and complete cleanup reporting are preserved.Evidence
Live (dev Gateway, OpenAI-backed agent on the built-in runtime, a large git repository, warm template):
sessions.create {worktree: true}, when each run startsInterim live finding during development: the first version hung one of three post-crash creates indefinitely (leaked dead-owner custody). That was fixed with regressions, and the crash replay above is on the fixed code.
Owner probes (synthetic repository): five concurrent creates complete in 5.5 to 8.2 s. After a SIGKILL, three restart creates complete in 9.5 to 11.2 s, with zero active pending slots and zero template readers on readback.
Tests: 240 cases across 21 files: reservation, capacity, templates, restoration, snapshot indexes, Git maintenance, GC, sandbox templates, CLI, and Gateway/RPC siblings. The final committed owner replay is 17 files with 182 tests passing (461 s). Negative controls reproduce the original serialization, the restart and budget hangs, and both queued-death cases. Oxlint, oxfmt, docs sanity, the madge cycle check (0), and the whole-branch autoreview are clean. Scoped types failed only on an unrelated
maintest-support error that main has since fixed (7b9405e22d7b).CI follow-up: the first exact-head run failed the main-thread SQLite ratchet (
846 -> 850,template-registry.ts 8 -> 12). The follow-up commits move all template SQL into the worker owner, which brings the ratchet to 838 and removes 99 production lines. They also route pending-slot recovery through the provisioning worker, and fix a stale GC fixture and the PR wrapper's pending-recovery routing. Both of those failures were reproduced before the fix. Owner coverage: 241 cases passing (one ReFS platform skip). The five-concurrent and SIGKILL probes still pass.Second review/CI round (ClawSweeper revision 2 and CI run 37452061759):
All 65 worktree/project/planner area files pass (63 passed, 2 platform skips). Whole-branch autoreview: "patch is correct", no findings.
Production +1498/-713, tests +1296/-169, docs +9/-5 (against base 9ad97b2).