Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(desktop): WSL backend connects with Docker bridges and slow cold starts #6129

Closedrehanhaider(GitHub profile, opens in a new tab)wants to merge 4 commits intomain fromrefs/pull/6129/headopened View on GitHub

What Changed

  • getDistroIp now prefers the default route’s source address, with hostname -I as the fallback.
  • DEFAULT_BACKEND_READINESS_TIMEOUT increases from 1 to 3 minutes.

Scope: two files, 19 lines, two commits. No tests added—the changes are one shell string and one constant.

Why two commits and not one?

Both commits fix the same user-visible hang, so they ship together.

  • The address bug is what #5211 reports and the address commit closes it on its own;
  • the readiness budget is what kept my machine hanging afterwards.

Both causes the exact same symptoms to the user.

Happy to split if you'd rather take them separately.

Why

On Windows, the desktop can remain on “Connecting to WSL…” when Docker is running inside the distro. The backend starts, listens, and answers readiness checks, but the app targets the wrong address and times out too early. Either bug can cause the hang.

Wrong address

getDistroIp previously selected the first IPv4 address from hostname -I, which lists all bound addresses in interface order. With Docker running, a br-* or docker0 bridge can appear first, directing the renderer to an address Windows cannot route to.

This also breaks mirrored networking. isLocalHostIpv4 in DesktopBackendConfiguration maps the backend to loopback only when the reported address belongs to a Windows interface. A Docker bridge does not match, so mirrored-mode users lose the intended loopback path.

The new command asks the kernel for the default route’s source address using ip -4 route get 192.0.2.1. This avoids interface-name matching and RFC1918 heuristics without adding another spawn. The route source is printed before hostname -I, allowing the existing first-match parser and IPv4 validation to remain unchanged.

hostname -I remains the fallback, so distros without iproute2 or a default route behave as they do today. 192.0.2.1 is reserved by RFC 5737, and this is only a routing-table lookup—no packet is sent.

Readiness timed out too early

Readiness currently receives a single 60-second budget. Loading the server bundle and dependencies across /mnt/c regularly takes longer. When the probe expires, the backend process remains alive but is never marked ready, leaving the splash visible even if startup completes seconds later.

The probe polls every 100 ms and resolves immediately when the backend responds, so increasing the budget does not slow fast launches.

Verification

Verified on Windows 11 with WSL2 mirrored networking and three active Docker bridges—the topology reported in #5211:

hostname -I   ->  172.18.0.1  172.17.0.1  172.19.0.1  192.168.1.5
route source  ->  192.168.1.5

Before the timeout change, with the address fix already applied:

  • Two launches abandoned readiness at exactly 60,000 ms.
  • The backend was listening and answering HTTP 200 at 98 seconds.

After both changes:

  • isLocalHostIpv4 matches 192.168.1.5 to the host Wi-Fi adapter.
  • Readiness targets http://127.0.0.1:.
  • The backend returns HTTP 200 and the desktop connects.

The address fix is evidenced by the route lookup above: hostname -I returns the bridge first, so the previous first-match selection resolves to 172.18.0.1, which Windows cannot route to. Measurements were taken against a dev build (dev:desktop), which also waits on the Vite server, so the 98s figure is not directly a packaged-build number.

Validation:

vp test run apps/desktop/src/wsl/DesktopWslEnvironment.test.ts apps/desktop/src/backend/DesktopBackendManager.test.ts

All 52 tests passed. Typecheck and lint are clean for both changed files.

This area is active:

  • #5889 is a draft addressing the same IP-selection bug with two parser helpers, an octet validator, a new timeout constant, and a second sequential spawn. This PR keeps the single spawn, existing timeout, IPv4 gate, and parser; only the command changes.
  • #5998 and #6068 also modify address selection as part of larger rewrites.
  • #5526 replaces the one-shot readiness probe with retries.
  • #5769 addresses slow startup by caching the runtime on the WSL filesystem.

There could be more robustness in the solution but I have preferred simple, tested, and workable solution instead.

Closes #5211 Refs #4535 and #5522.

