Repository navigation
perf(worktree): overlap base refresh with prepared checkout - #18998
Conversation
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
- Overlap base refresh with prepared checkout —
prefetchWorktreeCreateBasegains aprepareCheckoutcallback; when the remote-tracking ref already exists locally,prefetchLocalWorktreeCreateBasestarts the checkout before awaitinggetOrStartRemoteTrackingBaseRefreshinstead of after, so Create can reuse more warm-up work. - Shared
preparewrapper — dedups to one checkout per warm-up, swallows checkout failures with.catch(() => {}), and is awaited in afinallyso speculative work settles even when refresh fails. - Caller simplification — both the desktop IPC handler and the runtime RPC host now pass
prepareCheckout: (base) => prepareWorktreeCreateForRepo(store, repo, base)rather than awaiting it after the prefetch returns, preserving the prior error-swallowing semantics. - Test coverage — overlap/held-refresh unit tests, a real-Git finalize-revalidation test that moves the ref before and after
reset, and routing tests confirming SSH and folder repos skip local preparation.
The correctness hinge is finalizePreparedWorktree, which re-resolves the requested base and reset --hards the prepared checkout onto the refreshed commit, so a checkout keyed on the pre-refresh (stale) base is retargeted or rejected (cold create) at claim time. The real-Git test pins this behavior for both "base moved before reset" and "base moved after reset".
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Team Run ID: 📒 Files selected for processing (6)
Included review availability: Your plan provides up to 10 included reviews per hour; 0 remain after this review. 📝 WalkthroughWalkthroughWorktree base prefetch now accepts a checkout-preparation callback. It starts preparation at the correct point, runs it once, suppresses preparation errors, and waits for completion around remote-tracking refreshes. IPC and runtime callers now provide this callback. Tests cover local, WSL, SSH, folder, refresh-failure, and refreshed-base finalization scenarios. Merge Risk: ⚪ Minimal · up to Worktree checkout preparation now overlaps eligible local base refreshes while preserving finalization against the refreshed commit. The supplied coverage indicates preparation failures and refresh failures are handled as intended, with no current merge-blocking risk identified. 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
Full details: Description checkExplanation The description provides detailed scope, rationale, testing, measurements, risks, and validation, but it does not follow the required template structure. It lacks an explicit linked issue, Visual Proof section with N/A or attachments, Agent skill upstream boundary confirmation, and completed checklist items. Resolution Reformat the description using all template headings. Add an explicit linked issue in the required format, state N/A with a reason or attach visual proof, complete the Agent skill upstream boundary and checklist items, and include any applicable AI Disclosure and Review content.
✨ 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 |
…#18998) * Stop obsolete worktree preparations when evicted or expired * Let worktree preparation proceed during stale reclamation * Verify creation during stalled stale worktree reclamation * Preserve preparation ownership until Git removal starts * test: keep artifact share fixtures unexpired across calendar dates (stablyai#18955) * perf(worktree): overlap base refresh with prepared checkout

Worktree preparation currently waits for the remote base refresh before materializing files, even when that base already exists locally. Start the existing checkout alongside the refresh, so a Create click can reuse more of that work. Create still awaits refresh and finalization revalidates the target commit.
Both desktop IPC and runtime RPC use the same preparation callback. Each warm-up starts at most one checkout, settles it even on refresh failure, and isolates preparation failure from refresh success. Missing refs remain fetch-first. SSH and folder repositories do not enter local preparation; WSL routing is preserved. No UI, draft composer, hook/profile/agent startup, pool limit, Git-worker preference, wire, or persistence change.
Stacked on #18967 (which follows #18951), independent of parked draft-composer PR #18876. No merge authorized.
Validation:
Full CI passed at
64248b4893c, including all eight test shards, native/WSL routing tests, Git compatibility, typecheck, static analysis, and Linux/Windows packaging.The composer-free combined trial at
6d989819c5eintegrates these backend PRs onto main681119dc05b. Full typecheck, 60 focused tests, and background Electron existing Create-flow validation passed; screenshot inspected. Packaged macOS verification passed; see the current trial below.Assessed merge risk: low-to-moderate. Packaged macOS verification passed. No proven correctness issue. Live Windows/WSL concurrent fetch/checkout remains unverified.
User-facing negative trade-offs:
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) — supersedes the injected-delay numbers above
The 7.7–8.2 s → 4.5–4.9 s (~41%) figure quoted above is an artifact of the injected two-second fetch delay and should not be read as the real-world win. Re-measured against a real GitHub fetch and against the degenerate cases, using a private hardlinked clone of the 23,608-file fixture (macOS, warm cache). Totals are fetch‖checkout wall time; the finalize reset is reported separately.
A real single-ref fetch is only 0.5–1.3 s, so the saving is ≈0.5 s, not 3.3 s. The win scales with fetch latency; on a fast link it is small. The instant-fetch control shows no regression. The failure case exits 128 every run with no hang, and the resulting tree was correct and clean every run. One 12.4 s serial outlier (11.1 s checkout) reflects OS cache eviction noise.
Known trade-off: stale-ref start shifts reset work onto the Create path
The checkout now starts at the stale
refs/remotes/origin/<base>(src/main/worktree-create-base-prefetch.ts:91-94). When the fetch actually moves the ref,finalizePreparedWorktree(src/main/git/worktree-create-preparation.ts:237-242) runs a secondreset --hardat Create time — measured 0.48–0.84 s for a 138-commit / 1032-file drift. The previous code prepared after the fetch, keeping that reset off the critical path.Net effect: faster when the user clicks Create before warm-up finishes; roughly parity end-to-end (4.96 s vs 4.88 s) when they click after warm-up and the ref moved. A follow-up could re-reset the pooled entry once the refresh resolves, but that touches pool/claim lifecycle and was left out of this PR.
Overlap correctness: proven, not assumed
rev-parseagainst 954update-refwrites with periodicpack-refs(forcing loose↔packed transitions) produced 0 torn or empty reads across 4,271 reads.src/main/ipc/worktree-remote.ts:2660,src/main/runtime/runtime-local-git-worktree-create.ts:91), andfinalizePreparedWorktreere-resolves the base and resets on mismatch. All 40 probe runs ended withfinalHeadMatchesTarget && clean && treeReadable, including 5 where the ref genuinely moved mid-overlap.{ok:false}and never rejects; create proceeds on the existing local ref exactly as pre-PR, gated byhadLocalBaseRef. The prepared checkout sits at that same ref, matching cold-create output..catch(() => {})wrapsPromise.resolve().then(...)so sync throws are caught too, andfinally { await preparation }settles it before any refresh error propagates.refs/remotes/*.lock/packed-refs.lock/ objects;worktree add+reset --hardtouch.git/worktrees/<id>/{HEAD,index.lock,locked}. TheGIT_FETCH_SKIP_AUTO_MAINTENANCE_CONFIG_ARGS-cprefix is untouched, and checkout runs underwithRepoRefMaintenancePaused.GitCapabilityCacheentry is needed.prefetchRemoteWorktreeCreateBasebefore a preparation exists; folder repos return early. Both covered by new tests; WSL options threaded unchanged.Residual risk
fetch+reset --hardon the same repo is unverified live.