Repository navigation
perf(worktrees): avoid auto-maintenance in create fetches - #8039
Conversation
Git's opportunistic maintenance can keep an already-complete exact-base fetch open for seconds. Disable it per command for create-base refreshes only, leaving ordinary fetch maintenance and exact-ref freshness unchanged.
📝 WalkthroughWalkthroughAdded optional auto-maintenance suppression to remote-tracking fetches. SSH provider calls now forward the option through the relay, which validates it and prepends Git configuration flags when enabled. Worktree base refreshes pass the option, runtime fetch construction uses shared arguments, and related tests were updated to recognize and assert the new command shape. 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 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.
🧹 Nitpick comments (2)
src/main/ipc/worktree-remote.ts (1)
480-484: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAdd a "Why" comment for the maintenance-skip flag.
The behavior is non-obvious (opportunistic
git maintenance/gcdisabled only for this fetch). As per coding guidelines, "When writing or modifying code driven by a design doc or another non-obvious constraint, add a brief comment explaining why the code behaves that way."📝 Proposed comment addition
- () => - provider.fetchRemoteTrackingRef(repo.path, base.remote, base.branch, base.ref, { - skipAutoMaintenance: true - }) + () => + // Why: this exact-base refresh sits on the create hot path; skip + // opportunistic maintenance/gc for this fetch only instead of mutating + // repo config (see git-fetch-auto-maintenance.ts). + provider.fetchRemoteTrackingRef(repo.path, base.remote, base.branch, base.ref, { + skipAutoMaintenance: true + })Source: Coding guidelines
src/main/runtime/orca-runtime.ts (1)
14624-14631: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAdd a "Why" comment for the unconditional maintenance-skip here.
This spot always disables
maintenance.auto/gc.autofor the exact-base refresh, unlike the SSH path which gates it behind an opt-in flag. A brief comment would clarify that this function is scoped to the create-path base-ref resolution only, per coding guidelines' requirement to explain non-obvious, design-driven behavior.📝 Proposed comment addition
return gitExecFileAsync( - [ + // Why: this refresh backs worktree-create base-ref resolution only; + // skip opportunistic maintenance/gc for this fetch to keep create fast. + [ ...GIT_FETCH_SKIP_AUTO_MAINTENANCE_CONFIG_ARGS, 'fetch', '--no-tags', base.remote, `+refs/heads/${base.branch}:${base.ref}` ],Source: Coding guidelines
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 8899a7c8-6885-434f-aceb-961cad348f7f
📒 Files selected for processing (9)
src/main/ipc/worktree-remote.tssrc/main/ipc/worktrees.test.tssrc/main/providers/ssh-git-provider.test.tssrc/main/providers/ssh-git-provider.tssrc/main/runtime/fetch-remote-cache.test.tssrc/main/runtime/orca-runtime.tssrc/relay/git-handler.test.tssrc/relay/git-handler.tssrc/shared/git-fetch-auto-maintenance.ts
|
Compatibility audit complete.
Remaining manual gaps are a live Windows run and Docker SSH smoke; fixed argv routing, Windows/WSL tests, SSH integration tests, and win32/Linux relay builds cover those paths proportionally. Merging with squash. |
) * perf(worktrees): avoid auto-maintenance in create fetches Git's opportunistic maintenance can keep an already-complete exact-base fetch open for seconds. Disable it per command for create-base refreshes only, leaving ordinary fetch maintenance and exact-ref freshness unchanged. * docs(worktrees): explain create fetch maintenance scope * test(worktrees): account for fetch config prefixes * fix(worktrees): cover Git 2.29 auto maintenance
…ontroller (#30654) * fix(github): PR conflict previews fetch the base branch through the fetch controller The conflict summary on a PR card spawned its own `git fetch origin <base>`, outside RuntimeRemoteFetchController: it refetched a base a worktree create had just refreshed (and vice versa), ran git's auto-maintenance in the background, and never armed the idle loose-ref sweep. It now asks the runtime's controller for the exact-base refresh creates already use (same argv, per-remote queue, dedupe and freshness), waiting at most the old 10 s before falling back to the local ref. The runtime registers its controller at construction, since the IPC and poller paths have no runtime handle. Also corrects the controller comment that claimed every fetch skips auto-maintenance: full fetches keep it on purpose (#8039). * test(github): read the mocked fetch's WSL option without a type assertion * test(github): give the conflicting fallback-lookup test a git mock for its conflict summary * test(github): check WSL routing without duplicating fetch policy * fix(git): bound preview fetch ownership without cancelling create * Preserve repository identity after preview cancellation
Summary
The intermittent delay was not the network transfer: a traced real fetch negotiated and refreshed the requested ref in about 0.37s, then remained blocked in
git maintenance run --auto/reflog expire --all. The same exact fetch with per-command maintenance disabled completed in 0.42s instead of 26.65s, with the remote-tracking SHA unchanged.ELI5
Before Orca creates a worktree from a base such as
origin/main, it asks Git to update Orca's local pointer to that remote branch. This required step makes sure the new worktree starts from the current remote commit.Sometimes that one
git fetchcommand did two separate jobs:Orca must wait for the whole command to exit, so the UI continued to say “Fetching base branch…” during the optional cleanup—even though the base branch itself was already updated. That explains why the delay was intermittent: Git only starts automatic housekeeping when its thresholds are reached. In the traced slow case, the required remote work finished in about 0.37s and the later housekeeping caused nearly all of the remaining 26.65s.
This PR tells Git, for this one latency-sensitive create-time fetch: update the exact branch pointer, but do not start optional automatic housekeeping inside this command. It does not skip the required fetch, accept a stale branch, change which branch is fetched, or change what happens when the fetch fails. Normal fetch/pull operations and explicit or scheduled Git maintenance can still perform housekeeping.
Git version and platform compatibility
Orca's worktree feature requires Git 2.5 or newer. The final command covers every worktree-capable Git generation:
-candgc.auto=0are supported. These versions safely ignore the newer, syntactically valid maintenance keys.git maintenance run --autobeforemaintenance.auto=falsebecame a top-level gate.gc.auto=0disables its GC task andmaintenance.commit-graph.auto=0disables its only other automatic task. Git still starts one fast no-op maintenance process, but performs no housekeeping task.maintenance.auto=falseprevents the automatic maintenance process from starting. The other two keys remain valid and harmless.This was verified with locally built official Git 2.5.0 and Git 2.29.3 sources, Homebrew Git 2.44, and Apple Git 2.50.1. On Git 2.5.0, the three-key command fetched the exact remote SHA and successfully created a linked worktree from it. On Git 2.29.3, a trace first reproduced the commit-graph task with the two-key command, then showed the final three-key command running no maintenance task.
The arguments are passed as an argv array, not shell text, so no platform-specific quoting was added. Relay bundles build for Linux, macOS, Windows, and WSL on the supported x64/arm64 targets. Local, WSL, SSH, and mixed old/new relay behavior is covered by tests and static routing review.
Trade-offs
There is no known end-user correctness or freshness trade-off. There are deliberate scheduling and compatibility details:
git maintenance, but the final command prevents both available tasks from running.fetch.writeCommitGraph=trueis an explicit request inside fetch itself, not opportunistic auto-maintenance. Overriding it would create a user-configuration trade-off, so this PR intentionally does not.What is specifically not traded away: the exact remote ref update, the existing 30-second freshness rule, network/authentication behavior, configured SSH/WSL routing, timeouts, failure handling, or the commit SHA used to create the worktree.
Screenshots
No visual change.
Testing
pnpm lint— branch checks pass; a latest-mainlocal rebase separately exposed an unrelated Japanese localization mismatch in files untouched by this PRpnpm typecheckpnpm test— the full required GitHubverifycheck passed on the final PR headpnpm build—pnpm build:relaypassed for linux-x64, linux-arm64, darwin-x64, darwin-arm64, win32-x64, win32-arm64, and WSLFocused final regression suite (952 passed):
pnpm exec vitest run --config config/vitest.config.ts src/main/runtime/fetch-remote-cache.test.ts src/main/runtime/orca-runtime.test.ts src/main/ipc/worktrees.test.ts src/main/providers/ssh-git-provider.test.ts src/relay/git-handler.test.tsWindows/WSL Git runner suite: 26 passed.
Performance/correctness trace:
git fetch --no-tags origin +refs/heads/main:refs/remotes/origin/main— 26.65s total; remote negotiation/ref consumption finished in about 0.37s and the remainder was auto-maintenancegit -c maintenance.auto=false -c maintenance.commit-graph.auto=0 -c gc.auto=0 fetch --no-tags origin +refs/heads/main:refs/remotes/origin/main— 0.42s in the reproduced slow repositoryrefs/remotes/origin/mainresolved to the same SHA before and after the optimized commandAI Review Report
Two adversarial review/fix rounds covered the create hot path, fetch cache, WSL routing, SSH provider/relay protocol, Git version boundaries, and relevant tests. The review checked:
git worktree add; there is no stale-ref shortcut or longer cache windowThe first implementation used
--no-auto-gc, which is unavailable on older Git versions Orca tolerates. It was replaced with invocation-scoped config. A later adversarial pass then reproduced Git 2.29's transitional behavior and addedmaintenance.commit-graph.auto=0. Fresh Claude and Codex reviewers both returned no issues on the final three-key implementation.Security Audit
-cand no shell is involvedNotes