Skip to content

fix(wsl): close the review findings and migrate the hook runner + CLI installer - #15911

Closed
nwparker wants to merge 5 commits into
wsl-w3-skillsfrom
wsl-w3-core
Closed

nwparker wants to merge 5 commits into
wsl-w3-skillsfrom
wsl-w3-core

Conversation

@nwparker

@nwparker nwparker commented Aug 22, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 15 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​281 $\color{#cf222e}{\Huge{\mathbf{−}}}$​311 $\color{#cf222e}{\Huge{\mathbf{−}}}$​30
Prod 16 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​315 $\color{#cf222e}{\Huge{\mathbf{−}}}$​255 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​60

Stacked on #15910. This is the review-response PR: three independent reviews (Opus, Grok, GPT) ran against the stack, and this closes what they found — including a release blocker.

ELI5

Reviewers found that WSL hooks had quietly started running users' scripts with the wrong shell, and that a few failure paths answered "nothing found" when the honest answer was "couldn't check". Both are fixed, and the runner now refuses to guess.

P0 — WSL hooks silently ran user scripts under dash

hooks.ts passed a script with no shell, which defaults to sh. The native path pins /bin/bash (getHookShell()), and docs/reference/windows-setup-shell.md states the runner is "always executed by bash … on every platform."

Any orca.yaml hook using [[ ]], arrays, local or source worked on macOS/Linux and broke on WSL only — including one that opens with #!/usr/bin/env bash, since the shebang is inert when the payload arrives on stdin.

The bashism guard could not catch this: it scans caller source, and a hook script is user data loaded at runtime. Fixed by pinning shell: 'bash', with that reasoning at the call site.

P1s

  • A rejected probe poisoned the cache for the process lifetime. runProcess rejects when the child cannot start (ENOENT, EAGAIN under memory pressure). The uncaught rejection stayed in the in-flight map, so every WSL feature re-threw it until app restart. Now classified transient.
  • Three skill sites dropped exit-code checks (covered in fix(wsl): move the skill scans onto the runner and delete the base64 wrappers #15910).
  • Probe failure fell back to the login shell — sourcing ~/.profile, the exact stall the runner exists to remove, and most likely to bite precisely when the distro is slowest. It now runs shell-free.
  • The probe ran on its own 10s timer ahead of the timed leg, so a 5s caller could reach runProcess with 1ms left and report a timeout for a command that would have taken milliseconds. The probe now gets 2/3 of the remaining budget.
  • invalidateWslGuestEnvironment had no production caller. Its entire purpose is "installed a new CLI, Orca doesn't see it yet", which could not work while the guest PATH stayed cached for the process lifetime. Now wired into Refresh in the Agents pane.

The design change worth reviewing

Three reviews found the same class of defect three different ways: a call that answers "is this installed?" running on the bare default PATH and reporting an nvm-installed tool absent. Each time the fix was "check a flag at the call site" — and 3 of 8 sites had already forgotten the analogous exit-code check.

So the runner now throws when the login PATH can't be established. A caller that genuinely tolerates degradation says allowDegradedEnvironment: true. That puts the decision in the one place a reader looks instead of relying on every caller's memory. No production caller needs the flag today.

Elegance

Four byte-identical POSIX quote helpers collapsed to one. Dead addWorktreeSetupWslInteropEnv and the speculative signal option removed. Guard scanners share one walker (they had already drifted — that drift is why the WSL separator guard was scanning tests/e2e/.cross-version-checkouts/). Comments cut to AGENTS.md density.

Proof of no regression

Full suite, typecheck and lint clean. New tests cover: hook interpreter pinning, transient classification of a spawn rejection, the budget split, refusal on unresolved environment, and the opt-in escape hatch.

User-facing trade-offs

  1. WSL hooks are pinned to bash — restores prior behaviour; a hook that somehow depended on dash would change. No such hook can have existed, since bash was the interpreter before this stack.
  2. Refresh in the Agents pane now re-probes the distro, so it costs one login shell. That is the price of it actually working.

An independent review of the runner found two real defects and proved the
goalpost was wrong. All verified before fixing.

P1 -- `lane: 'interactive'` plus `script` ran with no login shell AND no cached
environment. A script never rides the login shell (it owns stdin), so that
combination fell into the shell-free branch while the environment was only
fetched for `lane: 'probe'` -- giving a caller who explicitly asked for the
user's terminal PATH strictly less than the probe lane would have. The cached
environment is now fetched whenever there is a script, on either lane.

P1 -- the guard missed the largest wsl.exe spawner in the tree. It only matched
a named opener, so `git/runner.ts` (`binary: 'wsl.exe'`, spawned four lines
later), locally-aliased callers (`run(`, `execFileUtf8(`) and `command:` fields
were all invisible. The count was the goalpost, so the goalpost was wrong. The
detector now accepts any identifier call and the assignment-style fields, and
the five files that reach a spawn through a variable are recorded as a named
blind spot rather than left implied.

Also:
- A missing fence now throws instead of returning `''`. `readStdout` returns
  null precisely to distinguish "no fence" from "empty payload", and collapsing
  them is the silent-wrong-answer shape this module exists to avoid.
- A `program` containing `=` is rejected: after `env PATH=… HOME=…` it reads as
  a third assignment, so `env` prints the whole guest environment and exits 0.
- An empty argv with a cwd is rejected: `exec` with no operands is a no-op, so
  the wrapper would cd and exit 0 having run nothing.
- The sentinel assertion could not fail (`offenders + allowlist >= 20` with a
  23-entry allowlist); it now names a call site that is definitely there.
`wsl-cli-installer.ts` probed on `bash -lc` purely to get a real PATH for its
interop checks, which is the direct cause of the 10s timeout behind a blocking
`~/.profile` (#14288). The probe lane gives it the same login PATH from one
cached probe instead of paying `~/.profile` on every call.

`hooks.ts` ran `bash -c` with hand-rolled single-quote escaping; the script now
travels on stdin, so there is no quoting boundary left to get wrong.

`set -euo pipefail` became `set -eu` in the two transported scripts. That is a
semantic change, so it was checked rather than assumed: neither script contains
a pipe, and dash -- which is `sh` on Debian/Ubuntu -- has no `pipefail` option
at all, so keeping it would have failed the script outright.

Deliberately not migrated, with reasons recorded rather than skipped:
- `wsl-availability.ts` and `wsl.ts` invoke host-level flags (`--status`,
  `--list --quiet`). The runner always prepends `--exec`, so a flag-only
  invocation cannot be expressed through its API at all.
- `wsl.ts`'s `getWslHome`/`wslUncDirectoryExists` are synchronous and called
  synchronously from six production files. The runner is Promise-only, so
  migrating them means a sync-to-async cascade well outside this scope -- and
  they share caches with their async twins, so migrating half would split one
  contract across two transports.

Allowlist: 23 -> 21.
Three independent reviews (Opus, Grok, GPT) converged on the same release
blocker and several reliability defects.

P0 -- WSL hooks silently ran user scripts under dash. `hooks.ts` passed a
script with no `shell`, which defaults to `sh`; the native path pins
`/bin/bash` and docs/reference/windows-setup-shell.md guarantees bash on every
platform. Any `orca.yaml` hook using `[[ ]]`, arrays, `local` or `source` broke
on WSL only. The bashism guard cannot see this -- the payload is user data, not
caller source -- so the fix is `shell: 'bash'` plus this note.

P1 -- a rejected probe poisoned the cache for the process lifetime.
`runProcess` rejects when the child cannot start, and the uncaught rejection
stayed in `inFlight`, so every WSL feature threw until restart. Now classified
transient.

P1 -- three skill sites dropped their exit-code checks. `runProcess` resolves on
a non-zero exit, so a scan killed at its 10s timeout returned partial stdout
that parsed into a valid "zero skills" result -- which reads as "nothing is
installed" and re-offers installs for skills that are present.

P1 -- probe failure used to fall back to the login shell, which sources
`~/.profile`: the stall this runner exists to remove, reintroduced exactly when
the distro is slowest. It now runs shell-free and reports
`environmentResolved: false`, and agent detection treats that as unknown rather
than absent -- reporting an nvm-installed agent absent is #9725.

Elegance: four byte-identical POSIX quote helpers collapsed to one; the dead
`addWorktreeSetupWslInteropEnv` and the speculative `signal` option removed; the
guard scanners share one walker; comments cut to AGENTS.md density.
Three reviews found the same class of defect three different ways: a call that
answers "is this installed?" running on the bare default PATH and reporting an
nvm-installed tool absent (#9725). Each time the fix was to check a flag at the
call site -- and 3 of 8 sites had already forgotten the analogous exit-code
check, so that approach was not going to hold.

The runner now throws when the login PATH cannot be established. A caller that
genuinely tolerates a degraded PATH says `allowDegradedEnvironment: true`, which
puts the decision in the one place a reader looks instead of in every caller's
memory. No production caller needs it today.

Also: the probe no longer runs on its own 10s timer ahead of the caller's
budget. A 5s caller could reach `runProcess` with 1ms left and report a timeout
for a command that would have taken milliseconds; the probe now gets two thirds
of the remaining budget and the command keeps the rest.

And `invalidateWslGuestEnvironment` finally has a production caller: Refresh in
the Agents pane. Its whole purpose is "installed a new CLI, Orca doesn't see it
yet", which could not work while the guest PATH stayed cached for the process
lifetime.
Migrating them onto the runner removed their direct child_process import, so
the W1 ratchet reports them stale. Second goalpost moving as a consequence of
the first: 163 -> 156.
@nwparker

Copy link
Copy Markdown
Contributor Author

Folded into #15915, which carries the same content plus three rounds of review fixes on one branch that is green on its own. The stacked branches predated those fixes, so each was red in isolation — collapsing was safer than four-way branch surgery.

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