Checklist

  • This PR is small and focused
  • I explained what changed and why
  • No UI, animation, or interaction changes

Note

[!NOTE]

Fix WSL distro IP detection and extend backend readiness timeout

  • Updates getDistroIpImpl in DesktopWslEnvironment.ts to prefer the IPv4 source address of the default route (ip -4 route get 192.0.2.1) before falling back to hostname -I, which is more reliable in multi-interface WSL environments.
  • Increases DEFAULT_BACKEND_READINESS_TIMEOUT in DesktopBackendManager.ts from 1 minute to 3 minutes to accommodate slower WSL startup times.
  • Behavioral Change: the IP returned by getDistroIpImpl may differ in environments with multiple network interfaces.
Macroscope summarized cce7a8b.
    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: Pro Plus

      Run ID: d9d2e26b-2946-43d9-a691-b7e7054c3b99

      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

      Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

      ❤️ Share
      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. Approvability

      Verdict: Needs human review

      This PR modifies WSL connection logic, including how the distro IP is determined. While the intent is to fix connection issues, changes to IP detection on the critical connection path warrant human verification to ensure correctness across different WSL configurations.

      You can customize Macroscope's approvability policy. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).
    4. 💡 Codex Review

      Here are some automated review suggestions for this pull request.

      Reviewed commit: cce7a8bf82

      ℹ️ About Codex in GitHub

      Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

      • Open a pull request for review
      • Mark a draft as ready
      • Comment "@codex review".

      If Codex has suggestions, it will comment; otherwise it will react with 👍.

      Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

      @@ -688,10 +688,15 @@
      688688 Effect.scoped(
      689689 Effect.gen(function* () {
      690690 const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;
      691- // `hostname -I` prints a space-separated list of all non-loopback
      692- // IPs the distro has bound. The first entry on the WSL2 default
      693- // network is always the eth0 vEthernet address Windows can reach
      694- // directly (no wslhost forwarding required).
      695691 const command = ChildProcess.make(
      696692 "wsl.exe",
      697- [...buildDistroArgs(distro), "--", "sh", "-c", "hostname -I"],
      693+ // `hostname -I` orders by interface, so a Docker bridge can mask the
      694+ // eth0 address NAT mode needs and the host address mirrored mode maps
      695+ // to loopback. The default route's source is printed first and wins;
      696+ // the `hostname -I` tail is the fallback without iproute2.
      697+ [
      698+ ...buildDistroArgs(distro),
      699+ "--",
      700+ "sh",
      701+ "-c",
      702+ "ip -4 route get 192.0.2.1 2>/dev/null | sed -n 's/.* src \\([0-9.]*\\).*/\\1/p'; hostname -I",

      P1 Badge Add focused tests for the new WSL address selection

      This changes backend IP-selection behavior but adds no test exercising the new ordered output. In the reported Docker scenario, a spawner-backed test should verify that the route source wins when hostname -I lists a bridge first, and that the hostname result still wins when iproute2 is unavailable; otherwise shell quoting or output-order regressions can restore the inaccessible address while the existing suite remains green.

      AGENTS.md reference: AGENTS.md:L108-L108

      Useful? React with 👍 / 👎.

      @@ -688,10 +688,15 @@
      688688 Effect.scoped(
      689689 Effect.gen(function* () {
      690690 const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;
      691- // `hostname -I` prints a space-separated list of all non-loopback
      692- // IPs the distro has bound. The first entry on the WSL2 default
      693- // network is always the eth0 vEthernet address Windows can reach
      694- // directly (no wslhost forwarding required).
      695691 const command = ChildProcess.make(
      696692 "wsl.exe",
      697- [...buildDistroArgs(distro), "--", "sh", "-c", "hostname -I"],
      693+ // `hostname -I` orders by interface, so a Docker bridge can mask the
      694+ // eth0 address NAT mode needs and the host address mirrored mode maps
      695+ // to loopback. The default route's source is printed first and wins;
      696+ // the `hostname -I` tail is the fallback without iproute2.
      697+ [
      698+ ...buildDistroArgs(distro),
      699+ "--",
      700+ "sh",
      701+ "-c",
      702+ "ip -4 route get 192.0.2.1 2>/dev/null | sed -n 's/.* src \\([0-9.]*\\).*/\\1/p'; hostname -I",

      P2 Badge Avoid selecting a VPN route source as the WSL address

      When a NAT-mode distro routes 192.0.2.1 through a VPN or exit-node policy table, ip route get returns the tunnel interface's source rather than the Windows-facing WSL address. The first-match parser then passes that address to resolveWslStartConfig, which uses it directly for the readiness and renderer URL; if Windows has no route to the distro's VPN address, the backend again remains stuck connecting. Select the Windows-facing interface/default gateway path rather than the source chosen for an arbitrary external destination.

      Useful? React with 👍 / 👎.

      @@ -60,4 +60,5 @@
      6060 // failures may instead provide their own larger retryLimit when they should
      6161 // self-heal for a while but must not leave the app connecting forever.
      6262 const MAX_PREFLIGHT_FAILURE_ATTEMPTS = 5;
      63-const DEFAULT_BACKEND_READINESS_TIMEOUT = Duration.minutes(1);
      63+// One-shot probe; a WSL backend over /mnt/c regularly needs 60-98s to answer.
      64+const DEFAULT_BACKEND_READINESS_TIMEOUT = Duration.minutes(3);

      P1 Badge Add a focused test for the extended readiness budget

      The intended slow-cold-start behavior is not covered by the existing readiness test, which supplies its own 50 ms timeout and therefore cannot detect this default being reverted or wired to the wrong backend path. Add a TestClock manager test where readiness succeeds after more than one minute but before three minutes and assert that onReady fires; otherwise this backend behavior change can regress while the focused desktop suite remains green.

      AGENTS.md reference: AGENTS.md:L108-L108

      Useful? React with 👍 / 👎.

    5. Checked the IP half on a real WSL2 distro. The new command emits two lines, the route source then the hostname -I list, and the existing parser is

      const candidate = raw.split(/\s+/).find((part) => IPV4_PATTERN.test(part));

      which splits on all whitespace including newlines and takes the first match, so the route source wins and the hostname -I tail stays a fallback exactly as intended. Worth stating explicitly in the comment, because the fix silently depends on that parser taking the first match across the whole output rather than parsing a single line. If anyone later "tidies" it to read one line or to prefer the last match, this regresses without a test noticing.

      The fallback chain also holds up: no iproute2 means sed gets nothing and hostname -I carries it, and no default route means no src field and the same fallback. Both degrade to today's behaviour rather than to nothing.

      The timeout half is the part I would push back on:

      -const DEFAULT_BACKEND_READINESS_TIMEOUT = Duration.minutes(1);
      +// One-shot probe; a WSL backend over /mnt/c regularly needs 60-98s to answer.
      +const DEFAULT_BACKEND_READINESS_TIMEOUT = Duration.minutes(3);

      The justification is specific to a WSL backend running off /mnt/c, but the constant is the default for every backend. After this, a local backend that is simply dead keeps the app in "connecting" for three minutes instead of one, on machines that never had the problem. That is a real cost paid by the majority to fix a case the code can already distinguish, since the WSL path is a separate branch and could carry its own readiness timeout.

      Worth flagging too that #5042 and #5769 both go after the cause rather than the symptom, by getting the backend off /mnt/c and onto the Linux filesystem. If either lands, the 60-98s figure this constant is sized against disappears, and a tripled global timeout is left behind as something nobody remembers to put back. A WSL-scoped override would not have that problem.

    6. Note

      🤖 GPT-5.6 Sol responding on behalf of Theo

      We're closing this PR as we clean up the T3 Code backlog. Thank you for taking the time to put this together.

      Closing this combined revision in favor of reviewing the focused WSL work in #5889 and the recovery work in #5998. Raising the shared readiness timeout to three minutes also delays non-WSL failures and does not fix recovery. Both alternatives are still open, so the WSL cases must remain tracked.

      If you believe we closed this in error, please reopen the PR and leave a comment explaining what we missed. If GitHub does not let you reopen it, leave a comment here and we'll take another look.

Sign in to join this conversation.