Skip to content

perf(preflight): read the WSL mount table once, and make launch agree with detection - #16053

Merged
nwparker merged 3 commits into
mainfrom
nwparker/wsl-awk-hoist
Aug 23, 2026
Merged

nwparker merged 3 commits into
mainfrom
nwparker/wsl-awk-hoist

Conversation

@nwparker

@nwparker nwparker commented Aug 23, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​99 $\color{#cf222e}{\Huge{\mathbf{−}}}$​2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​97
Prod 3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​24 $\color{#cf222e}{\Huge{\mathbf{−}}}$​5 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​19

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 forked awk 36
times
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 the
empty string, which must still count as read.

Pinned by counting real awk forks through /bin/sh with 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 isCommandOnPath did not — so Orca could report
the guest codex as installed and then launch the Windows one ahead of it on
PATH. 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:

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 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.exe has no
interop cap below 32,767. Measured on the same host, argv through wsl.exe:

script 7 k 9 k 16 k 24 k 26 k 30 k 31 k 32 k 40 k
result OK OK OK OK OK OK OK OK ENAMETOOLONG

The 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.
  • Lint and typecheck exit 0.
  • Planted host fixtures removed afterwards.

User-facing trade-offs

None. Fewer forks for the same answer, and two call sites that now agree
with detection instead of contradicting it.

…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.
@coderabbitai

coderabbitai Bot commented Aug 23, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

WSL Codex resolution and preflight command validation now ignore executables in Windows-mounted directories. The generated POSIX lookup script caches detected drvfs, 9p, and virtiofs mounts in _orca_win_mounts and reads /proc/mounts once per shell. Tests update expected script generation and verify mount-table access for single-command and multiple-command probes.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description explains the changes and testing, but it omits required template sections, including the linked issue, visual proof or N/A, and checklist status. Add the required template sections, provide the linked issue, mark visual proof as N/A with a reason, and complete the testing and review checklists.
✅ Passed checks (4 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed Docstring check was indeterminate for this PR — some files could not be analyzed in time. Not blocking.
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 mount-table performance improvement and alignment between WSL detection and launch.
✨ Finishing Touches
📝 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: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: ce12a139-3e43-4a9a-8cbe-71024a9860d6

📥 Commits

Reviewing files that changed from the base of the PR and between 4c984d4 and 2448e15.

📒 Files selected for processing (5)
  • src/main/codex-accounts/wsl-codex-command.ts
  • src/main/ipc/preflight-command-exec.test.ts
  • src/main/ipc/preflight-command-exec.ts
  • src/main/ipc/preflight-wsl-agent-detection.test.ts
  • src/shared/posix-command-path-lookup.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 8 remain after this review.

Comment on lines +304 to +324
// 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

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.

🎯 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.

Suggested change
// 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.

@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: 1

🧹 Nitpick comments (1)
src/main/ipc/preflight-wsl-agent-detection.test.ts (1)

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

Shorten 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

📥 Commits

Reviewing files that changed from the base of the PR and between 2448e15 and efe5892.

📒 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.

Comment on lines +369 to +375
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 }

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.

🎯 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

@nwparker
nwparker merged commit c3a1694 into main Aug 23, 2026
47 checks passed
@nwparker
nwparker deleted the nwparker/wsl-awk-hoist branch August 23, 2026 09:58
CodeHourra pushed a commit to CodeHourra/orca that referenced this pull request Aug 23, 2026
… 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.
paidaxingyo666 pushed a commit to paidaxingyo666/Manta that referenced this pull request Aug 25, 2026
… 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)
dallascrilley pushed a commit to dallascrilley/orca that referenced this pull request Aug 27, 2026
… 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.
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
… 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.
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.

1 participant