t3code icon indicating copy to clipboard operation
t3code copied to clipboard

fix(desktop): keep probing backend readiness while the process is alive

Open lgwacker opened this issue 3 months ago • 2 comments

What Changed

runBackendProcess (apps/desktop/src/backend/DesktopBackendManager.ts) now probes backend readiness in a loop while the child process is still alive, instead of probing exactly once with a fixed 60s budget and then never retrying.

Each round gets a fresh readiness budget; on timeout, onReadinessFailure fires and the loop immediately starts another round; the loop stops on success or is torn down with the run scope when the child exits. Behavior is unchanged when the backend becomes ready within the first budget.

Why

The readiness probe was one-shot: after the 60s budget expired, the app never probed again even though the backend process kept running and became healthy ~20s later. A slow WSL cold boot (server bundle loading across /mnt/c, or a first launch right after an update — cold Windows file cache + Defender re-scan) routinely exceeds that budget, so wsl-only users were left stuck on the "Connecting to WSL…" splash forever with no retry and no recovery path. This is the failure documented in #4535 and filed as #5522. It makes the app resilient regardless of how long boot takes, without widening the budget or changing the fast-path.

UI Changes

None.

Checklist

  • [x] This PR is small and focused
  • [x] I explained what changed and why
  • [x] I included before/after screenshots for any UI changes
  • [x] I included a video for animation/interaction changes

Fixes #5522


[!NOTE] Medium Risk Changes desktop backend bootstrap timing and readiness callbacks (including repeated onReadinessFailure), which affects WSL connection UX but not auth or data paths; fast-path behavior when ready within the first budget is unchanged.

Overview runBackendProcess no longer treats backend HTTP readiness as a single shot. It runs probeReadiness in a scoped loop: each round calls waitForHttpReady with a full timeout budget, fires onReadinessFailure when that round times out, and repeats until HTTP 200 (then onReady) or the child exits and the fork is torn down.

This fixes slow WSL cold boots where the backend stayed alive and became healthy after the first budget expired, which previously left the app stuck on “Connecting to WSL…” with no further probes.

A new test drives TestClock through multiple expired budgets before a 200 and asserts onReadinessFailure and onReady counts plus probe persistence.

Reviewed by Cursor Bugbot for commit 137cb05740e9e642157b12cbc9c0f98469c839c5. Bugbot is set up for automated code reviews on this repo. Configure here.

[!NOTE]

Fix runBackendProcess to keep probing backend readiness while the process is alive

Previously, runBackendProcess stopped probing after the first readiness timeout. It now loops, calling waitForHttpReady repeatedly across successive timeout budgets until the backend responds with HTTP 200, invoking onReadinessFailure on each failed attempt and onReady once on success. A new internal effect desktop.backendProcess.probeReadiness encapsulates a single probe attempt and returns a boolean to drive the loop.

Macroscope summarized 137cb05.

lgwacker avatar Aug 06 '26 14:08 lgwacker

[!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: be66c833-ab42-437e-a7e3-1952f7688b0b

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.

coderabbitai[bot] avatar Aug 06 '26 14:08 coderabbitai[bot]

Approvability

Verdict: Approved bc0c114

This is a focused bug fix that converts a one-shot backend readiness probe into a retry loop, preventing the app from getting stuck on 'Connecting to WSL...' when startup is slow. The change is self-contained with comprehensive test coverage.

You can customize Macroscope's approvability policy. Learn more.

macroscopeapp[bot] avatar Aug 06 '26 14:08 macroscopeapp[bot]

Verified on Windows 11, Node 24: 25/25 pass on this branch. Reverting only DesktopBackendManager.ts to main while keeping the new test fails it with expected 1 to equal 2, so it does cover the regression rather than just the current behavior, and the other 24 still pass.

Confirmed the premise on main separately — waitForHttpReady is called once at DesktopBackendManager.ts:566 with a catchTag on the timeout and no retry.

This is unit-level only. I did not run the packaged app against WSL, so I can't speak to the end-to-end "Connecting to WSL…" case.

CDVolvik avatar Aug 10 '26 07:08 CDVolvik

Two of the open Windows issues look like they're already covered here, if it's useful to link them:

#5364 describes exactly this failure — backend alive, desktop headless. On main the probe is forked and its timeout is non-fatal, so the child survives, but onReady never fires, and window creation hangs off it (DesktopBackendPool.ts:292), so no BrowserWindow gets created. Looping while the child is alive is that issue's own suggested direction 3.

#4209 is partly stale against current main. Its headline symptom is the desktop stopping the backend and shutting down, and that no longer happens: onReadinessFailure (DesktopBackendManager.ts:930) only logs a warning and writes a failure snapshot, and nothing wires app.quit to readiness failure. What survives from that report is the headless state this PR fixes.

One thing it doesn't cover, in case it's worth splitting out: discovery still blocks the readiness endpoint. #4209 measured checkCursorProviderStatus at about 22.7s. This makes a slow boot survivable rather than fast, so #5364's suggested direction 1 — serving minimal readiness before expensive initialization — stays open.

I also re-ran the suite on Linux (Ubuntu 26.04 under WSL2, Node 24): 25/25 here against 24/24 on main. Still unit-level, so my earlier caveat stands — I haven't run the packaged app against a WSL backend. Electron's binary isn't installed in that environment, so I stubbed path.txt; the tests mock everything and never launch it.

CDVolvik avatar Aug 10 '26 18:08 CDVolvik

@maria-rcks @juliusmarminge help a sad windows user!!

lgwacker avatar Aug 13 '26 19:08 lgwacker