Repository navigation
Stop evicted and expired worktree preparations - #18951
Conversation
📝 WalkthroughWalkthroughThe worktree preparation pool now combines caller and internal abort signals. It aborts in-flight checkouts when entries expire or are evicted, skips discard work before checkout starts, and checks cancellation before preparation steps. Discard retries stop for orphaned worktrees. Tests cover cleanup, shared cleanup, claimed entries, expiry, caller cancellation, and real-Git materialization aborts. An opt-in benchmark compares checkout latency with running and aborted obsolete preparations. Merge Risk: 🔵 Low · up to Worktree preparation cancellation behavior is covered by tests, but the new opt-in benchmark can report misleading cancellation performance because obsolete checkouts may not have begun materializing before measurement. 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
Full details: Description checkExplanation The description explains the change, motivation, testing, scope, risks, and validation results, but it does not follow the repository template. It omits the required section headings, a clear Linked Issue entry in the required format, checklist status, AI Disclosure, Review, Agent skill upstream boundary, and explicit Visual Proof status. Resolution Rewrite the description using all template headings. Add the linked issue using the required
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Team
Run ID: 0cc9fc44-34cf-4c30-9361-94104052688f
📒 Files selected for processing (3)
src/main/git/worktree-create-preparation-real-git.test.tssrc/main/worktree-create-preparation-pool.tssrc/main/worktree-create-preparation.test.ts
Included review availability: Your plan provides up to 10 included reviews per hour; 1 remains after this review.
There was a problem hiding this comment.
ℹ️ No critical issues — one minor rough edge inline.
Reviewed changes
- Cancel evicted/expired preparations —
startPreparationcomposes a per-entryAbortControllerwith the caller signal (AbortSignal.any) and bothexpireEntryandenforcePreparationLimitabort it, so an obsolete checkout stops instead of finishing a tree Create can no longer claim. - Skip discard for work that never started —
discardEntryawaitsentry.ready, then returns early whencheckoutStartedis false, preserving claimed in-flight work and keeping cleanup (and the options it uses) independent of entry cancellation. - Cancellation-policy + real-Git tests — five focused unit tests cover eviction, expiry, delayed shared cleanup, claimed in-flight work, and caller-signal composition; a new real-Git test aborts mid-materialization and verifies no later lock command plus removal of partial files and registration.
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
…kout already removed An evicted or expired preparation now aborts its checkout, which self-discards the registration before the pool's own discard runs. That second discard failed with "is not a working tree" and was enrolled for up to three retries on later preparations for the same host, spawning Git only to fail again and warning that the path stays registered when it was already gone. Also accept fs.watch events without a filename in the abort real-Git test, and add an opt-in bench (ORCA_WORKTREE_PREPARATION_CANCEL_BENCH=1) that measures a fresh checkout's wall time with obsolete checkouts left running versus aborted.
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Team
Run ID: e0493185-4262-4056-845f-2a5b9918fa86
📒 Files selected for processing (4)
src/main/git/worktree-create-preparation-real-git.test.tssrc/main/git/worktree-preparation-cancel-latency.bench.test.tssrc/main/worktree-create-preparation.test.tssrc/main/worktree-preparation-discard-retry.ts
Included review availability: Your plan provides up to 10 included reviews per hour; 1 remains after this review.
| const obsoleteWork = obsoletePaths.map((path, index) => | ||
| checkout(path, controllers[index].signal).catch(() => {}) | ||
| ) | ||
| if (variant === 'aborted') { | ||
| // Eviction aborts in the same turn the incoming preparation is armed, so abort before the | ||
| // fresh checkout starts. | ||
| controllers.forEach((controller) => controller.abort()) |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Synchronize obsolete checkout materialization before timing.
checkout() is asynchronous and first awaits base-ref resolution. These lines do not prove that any obsolete checkout reached materialization before aborting or starting the fresh checkout. Line 60 also hides failures in the running variant.
Wait until each obsolete worktree has entered materialization before the variant branch. Fail a running trial when an obsolete checkout rejects. Otherwise, the report can compare pre-start cancellation or no contention against normal checkout work.
There was a problem hiding this comment.
✅ No new issues found — prior feedback addressed cleanly.
Reviewed changes (delta against the prior Pullfrog review)
- Stop retrying discards for already-removed registrations —
runDiscardnow returns early onisOrphanedWorktreeError, so the pool's discard of an evicted/aborted preparation no longer spawns up to three doomedgit worktree unlock/remove --forceattempts plus aconsole.warnwhen the checkout's own self-discard already cleared the registration. - Robust real-Git abort test on Linux — the materialization watcher now treats a
nullfilename event as materialization too, sincefs.watchdelivers no filename on inotify and only theresetwrites into the watched path. - Opt-in cancellation-latency benchmark — a new
describe.skip-gated bench compares fresh-checkout wall time with obsolete preparations running vs aborted. - Preserve the real
isOrphanedWorktreeErrorin the pool test mock — the mock now passes through the real predicate, plus a new test asserting a discard that fails asis not a working treeis attempted exactly once and never warned.
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
Resolves #18951 squash-merge conflicts by keeping the backgrounded stale cleanup alongside main's discard-retry review fix. Moves the checkout cancellation tests into worktree-create-preparation-cancellation.test.ts to keep the registry suite under the test-file line limit.
* Stop obsolete worktree preparations when evicted or expired * fix(worktree): skip discard retries for registrations an aborted checkout already removed An evicted or expired preparation now aborts its checkout, which self-discards the registration before the pool's own discard runs. That second discard failed with "is not a working tree" and was enrolled for up to three retries on later preparations for the same host, spawning Git only to fail again and warning that the path stays registered when it was already gone. Also accept fs.watch events without a filename in the abort real-Git test, and add an opt-in bench (ORCA_WORKTREE_PREPARATION_CANCEL_BENCH=1) that measures a fresh checkout's wall time with obsolete checkouts left running versus aborted.

Changing the composer base could evict a checkout from the preparation pool while its Git checkout continued to completion. Repeated base changes therefore spent CPU and disk on trees that Create could no longer claim.
Cancel preparation when its entry is evicted or expires. Keep claimed entries running, preserve caller cancellation, and wait for Git to settle before cleanup. Work canceled before checkout begins skips removal of a nonexistent registration. Shared host cleanup and the options used for finalization remain independent of entry cancellation.
Validation:
A controlled registry probe before the change admitted ten blocked checkout operations while only three remained selectable and none was canceled. This verifies obsolete work admission, not a quantitative cold-create speedup. The new delayed-cleanup test proves evicted work never reaches checkout.
Assessed merge risk: low. Full CI passed at
deab74e7ff109eb0f43571c3c5f12467733bf1c1, including all eight test shards, Git compatibility, static analysis, typecheck, and Windows/main packaging. Live Windows/WSL interruption cleanup remains less directly verified than macOS; Linux CI passed; live Windows/WSL interrupted-reset cleanup remains unverified. No identified user-facing negative trade-off: evicted/expired entries were already unavailable to Create. Cancellation is not a hard bound on transient disk use while cleanup finishes.This is an independent follow-up to the instant-create work, based on main; it does not expand #18876. SSH/folder repositories remain outside this local/WSL preparation pool. No new Git command, wire field, dependency, UI, or mobile-facing surface. No merges are authorized; the user reviews and decides.
Current composer-free trial: v1.4.198-adhoc.20260906024508, source
6d989819c5ef5d85b8253d763450de9df4c88d57, includes current main681119dc05b(including A), cancellation #18951, background stale cleanup #18967, and fetch/checkout overlap #18998. Parked draft composer #18876 is excluded.Combined full typecheck, 60 focused tests, and background Electron existing Create flow passed. Downloaded ARM64 DMG passed SHA512/size, extraction identity, exact source/version, code signature and notarization. The actual background packaged app passed immediate Create, prepared Create, cancellation without additional workspaces/terminals, and real shell input/output. No draft editor appeared. Owned workspaces were clean and removed, terminal inventory returned to zero, the owned app stopped, and its remaining owned detached preparation was removed.
On the 23,608-file fixture: immediate Create took 7.317 s to observed selection; a second Create after nine seconds of composer dwell took 683 ms. Backend spans were 6.644 s and 515 ms. These are individual potentially warm-cache samples, with a blank terminal and no setup hook. They demonstrate the prepared path, not a universal cold speedup or agent readiness. Screenshots inspected. Windows release packaging is still running; no live Windows/WSL UI validation.
Post-review measurement (readiness review, 2026-09-05)
The original submission had no isolated latency number for this change. Measured with real Git on macOS (6000 × 48 KiB unique files, 5 trials per cell, alternating order, medians). Metric: wall time of a fresh
prepareWorktreeCreateCheckout— the next Create's critical path — while obsolete checkouts are left running (before) versus aborted (this PR).Aborted samples are tight: 749–795 ms across all 10 runs. Caveat: this measures Git-level contention on one machine; in-app numbers will differ with the admission limiter and disk. An opt-in bench (
ORCA_WORKTREE_PREPARATION_CANCEL_BENCH=1) is included and skipped by default.Defect found and fixed during review
Every evicted/expired in-flight checkout was double-discarding. Abort makes
prepareWorktreeCreateCheckoutself-discard (src/main/git/worktree-create-preparation.ts:110), then the pool'sdiscardEntryrunsgit worktree removeagain on the already-removed registration, which exits 128is not a working tree. That error was enrolled inpendingDiscards, retried across the next 3 preparations for the host (a wasted Git spawn each), and then logged a misleading "stays registered until this process exits" warning. Pre-existing for genuine checkout failures, but this PR makes it the common eviction path. Fixed by skipping retry onisOrphanedWorktreeError, with a regression test confirmed red (3 discards) without the guard and green (1) with it.Residual risk
worktree add --no-checkout(millisecond window) could leave a half-written.git/worktrees/<id>thatremove --forcerejects; onlygit worktree pruneclears it. Unproven; stale cleanup does not cover it.