Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(desktop): resolve WSL distro IP from the default route, not hostname -I order #8438

ClosedSanjay-doppalapudi(GitHub profile, opens in a new tab)wants to merge 7 commits intomain fromrefs/pull/8438/headopened View on GitHub

What Changed

getDistroIpImpl in apps/desktop/src/wsl/DesktopWslEnvironment.ts no longer trusts hostname -I ordering. It now gathers IPv4 candidates from two probes — the src field of ip -4 route get 1.1.1.1 (a pure routing-table lookup, no packet is sent), then the hostname -I list — and validates them against the Windows-side interfaces in ranked passes, strongest signal first: a candidate inside the subnet of a WSL-named vEthernet adapter (NAT mode — checked first so a Docker bridge address that coincides with some other Windows adapter cannot pose as mirrored mode), then a candidate equal to a Windows interface address (mirrored networking, which has no NAT adapter to match; the existing isLocalHostIpv4 detection then swaps the renderer URL to loopback), then a candidate inside any other Windows interface's subnet (renamed/custom Hyper-V switches). The ranking means a Windows-side VPN whose 10.x/172.x space overlaps an in-distro tunnel or Docker bridge cannot capture the probe while the real WSL adapter has a match. Candidates are validated as strict dotted quads (four octets, each 0–255). When no candidate matches a Windows interface, a lone candidate is still returned, but several candidates without evidence yield no address so the caller falls back to loopback instead of guessing an unreachable one. The probe logs the full candidate list plus the chosen address.

The parsing/selection is extracted into exported parseDistroIpCandidates / pickDistroIp / windowsIpv4Interfaces pure helpers with unit tests, following the file's existing pattern for the other probe parsers. The Windows interfaces are read through the existing DesktopNetworkInterfaces service (acquired in the layer, passed into the probe) rather than a direct node:os call, so the dependency is visible in the layer's requirements and substitutable in tests.

Why

Fixes #5211.

The desktop app hangs on "Connecting to WSL..." forever whenever Docker has created bridge networks inside the distro: hostname -I lists the bridge addresses (172.17.x.x, ...) before eth0, and the code took the first IPv4 as the renderer-visible host — an address Windows can never reach. docker network prune only rotates which unreachable bridge IP gets picked.

