fix(desktop): WSL backends advertise a Tailscale address that actually reaches them #23030
main fromrefs/pull/23030/head·opened View on GitHubProblem#
With the desktop backend running in WSL and Tailscale running separately on Windows and inside WSL, the pairing link pointed at the Windows Tailscale address. That address never reaches the backend, so pairing from another machine timed out until the user swapped in the WSL tailnet IP by hand.
Change#
When the running primary is the WSL backend, the desktop now asks the distro for its own IPv4 addresses (hostname -I, the probe it already uses) and for its own Tailscale IPs (tailscale ip -4, falling back to /snap/bin/tailscale), both cached for 60s. It then advertises only the addresses the backend actually has:
- NAT networking (the default): the Windows LAN, Tailscale and VPN IPs (such as NetBird's, advertised since #41655) are dropped, and the Tailscale IP the distro's own Tailscale reports is added. A 100.x address from another VPN is not mistaken for Tailscale. That is the address the reporter confirmed works.
- Mirrored networking: the distro shares the Windows addresses, so they are kept.
- Unchanged in every mode: loopback, Tailscale HTTPS (Serve forwards to loopback and checks its own reachability) and custom endpoints.
- If the probe fails, or WSL-only is set but the desktop fell back to the Windows backend, the Windows addresses are kept as before.
The distro's own NAT address (172.x) is never advertised, because other machines can't reach it.
Hyper-V adapters (vEthernet, including the Default Switch WSL creates) now rank behind the physical adapter when picking the LAN address, like the other VM adapters already did. Windows lists the Default Switch first, so main advertised its host-only 172.x address as the default LAN link, and in mirrored mode this PR then dropped LAN entirely because the distro doesn't share that address.
Scope and approval#
Fixes #21889, which Julius accepted as a bug. The change stays inside the desktop's endpoint selection for a WSL primary; Windows-primary behavior is unchanged.
Verification#
Real Windows 11 (26200) host, WSL2 Ubuntu, Tailscale on Windows. Each side's DesktopServerExposure was bundled and run by Windows Node with the real wsl.exe, Tailscale CLI and network interfaces; a real T3 server listened inside the distro on 0.0.0.0:3874; a MacBook on the same tailnet paired (POST /api/auth/browser-session, fresh token each time) against every non-loopback http address each side advertised. Base is merge base 30724e2e9a, head is d3ad25e0ed. Since then the branch has only taken main merges and a test cleanup; the non-test diff against main is identical.
NAT (transcript), with a second Tailscale node inside the distro:
| Advertised | Pairing from the Mac | |
|---|---|---|
| main | Default Switch 172.22.x.x (default), Windows Tailscale 100.115.x.x, Tailscale HTTPS | both failed (connect error, 8s timeout) |
| this PR | loopback, Tailscale HTTPS, distro Tailscale 100.75.x.x | 200 in 0.10s, authenticated: true |
Mirrored (transcript):
| Advertised | Pairing from the Mac | |
|---|---|---|
| main | Default Switch 172.22.x.x (default), Windows Tailscale 100.115.x.x, Tailscale HTTPS | Default Switch failed, Tailscale 200 |
| this PR | loopback, Ethernet 192.168.88.x, Windows Tailscale 100.115.x.x, Tailscale HTTPS | Tailscale 200 |
The Mac is not on the devbox's LAN, so LAN addresses time out from it on either side; the mirrored row shows which LAN address each side picks. vp test run src/backend/DesktopServerExposure.test.ts covers NAT, mirrored (with the Default Switch listed first, as on this host), probe failure, and the Windows-primary fallback.
Packaged desktop app, NAT (comment, transcript): the Windows nightly with a WSL-only backend offered the Default Switch and Windows Tailscale addresses on main, and both timed out from the Mac. With this PR's desktop bundle, it offered the distro's Tailscale IP, and the Mac paired (200).
Not covered: Tailscale HTTPS pairing.
Made with Claude Code (Sonnet 5.5 implementation, Opus 5.5 review) in T3 Code.