Skip to content

Desktop WSL sidecar fails with ServeError when networkingMode=mirrored #37718

Description

@Amamiya23

Description

OpenCode Desktop's managed WSL server consistently fails to start when WSL2 uses mirrored networking. The Desktop recognizes the distro and native Linux binary correctly, but the sidecar exits before health checking with only:

Error: Unexpected error
ServeError

This appears to be a port-allocation handoff issue in packages/desktop/src/main/wsl/sidecar.ts: allocatePort() reserves an ephemeral port on Windows, closes it, and then asks WSL to bind 0.0.0.0 on the same port. With networkingMode=mirrored, Windows and WSL share the port space, and the immediate WSL bind fails.

I reproduced the same allocation sequence independently 8 times; all 8 attempts failed with the identical Unexpected error / ServeError. Starting the same WSL binary directly on a known free fixed port succeeds.

Plugins

None in the WSL config.

OpenCode version

Desktop and WSL binary: 1.18.3

Steps to reproduce

  1. Configure %USERPROFILE%\.wslconfig:

    [experimental]
    networkingMode=mirrored
    dnsTunneling=true
    autoProxy=true
  2. Run wsl --shutdown, then start OpenCode Desktop.

  3. Add an installed WSL2 distro as a managed WSL server.

  4. Observe that the server repeatedly fails before becoming healthy.

Desktop log:

wsl sidecar starting { id: 'wsl:Ubuntu-24.04', distro: 'Ubuntu-24.04' }
wsl sidecar { distro: 'Ubuntu-24.04', stream: 'stderr', text: 'Error: Unexpected error' }
wsl sidecar { distro: 'Ubuntu-24.04', stream: 'stderr', text: 'ServeError' }
wsl sidecar failed to start {
  message: 'WSL server exited before becoming healthy (code=1 signal=null)'
}

Control test that succeeds:

~/.opencode/bin/opencode serve --hostname 0.0.0.0 --port 4096

Expected: the managed WSL sidecar starts while mirrored networking remains enabled.

A possible fix would be to allocate the port from inside WSL, let opencode serve --port 0 report its selected port, or retry when the cross-environment port handoff fails.

Operating System

Windows 11 25H2 build 26200.8875; WSL 2.9.3.0; Ubuntu-24.04 distro.

Terminal

OpenCode Desktop managed WSL server (reproduced independently from PowerShell).

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions