Skip to content

fix(wsl): move the skill scans onto the runner and delete the base64 wrappers - #15910

Closed
nwparker wants to merge 3 commits into
wsl-w3-detectionfrom
wsl-w3-skills
Closed

nwparker wants to merge 3 commits into
wsl-w3-detectionfrom
wsl-w3-skills

Conversation

@nwparker

@nwparker nwparker commented Aug 22, 2026 •

Copy link
Copy Markdown
Contributor

Stacked on #15907.

ELI5

Four bits of skill-scanning code were smuggling their shell script into WSL by base64-encoding it, because quoting kept breaking. The runner hands scripts over on stdin, where quoting can't break — so the encoding is deleted.

What changes

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. A script on stdin has no quoting boundary to escape from, so the wrapper has nothing left to solve.

The trap, and why no test would have caught it

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. On Debian/Ubuntu sh is dash, which rejects each with Syntax error: word unexpected: the #14292 signature.

No unit test would have caught this — the tests mock the runner, and the one round-trip test invokes the script through bash directly. It was caught by reading the payloads.

So: scripts declare their interpreter (shell: 'sh' | 'bash'), both bash payloads pin bash with the reason at the call site, and a guard fails any runner caller whose script uses bash-only syntax without declaring it. The detector covers the constructs that look like ordinary shell — pipefail, read -d — not just the obvious ones.

Credit: the subagent that did this migration flagged the interpreter risk itself and named two bashisms I had missed.

Proof of no regression

  • The NUL-delimited output protocol and its parsers are untouched.
  • All three sites now check result.code !== 0 || result.timedOut before parsing. This matters: runProcess resolves on a non-zero exit, so a scan killed at its 10s timeout previously returned partial stdout that parsed into a valid "zero skills" result — which reads as "nothing is installed" and re-offers installs for skills the user already has.
  • Bash guard verified in both directions (removing a shell: 'bash' makes it fail, naming the file).
  • 620 tests pass; typecheck and lint clean.

User-facing trade-offs

None intended. Interpreter, protocol and timeouts are preserved; the failure path is strictly better (a failed scan now surfaces as an error instead of an empty skill list).

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