Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(desktop): a backend busy right after startup no longer ends in a fatal HTTP 500 screen #34918

Mergedjuliusmarmingemerged 2 commits intomain fromrefs/pull/34918/headmerged by maria-rcks View on GitHub

juliusmarmingecommented

DesktopLocalEnvironmentAuth.getBearerToken wrapped its whole transient-retry loop (retrying 502/503/504, fetch errors and the 10 s per-attempt RemoteEnvironmentAuthTimeoutError every 500 ms) in a 15 s overall timeout. That covers only one 10 s /oauth/token attempt, so a backend stalled for more than about 15 s right after reporting ready failed the desktop bearer bootstrap, and the web client showed the fatal 'Primary environment request failed during fetch-session-state (HTTP 500)' screen. The fix raises BOOTSTRAP_TRANSIENT_RETRY_TIMEOUT to 60 s and adds a one-line comment saying why. Each 10 s attempt still times out and is retried; the bootstrap now gets several attempts and succeeds once the backend answers. I checked the IPC path (window.ts getLocalEnvironmentBearerToken -> preload -> web desktopAuth.ts): nothing else applies a shorter timeout, so the 60 s budget is the one that counts. Non-transient errors such as a rejected credential still fail at once (the existing test still passes). The repro test from factory/repro-23378 failed on its base and passes with the fix. No new regex or parser.

Fixes pingdotgg/t3code#23378

Reproduction on main

Commit bfec2754b8 (origin/main). Built with vp run build:desktop, then ran Electron under headless-desktop (Xvfb) with --no-sandbox --disable-gpu, a fresh T3CODE_HOME and a fresh --user-data-dir. (1) Normal launch: the welcome/onboarding screen loads. (2) A scratch NODE_OPTIONS --require preload blocked the backend's event loop for 30 s when it received the first POST /oauth/token. That is the reporter's condition: an event-loop stall right after the backend reports ready. The desktop trace matched the report exactly, twice: bootstrapRemoteBearerSession failed with RemoteEnvironmentAuthTimeoutError at 10.0 s, the retry was interrupted at 4.5 s, and desktop.localEnvironmentAuth.getBearerToken failed with DesktopLocalEnvironmentAuthSessionBootstrapError at 15.0 s. At 16 s the window showed the T3 splash. At 60 s, 24 s after the backend had recovered, it still showed the fatal 'Something went wrong. Primary environment request failed during fetch-session-state (HTTP 500).' screen with Try again / Reload app. (3) Control: SIGSTOP of the backend 50 ms after 'backend ready' came after the token exchange, which completes about 8 ms after ready. That stall hit the session fetch instead, and main showed a recoverable 'Still connecting' screen and recovered automatically after the backend resumed. So the fatal path needs the stall to land on /oauth/token. Unit test: one case added to DesktopLocalEnvironmentAuth.test.ts, in which the HTTP client never answers before t=30 s and answers afterwards. It fails on main (getBearerToken fails) and passes with the budget raised to 60 s (checked locally, not committed).

Evidence

Fresh Linux Electron launches under Xvfb, 1280×900, light theme, isolated state, no seeded data. The same preload blocks the backend event loop for 30 seconds on the first POST /oauth/token. No retry or reload clicks. Observe through 60 seconds.

BeforeAfter
bfec2754b8a7d9f1b35f
Before: fatal HTTP 500 persists after backend recoveryAfter: onboarding loads automatically
Startup recordingStartup recording

Base remains fatal at 60 seconds; head reaches onboarding by 40 seconds without intervention. Both final stills match another screenshot taken 500 ms earlier pixel-for-pixel.

Driver · Stall preload · Reproduction instructions · Sanitized timing transcript

AI-assisted; verified with the tests and tools listed above.

Not shown:

  • Windows and macOS desktop startup were not exercised; this proof uses real Linux Electron under Xvfb.

Tests

vp test run src/backend/DesktopLocalEnvironmentAuth.test.ts (apps/desktop): before the fix 1 failed / 3 passed (the repro case); after the fix 4 passed. vp run check:changed: format, lint, knip, typecheck (2 packages), test (1 file) all pass. The commit hooks (fmt, lint, knip) passed.

Not in this change

  • apps/web/src/environments/primary/auth.ts:54 makes up status 500 for a desktop IPC failure with no HTTP status, so the error screen reports 'HTTP 500' although the server never returned one.
  • The root route's beforeLoad treats a failed desktop bearer bootstrap as fatal and does not retry it once the backend recovers. A stall longer than 60 s still ends on that screen until the user clicks Reload.
  • Open PR #23805 makes the same budget change and could be closed as superseded.