Validating against the Windows-side interfaces (rather than preferring the Internet route's src outright) also keeps distros with an in-distro VPN/tunnel/VRF working: there the route to 1.1.1.1 reports the tunnel's address, which Windows cannot reach, while eth0 remains the correct choice.

This additionally repairs mirrored-mode detection in the Docker scenario — with a bridge IP the isLocalHostIpv4 host-interface comparison always failed, so the loopback fallback (which the issue reporter confirmed reachable) was never taken.

Verified with vp test run apps/desktop/src/wsl/DesktopWslEnvironment.test.ts (44 passed, including 16 new cases covering the Docker-bridge fixture from the issue in both NAT and mirrored mode, a bridge address coinciding with another Windows adapter, the in-distro VPN case, the overlapping Windows-VPN case, custom switch names, octet validation, the lone-candidate/no-evidence rules, and the interface flattening), plus desktop typecheck, lint, and vp fmt --check on the touched files.

Checklist

  • This PR is small and focused
  • I explained what changed and why
  • I included before/after screenshots for any UI changes (N/A — no UI change)
  • I included a video for animation/interaction changes (N/A)

Note

Resolve WSL distro IP from default route instead of hostname -I order

  • Changes the WSL IP probe in getDistroIpImpl to run a combined route-lookup and hostname command, then parse and rank candidates against Windows IPv4 interfaces instead of returning the first hostname token
  • Adds parseDistroIpCandidates (ordered, deduplicated IPv4 extraction), pickDistroIp (subnet-match ranking: WSL adapter first, exact interface match second, other subnets third), windowsIpv4Interfaces (adapter flattener), and ipv4ToInt/isValidIpv4 (strict dotted-quad validation rejecting octets > 255)
  • Wires DesktopNetworkInterfaces as a layer dependency so host interface data is available to every distro-IP probe
  • Adds test suites for all new helpers covering route ordering, deduplication, subnet precedence, mirrored-mode equality, and ambiguous-candidate null results
  • Updates DesktopBackendConfiguration test runtime to provide an empty DesktopNetworkInterfaces implementation
  • Behavioral Change: getDistroIpImpl now returns an empty option (instead of a best-effort first token) when no candidate matches ranking rules and multiple unmatched candidates exist; callers of getDistroIp should handle the empty case
Macroscope summarized 5675129.

Note

Medium Risk Changes Windows↔WSL connectivity URL selection for all WSL backends; logic is heavily unit-tested but wrong IP choice would still block connection until loopback fallback.

Overview Fixes #5211 by changing how the desktop app picks the WSL address the renderer uses instead of taking the first IPv4 from hostname -I.

WSL distro IP — getDistroIp now runs a shell probe that combines ip -4 route get 1.1.1.1 (route src) with hostname -I, parses candidates via parseDistroIpCandidates, and chooses one with pickDistroIp against Windows IPv4 adapters from DesktopNetworkInterfaces (WSL vEthernet subnet first, then exact Windows IP for mirrored mode, then other subnets). Invalid octets are rejected; a single unmatched candidate is kept, but several unmatched candidates return none so configuration can fall back to loopback rather than a Docker bridge or in-distro VPN address. The WSL layer now depends on DesktopNetworkInterfaces; backend configuration tests stub that service for the sync runSync label probe.

The diff also includes format-only edits (arrow/Effect.map wrapping, generated schema unions, minor spacing) across mobile, server, and packages with no behavior change there.

Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 5675129e82b26df2a7e71cf6dc0282afd28936dc. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).
    1. coderabbitai[bot](GitHub profile, opens in a new tab)commented

      Important

      Review skipped

      Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

      ⚙️ Run configuration

      Configuration used: Repository UI

      Review profile: CHILL

      Plan: Team

      Run ID: c48fc102-ff05-4f73-b2b0-277b1c48cf98

      You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

      Use the checkbox below for a quick retry:

      • 🔍 Trigger review

      Warning

      Your free Security trial is over. An organization admin can upgrade to Advanced for continuous pull request security review or dismiss this notice.


      Comment `@coderabbitai help` to get the list of available commands.
    2. github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched

    3. macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      Approvability

      Verdict: Not approved

      Macroscope's review found this PR not approvable — The substantive change alters WSL backend startup and renderer connectivity by introducing a nontrivial ranked IP-selection algorithm based on distro routes and Windows interfaces. Although the change is focused and well-tested, its cross-layer impact on an existing connection path merits human review.

      You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).
    4. One convention violation found: the new distro-IP probe reads the Windows network interfaces through a direct node:os call inside the Effect service implementation instead of acquiring the existing DesktopNetworkInterfaces service from the environment.

      Posted via Macroscope — Effect Service Conventions
    5. Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

      Fix All in Cursor ❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the [Cursor dashboard](https://www.cursor.com/dashboard/bugbot).

      Want fixes drafted automatically? Bugbot Autofix can create code changes for findings. A team admin can enable Autofix in the Cursor dashboard.

      Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 302442938aef58b31b648a7f47a77d95d33c38e2. Configure [here](https://www.cursor.com/dashboard/bugbot).
    6. Note

      🤖 GPT-6 Astra (preview) responding on behalf of Theo

      This note is part of an automated cleanup pass.

      Carryover from #5889 at 34a6876d09: retain strict IPv4 octet validation, accept only an exact src token rather than prefsrc, and return no address when hostname -I offers several candidates without enough evidence to choose one. Its route query and fallback share one timeout and must not start the fallback after that budget expires. Keep these checks alongside Windows-interface/VPN matching. The existing one-address NAT test does not verify the reported mirrored-mode Docker case.

    7. juliusmarminge closed this

    8. Closing as part of the open-PR backlog sweep (wave 2).

      Reason: WSL default-route IP fix drowned in a 35-file contaminated tree; no realistic merge path.

      Reopen if this is still wanted and you’re willing to rebase onto current main.

Sign in to join this conversation.