Skip to content

fix(install.ps1): WSL detection — strip null bytes from UTF-16 wsl --list output#1005

Merged
joelteply merged 1 commit into
canaryfrom
fix/install-ps1-wsl-detect-utf16
May 2, 2026
Merged

fix(install.ps1): WSL detection — strip null bytes from UTF-16 wsl --list output#1005
joelteply merged 1 commit into
canaryfrom
fix/install-ps1-wsl-detect-utf16

Conversation

@joelteply
Copy link
Copy Markdown
Contributor

Carl-OOTB Windows blocker — phase 1 (prereqs)

Discovered during continuum-b69f's Carl-OOTB Windows validation 2026-05-02. Fresh-Windows validator with Ubuntu installed and running in WSL2 hits:

+ Git for Windows already installed
+ Docker Desktop already installed
-> Installing WSL2 + Ubuntu (will require admin elevation + a reboot on first install) ...
! Not running as admin. WSL2 install needs admin -- relaunch ...

But wsl --list --verbose shows Ubuntu running. The Install-WSL2 detection in install.ps1 thinks WSL is missing and demands admin elevation.

Root cause

wsl.exe --list --quiet writes UTF-16 LE. PowerShell reads stdout as UTF-8, so each distro name interleaves with null bytes:

> $d = & wsl.exe --list --quiet
> $d[0]                           # appears as "U b u n t u "
> [byte[]][char[]]$d[0]           # 85,0,98,0,117,0,110,0,116,0,117,0
> $d -match 'Ubuntu'              # false — nulls block the regex

The detection's regex -match 'Ubuntu' never fires.

Fix

One line: strip nulls before regex.

$distros = (& wsl.exe --list --quiet 2>$null) -replace "`0", ""

Plus a comment block so the next reader doesn't reintroduce the bug — matches the local convention (PR #265 / #394 / #396 all carry similar 'caught by X on date Y' notes).

Test plan

  • Verified the bug locally on Windows: byte-level inspection shows interleaved nulls; pre-fix regex never matches; post-fix regex matches.
  • Re-ran install.ps1 with the patched line — + WSL2 + Ubuntu already installed now fires correctly, install proceeds past Phase 1 prereqs.
  • CI verification (whatever clean-install matrix continuum has).

Why this matters

Every Windows user running irm install.ps1 | iex after this PR lands gets past Phase 1 instead of hitting a wall on a working WSL install. The detection is a one-line bug masking a working environment.

🤖 Generated with Claude Code

…regex

Caught during Carl-OOTB Windows validation (continuum-b69f, 2026-05-02).
Symptom: fresh Windows validator with Ubuntu running in WSL2 sees:

  + Git for Windows already installed
  + Docker Desktop already installed
  -> Installing WSL2 + Ubuntu (will require admin elevation + a reboot on first install) ...
  ! Not running as admin. WSL2 install needs admin -- relaunch ...

The 'Installing WSL2' branch fires falsely; install.ps1 thinks Ubuntu
isn't there. But `wsl.exe --list --verbose` clearly shows Ubuntu Running.

Cause: wsl.exe writes --list output as UTF-16 LE (each char is two bytes,
the 'real' byte plus a null). PowerShell reads it as UTF-8, so each
distro name lands as "U`0b`0u`0n`0t`0u`0" instead of "Ubuntu". The
regex `-match 'Ubuntu'` never matches across null-interleaved chars.

Verified the byte pattern locally:
  > $d = & wsl.exe --list --quiet
  > $d[0]   # 'U b u n t u '  ← spaces are nulls in display
  > [byte[]][char[]]$d[0]      # 85,0,98,0,117,0,110,0,116,0,117,0

Fix: strip nulls from wsl output before pattern-matching:
  $distros = (& wsl.exe --list --quiet 2>$null) -replace "`0", ""

One-line change. 8 lines added (with the comment explaining why so the
next person doesn't reintroduce the bug). Behavior on machines without
Ubuntu installed is unchanged — the regex falls through, Install-WSL2
flow continues to the admin-prompt path correctly.
@joelteply joelteply merged commit 0b570c9 into canary May 2, 2026
2 of 3 checks passed
@joelteply joelteply deleted the fix/install-ps1-wsl-detect-utf16 branch May 2, 2026 14:29
joelteply added a commit that referenced this pull request May 2, 2026
#1010)

When WSL2 has lost external network reachability (vEthernet / HNS
corruption is common on Win10/11 after sleep cycles, driver updates,
or system patches), the curl inside `bootstrap.sh | bash` takes 30+
seconds to time out with a cryptic error — and the user has no signal
that the issue is environmental, not continuum-related.

Caught live 2026-05-02 by continuum-b69f during Carl-OOTB Windows
testing (issue #1006). After PR #1005 fixed the WSL detection bug,
install.ps1 delegated into bootstrap.sh successfully — and the WSL-
side curl just hung. The user has no way to tell whether the install
is broken or their box's WSL is broken.

Fix: 5s curl probe to raw.githubusercontent.com from inside WSL
BEFORE the delegate. If it fails, surface explicit Windows-side
remediation:
  1. wsl --shutdown
  2. (as admin) Restart-Service hns -Force
  3. Reboot Windows
  4. Edit %USERPROFILE%\.wslconfig — networkingMode=NAT
  + Re-run command

Pattern: same family as install.sh's friendly-failure phase traps
(#977 work) — fail loudly and tell the user exactly what to try
NEXT, instead of dying silent or with a 30s mystery timeout.

## Tests

- Edit-only PowerShell change, no shape change to delegate path
  when probe passes.
- Linux/Mac CI not affected (probe block is inside install.ps1).
- Live validation pending b69f's box (currently the WSL2 NAT is
  broken on their box per #1006 — perfect natural test case for
  the new probe message).

Co-authored-by: Test <test@test.com>
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant