Skip to content

fix(sandbox): deliver the WSL boot script over stdin, not argv - #226

Merged
quickbeard merged 1 commit into
mainfrom
fix/wsl-broker-bridge
Aug 13, 2026
Merged

quickbeard merged 1 commit into
mainfrom
fix/wsl-broker-bridge

Conversation

@quickbeard

Copy link
Copy Markdown
Owner

Problem

Every model request from a WSL sandbox failed with Cannot connect to API: other side closed, retrying forever. First live exercise of the WSL broker transport (the vz path was verified; WSL egress had only unit coverage).

Diagnosis (verified live on Windows 11 / WSL 2.7.11)

The provider passed the guest boot script as one argv element: wsl.exe -d <distro> -u root -- /bin/sh -c <script>. wsl.exe reassembles its command line from Windows argv and mishandles the backslash-escaped quotes node's spawn produces. The script's only quoted space — cut -d" " -f3 in the HOST_IP computation — reached the guest corrupted (cut errored with "the delimiter must be a single character"), HOST_IP came out empty, and the socat bridge ran as socat TCP-LISTEN:8788,... TCP::52714, dialing an empty host. Every other quoted string in the script happened to survive quote-stripping because nothing else quotes a space.

Reproduced deterministically: the same line run from a file inside the guest prints the gateway IP; run through wsl.exe argv it prints empty.

Fix

  • Deliver the boot script to /bin/sh over stdin — no Windows argv quoting layer exists to corrupt it.
  • Poll for the default route (up to 10s) instead of capturing whatever the route table says first, so a cold VM boot can't race the bridge.
  • Point the provider test suite's project dir at tmpdir() instead of a literal /tmp, so the WSL backend's tests also pass on the Windows machines it targets.

Verification

  • bun test src/wsl/ from packages/codev-sandbox: 17 pass (fake wsl now serves the boot script over stdin).
  • Live in-app on Windows: guest socat now reads TCP:172.30.48.1:<brokerPort>; a sandbox chat round-trip through the broker produced a model response, ran the Write tool with no permission prompt, and the file landed in the host project folder.

🤖 Generated with Claude Code

@quickbeard
quickbeard force-pushed the fix/wsl-broker-bridge branch from 4b0a765 to 8a48e97 Compare August 13, 2026 15:31
@quickbeard
quickbeard merged commit d34a521 into main Aug 13, 2026
0 of 5 checks passed
@quickbeard
quickbeard deleted the fix/wsl-broker-bridge branch August 13, 2026 15:32
wsl.exe reassembles its command line from Windows argv and drops the
backslash-escaped quotes node spawn produces, which corrupted the one
quoted space in the boot script: `cut -d" " -f3` reached the guest with
a broken delimiter, HOST_IP computed empty, and the socat broker bridge
dialed an empty host - every model request from a WSL sandbox failed
with "other side closed". Feed /bin/sh the script over stdin (no
quoting layer to corrupt), poll for the default route on cold VM boots,
and run the provider test suite's project dir through tmpdir() so it
also passes on Windows machines.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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