Repository navigation
fix(wsl): every local Git call follows its project's runtime unless it says why not (D1c-6) - #33531
Conversation
a7136bc to
f1da001
Compare
7c36ab9 to
ce63c44
Compare
f1da001 to
b59c2e9
Compare
eca009d to
df019e6
Compare
b59c2e9 to
71ac31c
Compare
d3eb4f9 to
28ab007
Compare
71ac31c to
3ef1f0c
Compare
d0e9f7f to
781fc53
Compare
3ef1f0c to
e7dc3bb
Compare
781fc53 to
2c84d33
Compare
e7dc3bb to
25bbc2d
Compare
2c84d33 to
f074b04
Compare
25bbc2d to
dce3e79
Compare
f074b04 to
e12d0ab
Compare
dce3e79 to
30b18bf
Compare
e12d0ab to
7498a03
Compare
30b18bf to
fa3fa88
Compare
7498a03 to
daeffd3
Compare
fa3fa88 to
4e271a5
Compare
daeffd3 to
27d2bdd
Compare
a919a01 to
1cb41e1
Compare
2511ed8 to
cfdbf45
Compare
| options: GitExecOptions | ||
| callerOptions: GitExecOptions | ||
| ): Promise<{ stdout: string; stderr: string }> { | ||
| const options = routeLocalGitOptions(callerOptions) |
There was a problem hiding this comment.
routeLocalGitOptions saves wslDistro before the command waits for admission or the fetch lock. Changing the project's Git clears the route table, but does not cancel queued commands or refresh their saved options. A command queued before switching to Windows Git can therefore start WSL Git afterward, mixing both Gits on the checkout again.
Recheck the route before starting the child, or cancel queued commands when that route changes. The spawned and streaming runners need the same protection.
Knowledge Base Used: Git operations and status
| const repos = linkedRepoPaths(found.root, found.gitdir, fs.automountRoots()) | ||
| return repos | ||
| .map((repo) => lookup(normalizeRuntimePathForComparison(repo))) | ||
| .find((route) => route !== undefined)?.wslDistro |
There was a problem hiding this comment.
If the distro uses [automount] root=/, this lookup can recognize /c/src/app/.git/worktrees/fix and route E:\new\fix into that distro. But command construction still turns the working folder into /mnt/e/new/fix, rather than /e/new/fix. Git then fails to enter the checkout.
Carry the owning distro's mount root into working-folder and argument conversion, not just worktree-link lookup.
Knowledge Base Used: Git operations and status
| // wsl.exe says a distro is missing on stderr; keep a tail so the failure can name it. | ||
| let stderrTail = '' | ||
| const keepStderr = (chunk: Buffer | string): void => { | ||
| stderrTail = `${stderrTail}${String(chunk)}`.slice(-2_048) | ||
| } | ||
| if (options.wslDistro && isLocalGitRuntimeRouterInstalled()) { | ||
| child.stderr?.on('data', keepStderr) |
There was a problem hiding this comment.
Missing distros keep getting spawned
withGitAdmission keeps only stderr, but wsl.exe reports a missing distro on stdout. Its close error therefore contains only the exit code, which isWslDistroNotFoundFailure cannot match. These calls bypass the new 30-second hold and keep starting extra WSL processes.
The streaming runner also drops stdout from its error, and the buffer runner does not call annotateWslHostFailure. Decode the WSL stdout diagnostic before recording the failure across all runner paths.
Knowledge Base Used: Add Git guards for missing project folders
1cb41e1 to
549afa7
Compare
cfdbf45 to
1f3d713
Compare
…t says why not (D1c-6)
…mer, and route a new worktree by its link
…it; host Git only where marked; no wsl.exe storms
…nd feed it spawn failures
…h from the link, and keep the sync launch under the ratchet
…om a git dir that still exists
… with the router on and off
The hooks tests expected the setup runner's `rev-parse --git-path` call to
carry `wslDistro: 'Ubuntu'` for a WSL-runtime project. On main that field
never reached Git: main's gitExecFileSync options have no wslDistro and it
calls resolveCommand('git', args, cwd) with no distro override, so the
lookup ran host Git (WSL only when the cwd itself is a WSL path). The tests
pinned call arguments, not what ran. The sync runner now states that with
`hostGit: true` and resolves exactly as main did, so the tests assert that.
New worktree-runner-script-link tests cover the router-gated link read:
router on reads the link; router on with no usable link falls back to host
Git and converts its Linux path; router off makes main's host Git call and
never reads the link.
…ch on POSIX The setup runner's path lookup now passes hostGit: true where it passed a wslDistro that gitExecFileSync never read, so the binary, args, cwd and env it spawns are unchanged. Update the call-shape assertions and pin the POSIX execFileSync call itself. (cherry picked from commit 6aae6d4d090e13b75c1d9ad2734f2f717dde7570)
With the Git router off admitWslGit returns null; awaiting it anyway added a microtask to every spawn's admission path that main doesn't have. (cherry picked from commit 883aaeb90bc23e89cafb039708a565ab3d72620e)
The remote-identity sweep moved every user's probes to the background admission tier, which only the router reads; it now keeps its tier unless the router is on. Admission wrapping and the spawn stderr tail also step aside without the router, so those calls run exactly as on main. (cherry picked from commit 151a3091307c03078d0c0b98487bbe3bf467ec27)
…ome, as host Git Co-Authored-By: Claude <[email protected]> (cherry picked from commit 255e85fc93deba83addc4370f889c1b721180188)
…ows leaves none installed Co-Authored-By: Claude <[email protected]>
… Git router is off Co-Authored-By: Claude <[email protected]>
…bed after its stop settled, so it never boots a terminated distro
1f3d713 to
a449819
Compare
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 3 minutes. View limit details
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 |
ELI5
A
C:\project whose runtime is WSL is supposed to run its Git inside the distro, unless the user switched it to Git for Windows (#33090). Only some places in Orca did that. Background fetches, base-branch lookups, status reads and others ran Windows Git on the same checkout. Two different Gits on one repo is how one can prune the other's worktrees (risk R36). After this PR every local Git call follows the project's runtime by default. The only exceptions are places that say in the code why they need Windows Git.What Changed
wslDistro. About half of the roughly 200 call sites did. The rest ran Windows Git for a WSL-runtimeC:\project. verify-12 caught three of them (feat(wsl): run Git for Windows for a WSL project on a Windows drive (D1c-2) #33090), and an audit found more, includingworktree move.Routed by default. The six Git runner entry points route their options first (
src/main/git/command-runner/local-git-runtime-route.ts):gitExecFileAsync,gitExecFileAsyncBuffer,gitSpawn,gitSpawnAfterWindowsEnvironmentReady,withGitAdmissionandgitStreamStdout. When a call has a Windows drive-path cwd and no distro, the router supplies the distro of the project that owns that folder.The router (
src/main/project-runtime-git-router.ts):It maps every local repo folder and every worktree Orca has metadata for to its project's Git. Longest folder wins, so a Windows project nested inside a WSL one keeps Windows Git.
Never stale. The route table is dropped on the Store's own write event (
onStateWritten, for the repos, projects, settings and worktree-metadata domains). That event fires synchronously with the in-memory write, so no Git call can run between a runtime switch and the drop. There is no timer.A lookup that misses rebuilds the table once.
A worktree created a moment ago, before its metadata is written, is routed through its
.gitlink to the repo it belongs to. That covers:C:/…);<automount root><drive>/…). Each WSL project distro's root is read once withwslpath -u 'C:\'(buildWslExecArgs, fenced output), only from a distro already confirmed running, and read again after it restarts./mnt/is always tried. A mapping is used only when it lands in a known project's folder;Links into the distro (
/home/…,//wsl.localhost/…) name no drive folder.A main checkout reached through a symlink, junction or
substdrive is routed by its real folder (realpathSync.native).Each unknown folder is traced once per store write, and the walk up to
.gitis capped at 16 levels. It stays synchronous, because the sync spawn and the worktree-mutation tracking both key on the routed Git at call time.Routes come from the saved preference, not from WSL's discovery caches. A project whose distro is missing routes to WSL, where its Git fails safely, instead of falling back to Windows Git on a WSL checkout. So the routes depend on nothing that lacks a change event.
Opt-out. A caller that must use Windows Git passes
hostGit: truewith a// Host Git on purpose: …line above it. The guard pins these eight files:A UNC cwd still routes to its distro either way.
Sync runner stays host Git. The synchronous runner moves verbatim to
git-exec-file-sync.tsand is never routed: routing it would turn a main-thread launch into a synchronouswsl.exe. Every caller says so with a requiredhostGit: true. The setup runner'srev-parse --git-path, which can't see a WSL-made worktree with host Git, instead reads the worktree's own.gitlink when the router is on (src/main/git/worktree-git-path.ts), and falls back to host Git as before when it can't.No
wsl.exestorms.background-tier Git (ref and pack maintenance, hosted-review polls, the remote-identity sweep) on a Windows-drive project waits until its distro is running instead of booting it.local-git-runtime-route-guard.test.ts). It fails if:hostGit: truehas no reason line above it;C:\project, routing everything through WSL makes status about 300× slower until the project switches to Git for Windows. The conversion and the new-project default (feat(wsl): run Git for Windows for a WSL project on a Windows drive (D1c-2) #33090, feat(wsl): default a new Windows-drive project under a WSL default to Git for Windows (D1c-5) #33122) offer that switch first.What this changes for non-WSL users
Nothing they can observe. The title's "every local Git call follows its project's runtime" applies only on Windows with the internal WSL hosts gate open, because that is the only place the router is installed. For macOS, Linux, Windows without the gate, SSH and paired hosts, and folder workspaces:
hostGitis a type-only marker removed before anything spawns.backgroundapplies only with the router on.execFileSynccall is pinned argument for argument (git-exec-file-sync.test.ts), and the setup runner's call is checked inhooks-setup-runner-script.test.ts("keeps POSIX runner behavior on POSIX platforms")..gitlink without the router; it asks Git, as on main.git.runs_intrace attribute (hostfor these users), as exec spans already do from feat(wsl): run Git for Windows for a WSL project on a Windows drive (D1c-2) #33090. It is telemetry only.Audit: every local Git call site
203 call sites in 89 files call the runner directly. Nothing in
src/mainstartsgitany other way; I checked forspawn,execFile,runProcessand the generic command runner. SSH and paired-host Git runs on the remote host and isn't covered by this audit."Runtime" means the project's runtime decides: the caller's explicit
wslDistro, or the router..git/worktrees. A prune or list by the wrong Git is the R36 hazard.worktree-movepassed only a cwd before this PR.user.nameand refs are read through the project's own Git config.hostGit: truehostGit: truewsl.exewould block the main thread; with the router on, the per-worktree path is read from the worktree's.gitlink instead.Why
C:\project would suddenly run all of its Git, status included, through WSL. That is the slowness D1c exists to remove. With the gate, the projects can be switched to Git for Windows (feat(wsl): run Git for Windows for a WSL project on a Windows drive (D1c-2) #33090, feat(wsl): default a new Windows-drive project under a WSL default to Git for Windows (D1c-5) #33122) before anything forces WSL Git onto them.Linked Issue
Part of the WSL re-write, step D1c (risk rows R36, R37). Stacked on #33122.
Visual Proof
N/A: no UI. The
git.runs_inspan attribute from #33090 shows the routing in traces.Testing
local-git-runtime-route.test.ts: the route, explicit distros,hostGit, UNC folders, other platforms, and no router installed.project-runtime-git-router.test.ts: repo folders, known worktrees elsewhere, a nested Windows project, converted and remote projects, unknown folders, a runtime switch on the next call, a just-created worktree routed by its link, a rebuild on a miss, and a missing distro still routing to WSL.project-runtime-git-router-store.test.ts: against the real Store,updateProjectandsetWorktreeMetachange the very next route.local-git-runtime-route-guard.test.ts: every runner entry point routes (7), everyhostGithas a reason line, and the host-only files are pinned. I checked that removing a reason line makes it fail.local-git-runtime-route.test.tsalso covers the missing-distro fast fail and the stopped-distro background hold.git-exec-file-sync.test.tscovers the sync runner staying on host Git in a WSL project, and pins its POSIX launch to main's exact arguments.worktree-git-path.test.tscovers the link read.pnpm tc, all ratchets, the changed-code quality gate, and 9,607 tests acrosssrc/main/git,src/main/ipcandsrc/main/wslpass locally. Six tests insrc/main/runtime(editor-view-layout-apply, restored-editor-move-restart, sweep-terminal-placement, orca-runtime) fail locally; they fail the same way on the mover base,5e37bf698ac, without this stack.git.runs_in = wsl:<distro>on everywinoldspan after add, andhostonwinnew.Review
Self-reviewed.
Agent skill upstream boundary
Notes
installProjectRuntimeGitRouter). Without it,routeLocalGitOptionsreturns the caller's own options; WSL admission, the missing-distro cache and the spawn stderr tail all step aside, so calls are scheduled exactly as on main; the setup runner never reads the.gitlink; and the remote-identity sweep keeps its admission tier.hostGitis a type-only marker that is stripped before spawn. The sync runner moved file verbatim, and its POSIX launch is pinned argument for argument ingit-exec-file-sync.test.ts. The automount-root follower is also started only with the router, so its settled-list check is flag-on only. The only addition is agit.runs_intrace attribute on exec and stream spans; the spawn path sets it only while the router is installed.Status
ca2ec49bbfd: rebased onto main64344142fa0, which has feat(wsl): run Git for Windows for a WSL project on a Windows drive (D1c-2) #33090 squash-merged (fix(wsl-host): tell users how to fix a distro Orca can't host (D1c-1) #33085 earlier) and fix(wsl-mover): hold an app update install while a moved project comes back #35357; feat(wsl): offer Git for Windows in a Windows-drive WSL project's settings (D1c-3) #33097 now targets main. Every commit is kept. CI: running on this head.followWslAutomountRootsreads a distro's automount root only whenwasWslDistroLastSeenRunningSettled(distro)holds for the list it was given, so a list probed mid-stop no longer boots a terminated distro (the bug fix(wsl): never boot a terminated distro off a list taken while it was still stopping #35143 fixed). The test drives the real running-distro cache and gate with a stubbed clock: a list probed inside the settle window makes no read; a settled one does.resolveGitCommandwhile no router is installed.pnpm tc,pnpm run typecheck:ci, the PR's tests,check:code-quality:changed, the anti-slop oxlint, repo oxlint and ast-grep (including the no-real-time-sleep test rules) and the e2e typecheck ratchet all pass locally on this head, run one branch at a time.