Skip to content

The agent that grows with you

fix(desktop): keep the cold-boot recovery overlay up while main retries behind it

wzslr321dbc18a0591fc
diff --git a/apps/desktop/src/app/gateway/hooks/use-gateway-boot.test.tsx b/apps/desktop/src/app/gateway/hooks/use-gateway-boot.test.tsx
index 5c26ae05ae2..65192a94129 100644
--- a/apps/desktop/src/app/gateway/hooks/use-gateway-boot.test.tsx
+++ b/apps/desktop/src/app/gateway/hooks/use-gateway-boot.test.tsx
@@ -2064,6 +2064,124 @@ describe('useGatewayBoot remote reconnect loop (real hook, fake socket)', () =>
expect(desktop.getConnection).toHaveBeenCalledTimes(6)
})
+ it('a failed cold boot keeps its recovery surface while main replays cold-boot progress behind it (#112899)', async () => {
+ // Main keeps startHermes() available after the renderer's boot concluded
+ // in failure; any later getConnection() caller re-enters it and replays
+ // `backend.resolve` (running:true — hides BootFailureOverlay) then
+ // `backend.remote` (error:null — the store's late-progress guard only
+ // holds while running is false, so this wipes boot.error). Each replay
+ // buried the recovery surface under the CONNECTING overlay for the whole
+ // ~45s readiness wait, indefinitely.
+ const desktop = fakeDesktop()
+ desktop.getConnection = vi.fn(async () => {
+ throw new Error('Hermes backend did not become ready: getaddrinfo ENOTFOUND gateway.tailnet.example')
+ })
+ desktop.getBootProgress = vi.fn(async () => ({
+ error: 'Hermes backend did not become ready: getaddrinfo ENOTFOUND gateway.tailnet.example',
+ fakeMode: false,
+ message: 'Desktop boot failed',
+ phase: 'backend.error',
+ progress: 24,
+ retryable: false,
+ running: false,
+ timestamp: Date.now()
+ }))
+ ;(window as { hermesDesktop?: unknown }).hermesDesktop = desktop
+
+ render(<Harness />)
+ await flushAsync()
+
+ expect($desktopBoot.get().error).toBeTruthy()
+ expect($desktopBoot.get().running).toBe(false)
+
+ for (let replay = 0; replay < 2; replay += 1) {
+ act(() => {
+ desktop.emitBootProgress({
+ error: null,
+ fakeMode: false,
+ message: 'Resolving Hermes backend',
+ phase: 'backend.resolve',
+ progress: 8,
+ running: true,
+ timestamp: Date.now()
+ })
+ desktop.emitBootProgress({
+ error: null,
+ fakeMode: false,
+ message: 'Connecting to remote Hermes backend at https://gateway.tailnet.example:8443',
+ phase: 'backend.remote',
+ progress: 24,
+ running: true,
+ timestamp: Date.now()
+ })
+ })
+
+ // BootFailureOverlay renders on `boot.error && !boot.running`.
+ expect($desktopBoot.get().error).toBeTruthy()
+ expect($desktopBoot.get().running).toBe(false)
+ }
+ })
+
+ it('a boot failed by a startup backend exit still shows the progress of its own bounded retry (#112899)', async () => {
+ // The failure latch must not outlive the boot it describes: onBackendExit
+ // concludes the in-flight boot, but boot()'s catch may then classify the
+ // failure as retryable and start a FRESH lifecycle. That retry's progress
+ // events must reach the overlay, or the retry runs blind behind a stale
+ // "couldn't start" surface.
+ const desktop = fakeDesktop()
+ let rejectConnection: (err: Error) => void = () => undefined
+ desktop.getConnection = vi
+ .fn()
+ .mockImplementationOnce(
+ () =>
+ new Promise<never>((_resolve, reject) => {
+ rejectConnection = reject
+ })
+ )
+ .mockImplementation(() => new Promise<never>(() => undefined))
+ desktop.getBootProgress = vi.fn(async () => ({
+ error: 'Could not verify the existing SSH backend.',
+ fakeMode: false,
+ message: 'Desktop boot failed',
+ phase: 'backend.error',
+ progress: 24,
+ retryable: true,
+ running: false,
+ timestamp: Date.now()
+ }))
+ ;(window as { hermesDesktop?: unknown }).hermesDesktop = desktop
+
+ render(<Harness />)
+ await flushAsync()
+
+ act(() => backendExit?.({ code: 1, signal: null }))
+ expect($desktopBoot.get().error).toBeTruthy()
+
+ await act(async () => {
+ rejectConnection(new Error('Could not verify the existing SSH backend.'))
+ await vi.advanceTimersByTimeAsync(0)
+ })
+ await advanceBackoff()
+
+ expect(desktop.getConnection).toHaveBeenCalledTimes(2)
+ expect($desktopBoot.get().error).toBeNull()
+
+ act(() => {
+ desktop.emitBootProgress({
+ error: null,
+ fakeMode: false,
+ message: 'Resolving Hermes backend',
+ phase: 'backend.resolve',
+ progress: 8,
+ running: true,
+ timestamp: Date.now()
+ })
+ })
+
+ expect($desktopBoot.get().phase).toBe('backend.resolve')
+ expect($desktopBoot.get().running).toBe(true)
+ })
+
it('FIX #82679: a NON-retryable boot failure (local / confirmed reauth) fails immediately without auto-retry', async () => {
const desktop = fakeDesktop()
desktop.getConnection = vi.fn(async () => {
diff --git a/apps/desktop/src/app/gateway/hooks/use-gateway-boot.ts b/apps/desktop/src/app/gateway/hooks/use-gateway-boot.ts
index 0d2005a91dd..e76e5e14617 100644
--- a/apps/desktop/src/app/gateway/hooks/use-gateway-boot.ts
+++ b/apps/desktop/src/app/gateway/hooks/use-gateway-boot.ts
@@ -251,6 +251,14 @@ export function useGatewayBoot({
// signals that fire around wake (power resume, network online, the window
// becoming visible).
let bootCompleted = false
+ // The other way a cold boot concludes. Main keeps startHermes() available
+ // after the renderer gave up, and every later getConnection() caller
+ // re-enters it, replaying `backend.resolve` (running:true) then
+ // `backend.remote` (error:null) onto a renderer whose boot is over. Without
+ // this latch each replay hid BootFailureOverlay for the whole readiness
+ // wait (#112899). Cleared wherever a FRESH boot lifecycle starts: a soft
+ // switch and the renderer's own bounded retry (#82679).
+ let bootFailed = false
let reconnecting = false
let reconnectTimer: ReturnType<typeof setTimeout> | null = null
let reconnectAttempt = 0
@@ -690,6 +698,7 @@ export function useGatewayBoot({
escalated = false
reauthNotified = false
primaryReauthError = null
+ bootFailed = false
gateway.close()
// The primary mode is changing, but registered v2 sources remain
@@ -777,6 +786,7 @@ export function useGatewayBoot({
if (mayPublishFailure) {
const message = err instanceof Error ? err.message : String(err)
+ bootFailed = true
failDesktopBoot(message)
// Only the current owner may lower loading. A failed begin returns no
@@ -802,11 +812,13 @@ export function useGatewayBoot({
}
// Soft switch / post-boot startHermes re-emits progress — ignore so the
- // cold-boot CONNECTING overlay stays down. Post-boot errors are gated:
+ // cold-boot CONNECTING overlay stays down. A boot that ended in failure
+ // is concluded too: replaying its steps would take the recovery overlay
+ // back down. Post-boot errors are gated:
// only confirmed reauth takes the full-screen recovery surface. Transient
// ticket-mint / host-unreachable failures must stay in the reconnect loop
// (otherwise a 1–3 min blip bricks reading/drafting behind "couldn't start").
- if ($gatewaySwitching.get() || bootCompleted) {
+ if ($gatewaySwitching.get() || bootCompleted || bootFailed) {
if (payload.error && shouldApplyPostBootProgressError(payload.error)) {
primaryReauthError = payload.error
@@ -1136,6 +1148,9 @@ export function useGatewayBoot({
// — a toast whose button does nothing would only mislead. Fail the
// overlay and stop there.
if ($desktopBoot.get().running || $desktopBoot.get().visible) {
+ // Concludes the in-flight boot on its behalf, so it latches like the
+ // catch blocks that conclude one.
+ bootFailed = true
failDesktopBoot(translateNow('boot.errors.backgroundExitedDuringStartup'))
return
@@ -1290,6 +1305,7 @@ export function useGatewayBoot({
if (retryable && !cancelled) {
const delay = reconnectBackoffDelayMs(bootRetryAttempt, { baseDelayMs: BOOT_RETRY_BASE_DELAY_MS })
bootRetryAttempt += 1
+ bootFailed = false
resumeDesktopBootForRetry(translateNow('boot.steps.retryingRemoteBackend'))
clearBootRetryTimer()
bootRetryTimer = setTimeout(() => {
@@ -1300,6 +1316,7 @@ export function useGatewayBoot({
return
}
+ bootFailed = true
failDesktopBoot(message)
notifyError(err, translateNow('boot.errors.desktopBootFailed'))
setSessionsLoading(false)