fix(desktop): retry transient bearer bootstrap and degrade on session fetch failure #12919
Mergedjamesvillarrubia(GitHub profile, opens in a new tab)merged 7 commits into
main fromrefs/pull/12919/headmerged by juliusmarminge View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:M
- apps/desktop/src/backend/DesktopLocalEnvironmentAuth.ts line 148OutdatedResolvedby jamesvillarrubia(GitHub profile, opens in a new tab)@@ -77,3 +137,12 @@77137 },78138 }).pipe(79139 Effect.provideService(HttpClient.HttpClient, httpClient),140+ // Retry transient failures (502/503/504, transport-level fetch errors,141+ // timeouts, TypeErrors) for up to ~15s before surfacing the bootstrap142+ // error. A single transient /oauth/token failure no longer hard-crashes143+ // the app; the renderer's cookie path already had this resilience.144+ // spaced(500ms) + upTo(15s) gives ~30 attempts in a 15s window.145+ Effect.retry({146+ while: isTransientBearerBootstrapError,147+ schedule: Schedule.spaced(BOOTSTRAP_TRANSIENT_RETRY_INTERVAL).pipe(148+ Schedule.upTo({ duration: BOOTSTRAP_TRANSIENT_RETRY_TIMEOUT }),
github-actions[bot](GitHub profile, opens in a new tab) removed labelssize:M
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
- apps/web/src/environments/primary/auth.ts lines 323 to 328OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -309,3 +309,20 @@309309310310 async function bootstrapServerAuth(urlCredential: string | null): Promise<ServerAuthGateState> {311- const currentSession = await fetchSessionState();311+ // The initial session fetch goes through the desktop bearer-token path312+ // (withPrimaryBearerToken in httpLayer.ts), which calls the main-process313+ // IPC getLocalEnvironmentBearerToken -> DesktopLocalEnvironmentAuth.314+ // A transient failure there (or in the /api/auth/session request itself)315+ // used to escape beforeLoad and render the root error component, crashing316+ // the app on launch. Fall back to requires-auth so the auth gate renders317+ // the pairing UI and the next navigation re-attempts bootstrap, mirroring318+ // how the cookie-exchange path below degrades.319+ let currentSession: AuthSessionState;320+ try {321+ currentSession = await fetchSessionState();322+ } catch (error) {323+ const fallbackAuth: AuthSessionState["auth"] = {324+ policy: "desktop-managed-local",325+ bootstrapMethods: ["desktop-bootstrap"],326+ sessionMethods: ["browser-session-cookie"],327+ sessionCookieName: "t3_session",328+ };
juliusmarminge added labelsmacroscope-review
github-actions[bot](GitHub profile, opens in a new tab) removed labelssize:L
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:S
juliusmarminge merged this76d3c96
juliusmarminge closed this
Sign in to join this conversation.
macroscopeapp[bot](GitHub profile, opens in a new tab) reviewed