Repository navigation
fix(git): bypass WSL login shells for status reads - #13207
Conversation
📝 WalkthroughWalkthroughAdds cached WSL Git environment probing with validation and per-distro state controls. Adds direct WSL Git execution for eligible Windows reads, with login-shell fallback for failed commands and streams. Routes status, numstat, and upstream reads through the direct-Git preference while leaving mutation commands unchanged. Adds tests for probing, routing, retries, streaming, and platform behavior. Adds a Windows/WSL benchmark command and package script that compare execution modes and emit JSON results. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ 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: 8
🧹 Nitpick comments (3)
config/scripts/wsl-git-shell-benchmark.mjs (1)
236-236: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winUse a POSIX path utility for the WSL fixture path.
Use
path.posix.join(repo, fixtureName)instead of string concatenation. The guest path format is POSIX even when the host is Windows.As per coding guidelines, “Use
path.joinor Electron/Node path utilities for file paths; never assume/or\.”Source: Coding guidelines
src/main/git/runner.ts (1)
350-371: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winReuse
resolveGitCommandWithoutProbefor the fallback branch.Lines 350-352 and the body of
resolveGitCommandWithoutProbeare identical. Call the helper fromresolveGitCommandso the login-shell routing rule stays defined once.♻️ Proposed refactor
- return resolveCommand('git', args, options.cwd, options.wslDistro, { - useWslLoginShell: Boolean(options.wslDistro) - }) + return resolveGitCommandWithoutProbe(args, options) }src/main/git/runner-wsl-direct-read.test.ts (1)
243-271: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAdd a case for a normal Git error.
This suite covers exit 127 (invalidate) and exit 128 (permanent disable), but no case asserts that an ordinary Git failure keeps the direct path enabled. Exit 128 is what
git rev-parse --verifyreturns for a missing ref, andsrc/main/git/status.tsruns that command throughgitStatusReadOptionsForWorktree. Add a test that a failing read leaves the next read on--exec. See the related comment onsrc/main/git/runner.tslines 382-399.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 321bf23e-97d1-44bd-ad42-6b196806f93f
📒 Files selected for processing (8)
config/scripts/wsl-git-shell-benchmark.mjspackage.jsonsrc/main/git/git-runtime-options.tssrc/main/git/runner-wsl-direct-read.test.tssrc/main/git/runner.tssrc/main/git/status.test.tssrc/main/git/status.tssrc/main/git/wsl-git-read-environment.ts
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/main/git/wsl-git-read-environment.ts (1)
13-100: 📐 Maintainability & Code Quality | 🟠 Major | 🏗️ Heavy liftUse
GitCapabilityCachefor direct WSL Git capability state.The local maps duplicate capability-cache state. Replace them with
GitCapabilityCache. Key state by executing host and distro. Keep exit codes78and127in a narrow unsupported-error predicate. Preserve the transient retry behavior.As per coding guidelines, "Use
GitCapabilityCachewith a narrow unsupported-error predicate, scope capability state to the executing host."Source: Coding guidelines
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: f1e49f2a-8d86-46b9-8788-ac779560f5b7
📒 Files selected for processing (5)
config/scripts/wsl-git-shell-benchmark.mjssrc/main/git/runner-wsl-direct-read.test.tssrc/main/git/runner.tssrc/main/git/status.test.tssrc/main/git/wsl-git-read-environment.ts
🚧 Files skipped from review as they are similar to previous changes (4)
- src/main/git/status.test.ts
- config/scripts/wsl-git-shell-benchmark.mjs
- src/main/git/runner-wsl-direct-read.test.ts
- src/main/git/runner.ts
WSL-routed git ran through the distro user's interactive login shell for one reason: to inherit their PATH. That shell also runs the distro's rc/motd and writes it to the stdout callers parse, which is why #10917 reports a shell banner breaking GitHub source detection. A shell-free route already existed (`--exec /usr/bin/env PATH=... git`, added for status reads in #13207) but it was opt-in, and only gitStatusReadOptionsForWorktree opted in. Every other read -- remote get-url, config --get, log, show, rev-parse -- took the login shell on every call, so the reported parse never benefited. Classify reads at the resolver instead of at each caller. A read needs nothing the login shell provides, so it takes the direct route without the caller asking. Writes and network operations stay on the login shell: they can depend on credential helpers and ssh-agent that the user's profile sets up. Subcommands that both read and write (config, remote, branch, submodule) require an explicit read flag before they qualify, so `config --get` goes direct while `config user.email x` does not. `git show` blob reads stop forcing the login shell and go direct too. The fence stays on that path: the login shell is still the fallback when the environment probe is cold or rejected, and a banner there would become file content. Behavior note: the first WSL read per distro now also warms the environment probe in the background, so a cold read spawns one extra wsl.exe. Subsequent reads start no shell at all.
* fix(git): run WSL git reads without a shell WSL-routed git ran through the distro user's interactive login shell for one reason: to inherit their PATH. That shell also runs the distro's rc/motd and writes it to the stdout callers parse, which is why #10917 reports a shell banner breaking GitHub source detection. A shell-free route already existed (`--exec /usr/bin/env PATH=... git`, added for status reads in #13207) but it was opt-in, and only gitStatusReadOptionsForWorktree opted in. Every other read -- remote get-url, config --get, log, show, rev-parse -- took the login shell on every call, so the reported parse never benefited. Classify reads at the resolver instead of at each caller. A read needs nothing the login shell provides, so it takes the direct route without the caller asking. Writes and network operations stay on the login shell: they can depend on credential helpers and ssh-agent that the user's profile sets up. Subcommands that both read and write (config, remote, branch, submodule) require an explicit read flag before they qualify, so `config --get` goes direct while `config user.email x` does not. `git show` blob reads stop forcing the login shell and go direct too. The fence stays on that path: the login shell is still the fallback when the environment probe is cold or rejected, and a banner there would become file content. Behavior note: the first WSL read per distro now also warms the environment probe in the background, so a cold read spawns one extra wsl.exe. Subsequent reads start no shell at all. * fix(git): keep queried WSL remote reads on login shell * style: format WSL runner test * fix(git): match WSL read markers positionally The conditional read markers were matched anywhere after the subcommand, so a positional argument that happened to share a marker's name routed a write shell-free: `worktree remove list` read as a listing, and `submodule foreach status` as a status query -- the latter can run arbitrary commands, including network ones. Split the two kinds of marker apart. `config`/`branch` are flag-marked and still match anywhere; `remote`/`worktree`/`submodule` are action-marked and must match the first non-flag argument. The queried `remote show` rule and the `symbolic-ref` arity rule are unchanged. Neither case is reachable today -- Orca issues no `submodule foreach`, and the worktree paths are its own CLI, not git argv -- but the loose match was the shape of the defect, not those two instances. * test(git): pin read routing behind global options Writes hidden behind -c/-C/--git-dir must not reach the shell-free route, and an unparsed global form must fall back to the login shell rather than guess at the subcommand. Both directions fail safe. --------- Co-authored-by: OrcaWin <[email protected]> Co-authored-by: Neil <[email protected]>
* fix(git): run WSL git reads without a shell WSL-routed git ran through the distro user's interactive login shell for one reason: to inherit their PATH. That shell also runs the distro's rc/motd and writes it to the stdout callers parse, which is why stablyai#10917 reports a shell banner breaking GitHub source detection. A shell-free route already existed (`--exec /usr/bin/env PATH=... git`, added for status reads in stablyai#13207) but it was opt-in, and only gitStatusReadOptionsForWorktree opted in. Every other read -- remote get-url, config --get, log, show, rev-parse -- took the login shell on every call, so the reported parse never benefited. Classify reads at the resolver instead of at each caller. A read needs nothing the login shell provides, so it takes the direct route without the caller asking. Writes and network operations stay on the login shell: they can depend on credential helpers and ssh-agent that the user's profile sets up. Subcommands that both read and write (config, remote, branch, submodule) require an explicit read flag before they qualify, so `config --get` goes direct while `config user.email x` does not. `git show` blob reads stop forcing the login shell and go direct too. The fence stays on that path: the login shell is still the fallback when the environment probe is cold or rejected, and a banner there would become file content. Behavior note: the first WSL read per distro now also warms the environment probe in the background, so a cold read spawns one extra wsl.exe. Subsequent reads start no shell at all. * fix(git): keep queried WSL remote reads on login shell * style: format WSL runner test * fix(git): match WSL read markers positionally The conditional read markers were matched anywhere after the subcommand, so a positional argument that happened to share a marker's name routed a write shell-free: `worktree remove list` read as a listing, and `submodule foreach status` as a status query -- the latter can run arbitrary commands, including network ones. Split the two kinds of marker apart. `config`/`branch` are flag-marked and still match anywhere; `remote`/`worktree`/`submodule` are action-marked and must match the first non-flag argument. The queried `remote show` rule and the `symbolic-ref` arity rule are unchanged. Neither case is reachable today -- Orca issues no `submodule foreach`, and the worktree paths are its own CLI, not git argv -- but the loose match was the shape of the defect, not those two instances. * test(git): pin read routing behind global options Writes hidden behind -c/-C/--git-dir must not reach the shell-free route, and an unparsed global form must fall back to the login shell rather than guess at the subcommand. Both directions fail safe. --------- Co-authored-by: OrcaWin <[email protected]> Co-authored-by: Neil <[email protected]>
* fix(git): run WSL git reads without a shell WSL-routed git ran through the distro user's interactive login shell for one reason: to inherit their PATH. That shell also runs the distro's rc/motd and writes it to the stdout callers parse, which is why stablyai#10917 reports a shell banner breaking GitHub source detection. A shell-free route already existed (`--exec /usr/bin/env PATH=... git`, added for status reads in stablyai#13207) but it was opt-in, and only gitStatusReadOptionsForWorktree opted in. Every other read -- remote get-url, config --get, log, show, rev-parse -- took the login shell on every call, so the reported parse never benefited. Classify reads at the resolver instead of at each caller. A read needs nothing the login shell provides, so it takes the direct route without the caller asking. Writes and network operations stay on the login shell: they can depend on credential helpers and ssh-agent that the user's profile sets up. Subcommands that both read and write (config, remote, branch, submodule) require an explicit read flag before they qualify, so `config --get` goes direct while `config user.email x` does not. `git show` blob reads stop forcing the login shell and go direct too. The fence stays on that path: the login shell is still the fallback when the environment probe is cold or rejected, and a banner there would become file content. Behavior note: the first WSL read per distro now also warms the environment probe in the background, so a cold read spawns one extra wsl.exe. Subsequent reads start no shell at all. * fix(git): keep queried WSL remote reads on login shell * style: format WSL runner test * fix(git): match WSL read markers positionally The conditional read markers were matched anywhere after the subcommand, so a positional argument that happened to share a marker's name routed a write shell-free: `worktree remove list` read as a listing, and `submodule foreach status` as a status query -- the latter can run arbitrary commands, including network ones. Split the two kinds of marker apart. `config`/`branch` are flag-marked and still match anywhere; `remote`/`worktree`/`submodule` are action-marked and must match the first non-flag argument. The queried `remote show` rule and the `symbolic-ref` arity rule are unchanged. Neither case is reachable today -- Orca issues no `submodule foreach`, and the worktree paths are its own CLI, not git argv -- but the loose match was the shape of the defect, not those two instances. * test(git): pin read routing behind global options Writes hidden behind -c/-C/--git-dir must not reach the shell-free route, and an unparsed global form must fall back to the login shell rather than guess at the subcommand. Both directions fail safe. --------- Co-authored-by: OrcaWin <[email protected]> Co-authored-by: Neil <[email protected]>
* fix(git): run WSL git reads without a shell WSL-routed git ran through the distro user's interactive login shell for one reason: to inherit their PATH. That shell also runs the distro's rc/motd and writes it to the stdout callers parse, which is why stablyai#10917 reports a shell banner breaking GitHub source detection. A shell-free route already existed (`--exec /usr/bin/env PATH=... git`, added for status reads in stablyai#13207) but it was opt-in, and only gitStatusReadOptionsForWorktree opted in. Every other read -- remote get-url, config --get, log, show, rev-parse -- took the login shell on every call, so the reported parse never benefited. Classify reads at the resolver instead of at each caller. A read needs nothing the login shell provides, so it takes the direct route without the caller asking. Writes and network operations stay on the login shell: they can depend on credential helpers and ssh-agent that the user's profile sets up. Subcommands that both read and write (config, remote, branch, submodule) require an explicit read flag before they qualify, so `config --get` goes direct while `config user.email x` does not. `git show` blob reads stop forcing the login shell and go direct too. The fence stays on that path: the login shell is still the fallback when the environment probe is cold or rejected, and a banner there would become file content. Behavior note: the first WSL read per distro now also warms the environment probe in the background, so a cold read spawns one extra wsl.exe. Subsequent reads start no shell at all. * fix(git): keep queried WSL remote reads on login shell * style: format WSL runner test * fix(git): match WSL read markers positionally The conditional read markers were matched anywhere after the subcommand, so a positional argument that happened to share a marker's name routed a write shell-free: `worktree remove list` read as a listing, and `submodule foreach status` as a status query -- the latter can run arbitrary commands, including network ones. Split the two kinds of marker apart. `config`/`branch` are flag-marked and still match anywhere; `remote`/`worktree`/`submodule` are action-marked and must match the first non-flag argument. The queried `remote show` rule and the `symbolic-ref` arity rule are unchanged. Neither case is reachable today -- Orca issues no `submodule foreach`, and the worktree paths are its own CLI, not git argv -- but the loose match was the shape of the defect, not those two instances. * test(git): pin read routing behind global options Writes hidden behind -c/-C/--git-dir must not reach the shell-free route, and an unparsed global form must fall back to the login shell rather than guess at the subcommand. Both directions fail safe. --------- Co-authored-by: OrcaWin <[email protected]> Co-authored-by: Neil <[email protected]>
Summary
WSL project runtimes currently start the user's interactive login shell for every source-control status subprocess. This PR preserves the first-read behavior while a per-distro probe captures the login-shell Git path, HOME, and PATH, then runs later status, numstat, and upstream reads directly through wsl.exe --exec + git -C.
Mutations and network operations remain on the login shell. Custom per-command Git environment policy disables the optimization, and direct failures retry through the login shell without permanently disabling normal Git error paths.
Refs #9284
Related #9768, #9300
Proof of fix
Real Windows 11 + WSL2 (Ubuntu-24.04, Git 2.43), using equivalent clones in the WSL filesystem and on C:. Each arm used 3 warmups and 20 measured samples in ABBA order; every paired Git stdout and stderr payload was byte-identical.
A deterministic 250 ms login-startup delay models a slow profile/endpoint-security host. Ten samples plus two warmups per arm produced:
The benchmark also invokes the production runner for both layouts and checks exact stdout/stderr equality. Run it with:
Safety and compatibility
AI Review Report
Security Audit
Testing
Notes
This does not solve the larger DrvFS cost. On the mounted fixture, Windows Git measured 22.4 ms median versus about 1,031 ms for WSL Git status, but switching execution hosts can change global config, line endings, symlinks, hooks, credentials, case behavior, and linked-worktree metadata. Filesystem-host routing and Windows-created linked-gitdir compatibility remain separate measured design follow-ups.
Screenshots
No UI change.