AI-assisted; verified with the tests and tools listed above.

    1. github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted

    2. Approvability

      Verdict: Needs Human Approval

      Macroscope's review found this PR requires human approval — The desktop bootstrap retry window increases from 15 to 60 seconds, allowing recovery from longer backend stalls but delaying persistent-failure feedback. This changes the default startup waiting behavior and requires human confirmation of that tradeoff.

      You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).
    3. coderabbitai[bot](GitHub profile, opens in a new tab)commented
      Explain Change →

      No actionable comments were generated in the recent review.

      Walkthrough

      The desktop bearer bootstrap retry timeout increases from 15 seconds to 60 seconds. A test verifies that authentication succeeds after a delayed token exchange and four requests.

      Changes: Desktop authentication bootstrap

      Layer / File(s)Summary
      Extend the retry window and test delayed token exchange
      apps/desktop/src/backend/DesktopLocalEnvironmentAuth.ts, apps/desktop/src/backend/DesktopLocalEnvironmentAuth.test.ts
      The bootstrap retry timeout increases to 60 seconds. The test advances the clock by 45 seconds and checks that authentication succeeds after four requests.

      Estimated code review effort: 2 (Simple) | ~10 minutes

      Change: Bug fix · Severity of issue fixed: Medium

      Suggested reviewers: jamesvillarrubia, maria-rcks

      Merge Risk: Minimal · up to a7d9f

      The desktop app now tolerates a backend stall of up to roughly a minute during startup before showing a fatal error. No merge-blocking risk remains. Stalls longer than 60 seconds still end in the fatal screen, which the author notes is out of scope.

      Pre-merge checks: Passed 4

      Check nameStatusExplanation
      Title checkPassedThe title names the desktop startup fix, which matches the change: the bearer-bootstrap retry budget is raised from 15 s to 60 s so a backend busy right after startup no longer ends on the fatal HTTP …
      Linked Issues checkPassedLinked issue #23378 is the only active direct target. Its core requirement: a backend delay during desktop startup must not produce the fatal screen before the backend recovers. The diagnosis names th…
      Out of Scope Changes checkPassedThe change set has three parts: the BOOTSTRAP_TRANSIENT_RETRY_TIMEOUT value change with an explanatory comment in DesktopLocalEnvironmentAuth.ts (+2/-1), and one added test case in DesktopLocalEnviron…
      Description checkPassedThe description is thorough and follows the template. It has a Problem section that states the bug and its trigger. It has a Change section that explains the 15 s to 60 s budget raise and why it fixes…
      Full details: Title check

      Explanation

      The title names the desktop startup fix, which matches the change: the bearer-bootstrap retry budget is raised from 15 s to 60 s so a backend busy right after startup no longer ends on the fatal HTTP 500 screen. It is a conventional commit title in plain language, and it states the primary change.

      Full details: Linked Issues check

      Explanation

      Linked issue #23378 is the only active direct target. Its core requirement: a backend delay during desktop startup must not produce the fatal screen before the backend recovers. The diagnosis names the 15 s BOOTSTRAP_TRANSIENT_RETRY_TIMEOUT wrapping the whole retry loop as the cause. The PR raises that constant to 60 s in apps/desktop/src/backend/DesktopLocalEnvironmentAuth.ts. Each /oauth/token attempt keeps its 10 s timeout and the 500 ms retry continues, so several attempts now fit in the budget. The added test in DesktopLocalEnvironmentAuth.test.ts models a backend that stalls for 30 s during token exchange and expects success. The PR objectives scope the issue to a /oauth/token delay on first load. Under that scope the change addresses the requirement. The issue also lists two related points: the web side does not retry, and the error screen shows a status the server never sent. The PR description and objectives state these are out of scope. They are diagnosis context, not separate acceptance criteria in the active scope. Limit: a stall longer than 60 s still reaches the fatal screen. The PR states this limit explicitly.

      Full details: Out of Scope Changes check

      Explanation

      The change set has three parts: the BOOTSTRAP_TRANSIENT_RETRY_TIMEOUT value change with an explanatory comment in DesktopLocalEnvironmentAuth.ts (+2/-1), and one added test case in DesktopLocalEnvironmentAuth.test.ts (+32/-0). The constant change implements #23378. The test supports that change and verifies the 30 s stall case. The PR description reports no changes to the web client, the IPC path, or the HTTP 500 mapping. Those items are listed under 'Not in this change' and are not in the diff summary. No unrelated change was found in the summary.

      Full details: Description check

      Explanation

      The description is thorough and follows the template. It has a Problem section that states the bug and its trigger. It has a Change section that explains the 15 s to 60 s budget raise and why it fixes the problem. It has a Scope section that links issue #23378 and describes a bug fix. It has a Verification section with the unit test results, a reproduction on main, and before/after evidence. The author states what was not checked: Windows and macOS startup. The Scope section does not explicitly state that the change is a bug fix rather than a feature, but the linked issue and the wording make that clear. The description also includes a 'Not in this change' section that names follow-up work. The template's comment asks for a model and harness attribution when an agent was used. The description says 'AI-assisted' but does not name the model or harness, so this is a minor gap.

      Finishing Touches

      Generate unit tests (beta)

      • Commit to this branch
      • Create a new PR
      • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
      Recent review info

      Run configuration

      Commits

      Reviewing files that changed from the base of the PR and between 8024e50c6fef20525f5360448cede149fbda460f and a7d9f1b35f4f00ad3d855a8ce3a4fb22267aa97b.

      Files selected for processing: 2

      • apps/desktop/src/backend/DesktopLocalEnvironmentAuth.test.ts
      • apps/desktop/src/backend/DesktopLocalEnvironmentAuth.ts

      Limit details: You’ve used all 10 included reviews currently available.

    4. tanstack-source added labelsbug

    5. maria-rcks merged thise3c7c08

    6. maria-rcks closed this

Sign in to join this conversation.