Skip to content

fix(git): bypass WSL login shells for status reads - #13207

Merged
Jinwoo-H merged 3 commits into
mainfrom
fix/wsl-git-hot-path
Aug 9, 2026
Merged

Jinwoo-H merged 3 commits into
mainfrom
fix/wsl-git-hot-path

Conversation

@OrcaWin

@OrcaWin OrcaWin commented Aug 8, 2026 •

Copy link
Copy Markdown
Collaborator

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.

Layout / operation Login median / p95 Direct median / p95 Median saved
WSL-native status 73.2 / 75.7 ms 63.5 / 66.8 ms 9.7 ms
WSL-native stage + refresh 221.1 / 234.8 ms 203.3 / 207.0 ms 17.8 ms
C: via WSL status 1,063.2 / 1,134.4 ms 1,030.8 / 1,070.5 ms 32.4 ms
C: via WSL stage + refresh 1,272.7 / 1,318.8 ms 1,225.3 / 1,246.4 ms 47.4 ms

A deterministic 250 ms login-startup delay models a slow profile/endpoint-security host. Ten samples plus two warmups per arm produced:

Layout / operation Login median / p95 Direct median / p95 Median saved
WSL-native status 330.1 / 339.4 ms 64.5 / 67.7 ms 265.6 ms
WSL-native stage + refresh 1,055.6 / 1,069.9 ms 476.2 / 490.2 ms 579.4 ms
C: via WSL status 1,355.2 / 1,412.0 ms 1,041.9 / 1,068.7 ms 313.3 ms
C: via WSL stage + refresh 2,090.6 / 2,829.1 ms 1,482.8 / 2,392.3 ms 607.8 ms

The benchmark also invokes the production runner for both layouts and checks exact stdout/stderr equality. Run it with:

pnpm bench:wsl-git-shell -- --distro <distro> --native-repo <linux-path> --mounted-repo <linux-path> --samples 20 --warmups 3

Safety and compatibility

  • Only source-control read call sites opt in; add/restore/commit, network commands, SSH providers, relays, native Windows Git, macOS, and Linux retain existing routing.
  • The first read retains today's login-shell path while one background probe warms the cache, so first-use latency does not wait for two WSL launches in series.
  • The probe requires absolute HOME/Git paths and a bounded PATH. GIT_*, XDG_CONFIG_HOME, or LD_LIBRARY_PATH profile policy keeps all reads on the login shell.
  • Inherited Windows GIT_* values do not disable the path unless a caller changes them; any value forwarded into the WSL profile is still detected by the probe.
  • Direct nonzero exits retry once through the login shell. A missing executable invalidates and re-probes. A successful login fallback disables direct reads for the session; matching ordinary Git failures leave them enabled. Streams retry only before emitting stdout.
  • Transient probe failures retry after 30 seconds; deterministic policy rejection remains cached.
  • git -C predates the Git 2.25 baseline; no newer Git command or option is introduced. Leading global options remain intact.
  • Folder workspaces and WSL UNC paths remain supported. Override-less UNC routing retains its existing non-login shell.

AI Review Report

  • Manual regression review found and fixed the no-upstream case where a normal rev-parse failure disabled the optimization for the session.
  • CodeRabbit's actionable findings were applied for HOME parity, ambient host Git variables, transient probe retry, benchmark stderr equivalence, exclusive fixture ownership, and test robustness.
  • The environment snapshot intentionally remains a dedicated per-distro cache rather than GitCapabilityCache: it stores PATH/HOME/executable data and transient retry state, not a supported/unsupported Git feature.
  • Ordinary nonzero Git exits still receive a conservative login retry because a profile-dependent config difference can turn the same Git exit into success; matching failures no longer disable the direct path.

Security Audit

  • No command is assembled from unquoted user input on the direct path; wsl.exe, env assignments, Git's absolute executable, cwd, and Git arguments are passed as argv entries.
  • The login probe validates absolute HOME/Git paths, rejects line breaks, bounds captured output/PATH, and opts out when profile-level Git or loader policy could change behavior.
  • Benchmark fixtures use an exclusive random filename and only clean up the file created by that run.
  • No RPC, stream opcode, remote payload, credential, network, mutation, or SSH behavior changes.

Testing

  • 108 targeted runner/status tests
  • 293 additional runner/status tests with host-limited suites excluded
  • Known host limitations rechecked separately: 9 Windows symlink fixtures fail with EPERM; one unrelated cancellation cleanup can hit EBUSY
  • Node typecheck
  • Direct oxlint on every changed source/test/benchmark file
  • Max-lines ratchet and git diff --check
  • Real WSL production-runner verification on WSL-native and mounted repositories
  • 20-sample natural-profile benchmark and 10-sample deterministic-delay benchmark
  • Post-review 5-sample ABBA rerun with exact stdout/stderr equality and exclusive-fixture cleanup
  • Full build/package suite — delegated to CI

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.

@coderabbitai

coderabbitai Bot commented Aug 8, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Adds 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)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 7.69% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly summarizes the primary change: bypassing WSL login shells for Git status reads.
Description check ✅ Passed The description covers the required summary, screenshots, testing, AI review, security audit, and platform-specific notes.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 8

🧹 Nitpick comments (3)
config/scripts/wsl-git-shell-benchmark.mjs (1)

236-236: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Use 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.join or 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 win

Reuse resolveGitCommandWithoutProbe for the fallback branch.

Lines 350-352 and the body of resolveGitCommandWithoutProbe are identical. Call the helper from resolveGitCommand so 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 win

Add 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 --verify returns for a missing ref, and src/main/git/status.ts runs that command through gitStatusReadOptionsForWorktree. Add a test that a failing read leaves the next read on --exec. See the related comment on src/main/git/runner.ts lines 382-399.


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 321bf23e-97d1-44bd-ad42-6b196806f93f

📥 Commits

Reviewing files that changed from the base of the PR and between 6da7b8e and b6b59db.

📒 Files selected for processing (8)
  • config/scripts/wsl-git-shell-benchmark.mjs
  • package.json
  • src/main/git/git-runtime-options.ts
  • src/main/git/runner-wsl-direct-read.test.ts
  • src/main/git/runner.ts
  • src/main/git/status.test.ts
  • src/main/git/status.ts
  • src/main/git/wsl-git-read-environment.ts

Comment thread src/main/git/runner.ts Resolved
Comment thread src/main/git/runner.ts Resolved
Comment thread src/main/git/runner.ts Resolved
Comment thread src/main/git/status.test.ts Resolved

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 lift

Use GitCapabilityCache for 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 codes 78 and 127 in a narrow unsupported-error predicate. Preserve the transient retry behavior.

As per coding guidelines, "Use GitCapabilityCache with 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

📥 Commits

Reviewing files that changed from the base of the PR and between ac37713 and de84ef3.

📒 Files selected for processing (5)
  • config/scripts/wsl-git-shell-benchmark.mjs
  • src/main/git/runner-wsl-direct-read.test.ts
  • src/main/git/runner.ts
  • src/main/git/status.test.ts
  • src/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

@Jinwoo-H
Jinwoo-H merged commit 69ca015 into main Aug 9, 2026
45 checks passed
OrcaWin added a commit that referenced this pull request Aug 18, 2026
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.
OrcaWin added a commit that referenced this pull request Aug 18, 2026
* 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]>
paidaxingyo666 pushed a commit to paidaxingyo666/Manta that referenced this pull request Aug 21, 2026
* 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]>
dallascrilley pushed a commit to dallascrilley/orca that referenced this pull request Aug 27, 2026
* 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]>
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
* 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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants