Repository navigation
perf(preflight): read the WSL mount table once, and make launch agree with detection - #16053
Conversation
…r CLI
The prelude is embedded in the lookup script, and the caller wraps that in
`for cmd in <every agent>`, so the unconditional assignment forked awk once per
probed CLI -- 36 of them inside the distro against a 10s detection budget. The
comment claimed it was read once outside the loop; it was not.
`${x+set}` rather than `[ -n ... ]`: a host with no Windows mounts yields the
empty string, which must still count as read.
Pinned by counting real awk forks through /bin/sh with a stub on PATH, because
nothing covered this expression at all -- a wrong-field mutation shipped green.
Verified to bind: the unconditional form counts 4 for 4 commands.
Agent detection skips Windows mounts during the PATH walk; the Codex WSL command builder and the WSL branch of isCommandOnPath did not. So Orca could report the guest codex as installed and then launch the Windows one sitting ahead of it on PATH, or disagree with itself between preflight and detection about the same distro. Both now pass the same option. Verified on a real Windows host against a real WSL2 distro, with a Windows binary planted ahead of a guest one on PATH: plain `command -v orcaprobe` -> /mnt/c/Users/neil/orca-agree/orcaprobe this lookup -> /home/neil/.orca-agree/bin/orcaprobe That host reports /mnt/c as 9p, which the mount expression matches, so the fstype list is confirmed against hardware rather than fixtures.
📝 WalkthroughWalkthroughWSL Codex resolution and preflight command validation now ignore executables in Windows-mounted directories. The generated POSIX lookup script caches detected 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 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.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: ce12a139-3e43-4a9a-8cbe-71024a9860d6
📒 Files selected for processing (5)
src/main/codex-accounts/wsl-codex-command.tssrc/main/ipc/preflight-command-exec.test.tssrc/main/ipc/preflight-command-exec.tssrc/main/ipc/preflight-wsl-agent-detection.test.tssrc/shared/posix-command-path-lookup.ts
Included review availability: Your plan provides up to 10 included reviews per hour; 8 remain after this review.
| // A stub that records each fork, then answers as awk would on a host | ||
| // with no Windows mounts. | ||
| writeFileSync(join(bin, 'awk'), `#!/bin/sh\necho x >> ${counter}\nexit 0\n`) | ||
| chmodSync(join(bin, 'awk'), 0o755) | ||
| writeFileSync(counter, '') | ||
|
|
||
| runWslProcessMock.mockResolvedValue({ | ||
| environmentResolved: true, | ||
| code: 0, | ||
| stdout: '', | ||
| stderr: '', | ||
| timedOut: false | ||
| }) | ||
| await detectWslCommandsOnPath({ distro: 'Ubuntu' }, commands) | ||
| const script = String(runWslProcessMock.mock.calls.at(-1)?.[0].script) | ||
| const options: ExecFileSyncOptions = { | ||
| encoding: 'utf8', | ||
| env: { PATH: `${bin}:/usr/bin:/bin`, HOME: root } | ||
| } | ||
| execFileSync('/bin/sh', ['-c', script], options) | ||
| return readFileSync(counter, 'utf8').trim().split('\n').filter(Boolean).length |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Pass the counter path through the environment.
Line 306 inserts counter into shell source without quoting. If TMPDIR contains whitespace, the stub writes to the wrong path and this test reports zero invocations.
Proposed fix
- writeFileSync(join(bin, 'awk'), `#!/bin/sh\necho x >> ${counter}\nexit 0\n`)
+ writeFileSync(join(bin, 'awk'), '#!/bin/sh\nprintf x >> "$ORCA_AWK_COUNTER"\nexit 0\n')
...
- env: { PATH: `${bin}:/usr/bin:/bin`, HOME: root }
+ env: { PATH: `${bin}:/usr/bin:/bin`, HOME: root, ORCA_AWK_COUNTER: counter }As per coding guidelines, commands and scripts must work on macOS, Linux, and Windows.
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| // A stub that records each fork, then answers as awk would on a host | |
| // with no Windows mounts. | |
| writeFileSync(join(bin, 'awk'), `#!/bin/sh\necho x >> ${counter}\nexit 0\n`) | |
| chmodSync(join(bin, 'awk'), 0o755) | |
| writeFileSync(counter, '') | |
| runWslProcessMock.mockResolvedValue({ | |
| environmentResolved: true, | |
| code: 0, | |
| stdout: '', | |
| stderr: '', | |
| timedOut: false | |
| }) | |
| await detectWslCommandsOnPath({ distro: 'Ubuntu' }, commands) | |
| const script = String(runWslProcessMock.mock.calls.at(-1)?.[0].script) | |
| const options: ExecFileSyncOptions = { | |
| encoding: 'utf8', | |
| env: { PATH: `${bin}:/usr/bin:/bin`, HOME: root } | |
| } | |
| execFileSync('/bin/sh', ['-c', script], options) | |
| return readFileSync(counter, 'utf8').trim().split('\n').filter(Boolean).length | |
| // A stub that records each fork, then answers as awk would on a host | |
| // with no Windows mounts. | |
| writeFileSync(join(bin, 'awk'), '#!/bin/sh\nprintf x >> "$ORCA_AWK_COUNTER"\nexit 0\n') | |
| chmodSync(join(bin, 'awk'), 0o755) | |
| writeFileSync(counter, '') | |
| runWslProcessMock.mockResolvedValue({ | |
| environmentResolved: true, | |
| code: 0, | |
| stdout: '', | |
| stderr: '', | |
| timedOut: false | |
| }) | |
| await detectWslCommandsOnPath({ distro: 'Ubuntu' }, commands) | |
| const script = String(runWslProcessMock.mock.calls.at(-1)?.[0].script) | |
| const options: ExecFileSyncOptions = { | |
| encoding: 'utf8', | |
| env: { PATH: `${bin}:/usr/bin:/bin`, HOME: root, ORCA_AWK_COUNTER: counter } | |
| } | |
| execFileSync('/bin/sh', ['-c', script], options) | |
| return readFileSync(counter, 'utf8').trim().split('\n').filter(Boolean).length |
🧰 Tools
🪛 ast-grep (0.45.1)
[warning] Importing child_process exposes a command-execution surface; ensure any command/argument built from input is validated, and prefer execFile/spawn with an argument array over exec.
Context: import { execFileSync, type ExecFileSyncOptions } from 'node:child_process'
Note: [CWE-78] Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection').
(detect-child-process-typescript)
Source: Coding guidelines
… command Counting awk forks with a stub that reports no mounts cannot see what the hoist trades correctness for. A mutant that empties `_orca_win_mounts` inside the walk keeps the fork count at 1 and keeps every existing test green, while every agent after the first stops skipping /mnt. This runs two commands behind a stubbed Windows mount and asserts both resolve to the guest binary. Verified against that exact mutant. Credit: review counsel.
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
src/main/ipc/preflight-wsl-agent-detection.test.ts (1)
342-346: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winShorten the regression rationale comment.
Keep the non-obvious invariant and remove the implementation history. For example:
// This catches mount-list clobbering after the first command, which fork counts miss.As per coding guidelines, comments must be concise, non-obvious, and brief; prefer one line.
Source: Coding guidelines
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 2528883d-40f2-4490-8a35-4a5deae3f2fb
📒 Files selected for processing (1)
src/main/ipc/preflight-wsl-agent-detection.test.ts
Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.
| const script = String(runWslProcessMock.mock.calls.at(-1)?.[0].script).replace( | ||
| /_orca_win_mounts=\$\([^)]*\)/, | ||
| `_orca_win_mounts=${join(root, 'winmnt')}` | ||
| ) | ||
| const options: ExecFileSyncOptions = { | ||
| encoding: 'utf8', | ||
| env: { PATH: `${win}:${guest}:/usr/bin:/bin`, HOME: root } |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Pass the mount path through the environment.
Line 371 inserts join(root, 'winmnt') into shell source without quoting. If TMPDIR contains whitespace or shell-significant characters, the test can fail before it checks command resolution. Store the path in env and reference a quoted variable in the replacement.
Proposed fix
- `_orca_win_mounts=${join(root, 'winmnt')}`
+ '_orca_win_mounts="$ORCA_TEST_WIN_MOUNT"'
...
- env: { PATH: `${win}:${guest}:/usr/bin:/bin`, HOME: root }
+ env: {
+ PATH: `${win}:${guest}:/usr/bin:/bin`,
+ HOME: root,
+ ORCA_TEST_WIN_MOUNT: join(root, 'winmnt')
+ }As per coding guidelines, commands and scripts must work on macOS, Linux, and Windows.
🧰 Tools
🪛 ast-grep (0.45.1)
[warning] Importing child_process exposes a command-execution surface; ensure any command/argument built from input is validated, and prefer execFile/spawn with an argument array over exec.
Context: import { execFileSync, type ExecFileSyncOptions } from 'node:child_process'
Note: [CWE-78] Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection').
(detect-child-process-typescript)
Source: Coding guidelines
… with detection (stablyai#16053) * perf(preflight): read the WSL mount table once per shell, not once per CLI The prelude is embedded in the lookup script, and the caller wraps that in `for cmd in <every agent>`, so the unconditional assignment forked awk once per probed CLI -- 36 of them inside the distro against a 10s detection budget. The comment claimed it was read once outside the loop; it was not. `${x+set}` rather than `[ -n ... ]`: a host with no Windows mounts yields the empty string, which must still count as read. Pinned by counting real awk forks through /bin/sh with a stub on PATH, because nothing covered this expression at all -- a wrong-field mutation shipped green. Verified to bind: the unconditional form counts 4 for 4 commands. * fix(wsl): make launch resolve the same binary detection reported Agent detection skips Windows mounts during the PATH walk; the Codex WSL command builder and the WSL branch of isCommandOnPath did not. So Orca could report the guest codex as installed and then launch the Windows one sitting ahead of it on PATH, or disagree with itself between preflight and detection about the same distro. Both now pass the same option. Verified on a real Windows host against a real WSL2 distro, with a Windows binary planted ahead of a guest one on PATH: plain `command -v orcaprobe` -> /mnt/c/Users/neil/orca-agree/orcaprobe this lookup -> /home/neil/.orca-agree/bin/orcaprobe That host reports /mnt/c as 9p, which the mount expression matches, so the fstype list is confirmed against hardware rather than fixtures. * test(preflight): prove the memoised mount list applies past the first command Counting awk forks with a stub that reports no mounts cannot see what the hoist trades correctness for. A mutant that empties `_orca_win_mounts` inside the walk keeps the fork count at 1 and keeps every existing test green, while every agent after the first stops skipping /mnt. This runs two commands behind a stubbed Windows mount and asserts both resolve to the guest binary. Verified against that exact mutant. Credit: review counsel.
… with detection (stablyai#16053) * perf(preflight): read the WSL mount table once per shell, not once per CLI The prelude is embedded in the lookup script, and the caller wraps that in `for cmd in <every agent>`, so the unconditional assignment forked awk once per probed CLI -- 36 of them inside the distro against a 10s detection budget. The comment claimed it was read once outside the loop; it was not. `${x+set}` rather than `[ -n ... ]`: a host with no Windows mounts yields the empty string, which must still count as read. Pinned by counting real awk forks through /bin/sh with a stub on PATH, because nothing covered this expression at all -- a wrong-field mutation shipped green. Verified to bind: the unconditional form counts 4 for 4 commands. * fix(wsl): make launch resolve the same binary detection reported Agent detection skips Windows mounts during the PATH walk; the Codex WSL command builder and the WSL branch of isCommandOnPath did not. So Orca could report the guest codex as installed and then launch the Windows one sitting ahead of it on PATH, or disagree with itself between preflight and detection about the same distro. Both now pass the same option. Verified on a real Windows host against a real WSL2 distro, with a Windows binary planted ahead of a guest one on PATH: plain `command -v orcaprobe` -> /mnt/c/Users/neil/orca-agree/orcaprobe this lookup -> /home/neil/.orca-agree/bin/orcaprobe That host reports /mnt/c as 9p, which the mount expression matches, so the fstype list is confirmed against hardware rather than fixtures. * test(preflight): prove the memoised mount list applies past the first command Counting awk forks with a stub that reports no mounts cannot see what the hoist trades correctness for. A mutant that empties `_orca_win_mounts` inside the walk keeps the fork count at 1 and keeps every existing test green, while every agent after the first stops skipping /mnt. This runs two commands behind a stubbed Windows mount and asserts both resolve to the guest binary. Verified against that exact mutant. Credit: review counsel. (cherry picked from commit c3a1694)
… with detection (stablyai#16053) * perf(preflight): read the WSL mount table once per shell, not once per CLI The prelude is embedded in the lookup script, and the caller wraps that in `for cmd in <every agent>`, so the unconditional assignment forked awk once per probed CLI -- 36 of them inside the distro against a 10s detection budget. The comment claimed it was read once outside the loop; it was not. `${x+set}` rather than `[ -n ... ]`: a host with no Windows mounts yields the empty string, which must still count as read. Pinned by counting real awk forks through /bin/sh with a stub on PATH, because nothing covered this expression at all -- a wrong-field mutation shipped green. Verified to bind: the unconditional form counts 4 for 4 commands. * fix(wsl): make launch resolve the same binary detection reported Agent detection skips Windows mounts during the PATH walk; the Codex WSL command builder and the WSL branch of isCommandOnPath did not. So Orca could report the guest codex as installed and then launch the Windows one sitting ahead of it on PATH, or disagree with itself between preflight and detection about the same distro. Both now pass the same option. Verified on a real Windows host against a real WSL2 distro, with a Windows binary planted ahead of a guest one on PATH: plain `command -v orcaprobe` -> /mnt/c/Users/neil/orca-agree/orcaprobe this lookup -> /home/neil/.orca-agree/bin/orcaprobe That host reports /mnt/c as 9p, which the mount expression matches, so the fstype list is confirmed against hardware rather than fixtures. * test(preflight): prove the memoised mount list applies past the first command Counting awk forks with a stub that reports no mounts cannot see what the hoist trades correctness for. A mutant that empties `_orca_win_mounts` inside the walk keeps the fork count at 1 and keeps every existing test green, while every agent after the first stops skipping /mnt. This runs two commands behind a stubbed Windows mount and asserts both resolve to the guest binary. Verified against that exact mutant. Credit: review counsel.
… with detection (stablyai#16053) * perf(preflight): read the WSL mount table once per shell, not once per CLI The prelude is embedded in the lookup script, and the caller wraps that in `for cmd in <every agent>`, so the unconditional assignment forked awk once per probed CLI -- 36 of them inside the distro against a 10s detection budget. The comment claimed it was read once outside the loop; it was not. `${x+set}` rather than `[ -n ... ]`: a host with no Windows mounts yields the empty string, which must still count as read. Pinned by counting real awk forks through /bin/sh with a stub on PATH, because nothing covered this expression at all -- a wrong-field mutation shipped green. Verified to bind: the unconditional form counts 4 for 4 commands. * fix(wsl): make launch resolve the same binary detection reported Agent detection skips Windows mounts during the PATH walk; the Codex WSL command builder and the WSL branch of isCommandOnPath did not. So Orca could report the guest codex as installed and then launch the Windows one sitting ahead of it on PATH, or disagree with itself between preflight and detection about the same distro. Both now pass the same option. Verified on a real Windows host against a real WSL2 distro, with a Windows binary planted ahead of a guest one on PATH: plain `command -v orcaprobe` -> /mnt/c/Users/neil/orca-agree/orcaprobe this lookup -> /home/neil/.orca-agree/bin/orcaprobe That host reports /mnt/c as 9p, which the mount expression matches, so the fstype list is confirmed against hardware rather than fixtures. * test(preflight): prove the memoised mount list applies past the first command Counting awk forks with a stub that reports no mounts cannot see what the hoist trades correctness for. A mutant that empties `_orca_win_mounts` inside the walk keeps the fork count at 1 and keeps every existing test green, while every agent after the first stops skipping /mnt. This runs two commands behind a stubbed Windows mount and asserts both resolve to the guest binary. Verified against that exact mutant. Credit: review counsel.
Two follow-ups from the readiness review of #16028, plus the real-hardware verification that review asked for.
1. The mount table was read once per probed CLI, not once
The prelude is embedded in the lookup script, and the caller wraps that in
for cmd in <every agent>— so the unconditional assignment forkedawk36times inside the distro, against a 10 s detection budget. My comment claimed
it was read once outside the loop. It was not.
${x+set}rather than[ -n … ]: a host with no Windows mounts yields theempty string, which must still count as read.
Pinned by counting real
awkforks through/bin/shwith a stub on PATH —nothing covered this expression at all before, so a wrong-field mutation
shipped green. Verified to bind: the unconditional form counts 4 for 4 commands.
2. Detection and launch could resolve different binaries
Agent detection skips Windows mounts during the walk. The Codex WSL command
builder and the WSL branch of
isCommandOnPathdid not — so Orca could reportthe guest
codexas installed and then launch the Windows one ahead of it onPATH. Both now pass the same option.
Verified on real hardware
Run against a real Windows host and a real WSL2 distro, with a Windows binary
planted ahead of a guest one on PATH:
That host reports
/mnt/cas 9p, which the mount expression matches — sothe fstype list is now confirmed against hardware, not fixtures.
Separately, this retires the residual risk flagged on #16032. Scripts in the
8 KB–30 KB band newly travel by argv, and nobody had confirmed
wsl.exehas nointerop cap below 32,767. Measured on the same host, argv through
wsl.exe:ENAMETOOLONGThe 30,000 budget is correct with confirmed headroom, and the failure mode past
it is a loud spawn error rather than truncation.
Proof of no regression
src/main/ipc+src/main/codex-accounts: 3,402 passed.User-facing trade-offs
None. Fewer forks for the same answer, and two call sites that now agree
with detection instead of contradicting it.