Skip to content
Source
Sign inSign up
pingdotgg/t3code

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

Mergedlgwacker(GitHub profile, opens in a new tab)merged 23 commits intomain fromrefs/pull/5526/headmerged by juliusmarminge View on GitHub

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

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

Fixes #5522


Note

Medium Risk Changes desktop startup and readiness callbacks (onReadinessFailure may fire repeatedly); limited to backend process lifecycle with new test coverage.

Overview runBackendProcess no longer treats HTTP readiness as a single attempt with one timeout budget. It loops waitForHttpReady while the backend child is still running: each round gets a fresh budget; on timeout it invokes onReadinessFailure and starts another round; on success it invokes onReady and stops. The loop runs in a scoped fork so it is cancelled when the process exits.

This fixes cases where a slow WSL cold boot outlasts the first budget but the process later becomes healthy—the app was stuck on “Connecting to WSL…” with no further probes.

Behavioral note: onReadinessFailure may run multiple times before onReady. The fast path (ready within the first budget) is unchanged.

A TestClock test asserts re-probing across expired budgets until HTTP returns 200.

Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 441ed06c7bd10c6e8811a983adbb45e03b06888f. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).

Note

Re-probe backend HTTP readiness continuously while the process is alive

Previously, runBackendProcess gave up after the first readiness timeout. Now it loops readiness probing across multiple timeout budgets, calling onReadinessFailure after each expired budget and onReady once a probe succeeds. The loop is forked in the run scope so it stops automatically when the child process exits. Behavioral Change: onReadinessFailure may now be called multiple times before onReady is eventually invoked.

Macroscope summarized 441ed06.
    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: 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.
    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: 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](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).
    4. One convention finding: the new readiness probe recovers a statically known tagged failure with Effect.result + Result.isSuccess instead of Effect.catchTags. See the inline comment.

      Posted via Macroscope — Effect Service Conventions
    5. 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.

    6. 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.

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

    8. Independent verification on Linux (WSL2 Ubuntu, Node 24), since this has been sitting a while.

      Branch as submitted:

      ✓ src/backend/DesktopBackendManager.test.ts (25 tests)
        Tests  25 passed (25)

      Then swapping only DesktopBackendManager.ts for the current main copy and keeping this PR's test file, to check the new test actually pins the fixed behaviour rather than passing either way:

      × re-probes readiness after the first budget expires while the backend is still alive
        AssertionError: expected 1 to equal 2
      
        Tests  1 failed | 24 passed (25)

      One targeted failure, the other 24 unaffected. That is the useful shape: the new test fails without the source change and passes with it, and it is not incidentally coupled to the rest of the file.

      The branch is behind main but still reports MERGEABLE, and the source file applies cleanly, so the staleness looks cosmetic rather than a conflict risk.

      No findings against the change itself from my side.

    9. juliusmarminge merged this160c76c

    10. juliusmarminge closed this

Sign in to join this conversation.