Skip to content

fix(wsl): migrate nine call sites onto the runner - #15915

Closed
nwparker wants to merge 8 commits into
wsl-w3from
wsl-w3-migrations
Closed

nwparker wants to merge 8 commits into
wsl-w3from
wsl-w3-migrations

Conversation

@nwparker

@nwparker nwparker commented Aug 22, 2026 •

Copy link
Copy Markdown
Contributor

Stacked on #15903 (the runner). This is every call-site migration plus the fixes from three rounds of adversarial review, collapsed into one branch so it can be green on its own.

Supersedes #15907, #15910, #15911 — same content, one reviewable unit. Read it by commit; each is self-contained.

ELI5

Nine places that talked to WSL their own way now call one function. Along the way, reviewers found that hooks had quietly switched to the wrong shell and that several failure paths answered "nothing found" when the honest answer was "couldn't check". Both fixed.

What moves

21 sites across 15 files. Allowlist 23 → 16 on the WSL guard; 163 → 152 on the W1 child_process guard, which moved as a consequence — the shape you want.

Site Was Now
preflight-wsl-agent-detection.ts uncaptured login shell, parsed a banner probe lane
skill-wsl-provider-detection.ts bare sh -c, no login PATH probe lane
4 × skills/* base64 → pipe to bash script on stdin, shell declared
hooks.ts bash -c + hand-rolled quoting script on stdin, shell: 'bash'
cli/wsl-cli-installer.ts bash -lc per call (#14288) probe lane, cached PATH
claude-accounts × 2, codex-accounts × 2 base64 → bash -lc script on stdin, shell: 'bash'
fish cleanup, codex bridge, relay install, 2 × preflight ad-hoc execFile probe lane

The two findings worth your attention

P0 — hooks 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 everywhere. Any orca.yaml hook using [[ ]], arrays, local or source worked on macOS and broke on WSL only. The bashism guard cannot catch this — it scans caller source, and a hook script is user data.

Design change — a degraded PATH refuses instead of answering. Three reviews found the same defect three ways: a call answering "is this installed?" on the bare default PATH, reporting an nvm-installed tool absent (#9725). Each fix was "check a flag at the call site", and 3 of 8 sites had already forgotten the analogous exit-code check. The runner now throws; allowDegradedEnvironment: true opts in. No production caller needs it.

Proof of no regression

  • Full suite: 57,176 pass. The one failure, transcript-watch-liveness.test.ts, passes in isolation and is a pre-existing load flake in untouched code.
  • Typecheck and lint clean.
  • Every migrated site now checks result.code !== 0 || result.timedOut — runProcess resolves on a non-zero exit, so a timed-out scan previously parsed partial stdout into a valid "zero skills" result.
  • Both bash payloads pin bash, enforced by a guard covering the constructs that look like ordinary shell (pipefail, read -d), verified in both directions.
  • New tests: hook interpreter, transient classification of a spawn rejection, timeout-budget split, refusal on unresolved environment, banner-in-stdout regression, PATH-only install detection.

User-facing trade-offs

  1. First probe-lane call per distro pays one login-shell probe, bounded to 2/3 of the caller's timeout. Every later call is faster. Cold-start cost, warm-state win.
  2. Refresh in the Agents pane now re-probes, costing one login shell — the price of it actually working (invalidateWslGuestEnvironment previously had no production caller, so Refresh could never see a newly installed CLI).
  3. A distro whose login PATH can't be read now errors rather than silently reporting your agents as missing.

No other behaviour changes.

Four review rounds

Each round found real defects, several introduced by the previous round's fixes. Rounds 1–3 are closed and re-verified; round 4 is running.

Round Found Notable
1 1 P0, 5 P1 Hooks ran user scripts under dash; probe failure fell back to the login shell, reintroducing #14288
2 4 P1 An unparseable probe was cached permanently, disabling all WSL features on a distro; hooks regressed from "runs degraded" to "fails"
3 3 P1 Exit 127 had no expiry; a starved 5s probe hard-failed the 10s scan behind it; a joiner burned its budget on someone else's probe

The recurring theme — a call answering "is this installed?" on a degraded PATH — was eventually fixed structurally: the runner refuses an unresolved guest PATH unless the caller opts in. Per-call-site vigilance demonstrably wasn't holding; 3 of 8 sites had already forgotten the analogous exit-code check.

Not in scope

16 files still spawn wsl.exe directly, each needing a runner mode that doesn't exist:

  • Long-lived streaming children — the Codex/Claude OAuth logins and the hook relay keep a live ChildProcess, stream stdout to detect auth patterns, hold stdin open for the callback server, and tree-kill on cancel. The runner is run-to-completion.
  • Synchronous callers — codex-accounts' constructor seeds managed-home config on the same tick as startup. The agent measured this rather than assuming: deferring it to a microtask fails four startup tests, so the cascade is real.
  • Host-level flags — --status, --list --quiet query the hypervisor, not a guest; the runner always prepends --exec.

Five decisions have to be made on each `wsl.exe` call. Each has a right answer,
each is invisible in a diff, and each has shipped wrong:

- **Separator.** `--` makes wsl.exe expand `$name` in every forwarded argument
  before the guest runs -- even with no shell in the command -- so `awk
  '{print $2}'` loses its field reference (#12964).
- **Shell.** A login shell on a probe path sources `~/.profile`, so one blocking
  line eats the whole timeout (#14288) and every call pays startup (#9768). No
  login shell on a user-facing path means PATH does not match the user's own
  terminal, so nvm-installed agents read as absent (#9725, #7563, #8366).
- **Fencing.** An interactive login shell runs the distro rc, and stock Ubuntu
  writes its "run as administrator" hint to *stdout* -- so anything parsing that
  stream reads the banner as data (#11327, #11823).
- **WSLENV.** Unset, a Windows-side variable silently never crosses (#12557).
- **Payload.** Scripts go in on stdin. A script on stdin has no quoting boundary
  to escape from, which is what the base64 and `eval` wrappers work around
  (#14292). `filesystem-watcher-wsl.ts` already does this and is the only WSL
  caller with no quoting bug in its history.

`runWslProcess` makes them once, on top of W1's `runProcess` so it inherits
windowsHide, shell:false, timeouts and abort. `lane` is required with no
default: picking the wrong lane by omission is the most common WSL defect here.

The probe lane resolves the login PATH/HOME once per distro and then runs with
no shell at all, so #14288 and #9768 are closed by construction rather than by a
longer timeout. An unprobed distro degrades to the interactive lane -- "we could
not ask" must not become "run with no PATH".

Additive only: no call site is migrated yet. The new guard allowlists the 23
files that still spawn directly, and its length is the workstream's goalpost.

Two guard bugs found by testing the guards against planted call sites: a bare
`main/wsl` prefix also exempted `main/wsl.ts`, `wsl-availability.ts` and
`wsl-unc-delete.ts` -- three real offenders.
These two sites make opposite mistakes, and neither is reviewable against the
other:

- `preflight-wsl-agent-detection.ts` ran `buildWslLoginShellCommand` -- the
  *uncaptured* variant -- and parsed stdout. An interactive login shell runs the
  distro rc, and stock Ubuntu writes its "run a command as administrator" hint
  to stdout, so detection was parsing a stream with a banner in front of it.
- `skill-wsl-provider-detection.ts` ran a bare `sh -c` with no login shell at
  all, so a codex/claude installed through nvm or mise was never on PATH and
  read as absent.

Both want the same thing: the user's real login PATH, without a shell in the
loop. That is the probe lane -- the PATH comes from one cached login-shell probe
per distro, and no shell runs on the call itself, so there is no banner to strip
and no `~/.profile` to stall behind (#9725, #7563, #8366).

Also removes the hand-rolled Promise.race timeout in the preflight file;
`runProcess` already bounds the child and escalates to SIGKILL.

Allowlist: 23 -> 21.
…wrappers

Four skill sites spawned wsl.exe directly; two wrapped their payload in
`buildEncodedWslBashCommand` -- base64, decoded in-guest, piped to a shell --
purely to get a multi-line script across the argv boundary intact. The runner
delivers a script on stdin, which has no quoting boundary to escape from, so the
wrapper has nothing left to solve.

The trap in this migration is that `bash -c` and the runner's default `sh` are
not the same interpreter. These scans use `set -o pipefail`, `read -r -d ''` and
`done < <(find ...)` -- all bash-only -- and on Debian/Ubuntu `sh` is dash, which
rejects each with `Syntax error: word unexpected`. That is the #14292 signature,
and no unit test would have caught it, because the tests mock the runner and the
one round-trip test invokes the script through `bash` directly.

So scripts now declare their interpreter (`shell: 'sh' | 'bash'`, default `sh`),
both bash payloads pin `bash`, and a guard fails any runner caller whose script
uses bash-only syntax without saying so. The detector covers the constructs that
look like ordinary shell -- `pipefail` and `read -d` -- not just the obvious
ones; verified in both directions.

Allowlist: 21 -> 17.
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.
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