2b7f49673f
A dropped registered remote connection (SSH or HTTP) never recovered on
its own: the next boot attempt failed with a transient transport error
("Could not verify the existing SSH backend", ERR_CONNECTION_RESET,
mint timeout), the failure was correctly NOT latched, but nothing ever
re-attempted the boot — the renderer's reconnect machinery only arms
after a completed boot. The app parked on "Desktop boot failed" until
the user manually deleted and re-entered the same connection details,
which merely forced the fresh bootstrap an automatic retry would have
performed (issue 82679, feature ask 80430).
Root causes and fixes:
- electron/backend-start-failure.ts: new isRetryableRemoteBootFailure()
predicate — a remote, non-reauth boot failure is transient and may be
retried; local failures and confirmed 401/403 rejections are not
(a missing capability differs from a transient failure).
- electron/main.ts: the boot-failure progress broadcast now carries
`retryable` (rides with `error` through updateBootProgress), and a
failed reuse probe against a cached SSH master tears the stale
master/tunnel down so the next attempt bootstraps fresh — exactly
what manual re-entry did.
- use-gateway-boot.ts: bounded self-heal loop for a failed boot whose
progress is marked retryable — up to 5 re-attempts with the same
full-jitter backoff as the socket reconnect loop (2s base, 15s cap).
Exhausted retries end in the real boot-failure recovery overlay,
never an infinite spinner. Reset on success and on soft switch;
timer cleared on unmount.
- store/boot.ts: resumeDesktopBootForRetry() re-arms the overlay with a
retry status while an automatic retry is in flight.
Secondaries already had full-jitter backoff (store/gateway.ts); this
closes the same class for the PRIMARY/registered-connection path.
Tests: predicate matrix (retryable vs reauth-latch mutually exclusive),
plus renderer hook tests proving a transient SSH failure self-heals on
the next attempt, retries are bounded (6 total dials then the recovery
overlay, no further attempts), and non-retryable failures never enter
the loop. Sabotage-verified (disabling either half fails 4 tests).
Fixes #82679
Fixes #80430
117 lines
3.1 KiB
TypeScript
117 lines
3.1 KiB
TypeScript
import { atom } from 'nanostores'
|
|
|
|
import type { DesktopBootProgress } from '@/global'
|
|
import { translateNow } from '@/i18n'
|
|
|
|
export interface DesktopBootState extends DesktopBootProgress {
|
|
visible: boolean
|
|
}
|
|
|
|
const INITIAL_BOOT_STATE: DesktopBootState = {
|
|
error: null,
|
|
fakeMode: false,
|
|
message: translateNow('boot.steps.startingHermesDesktop'),
|
|
phase: 'renderer.init',
|
|
progress: 2,
|
|
running: true,
|
|
timestamp: Date.now(),
|
|
visible: true
|
|
}
|
|
|
|
export const $desktopBoot = atom<DesktopBootState>(INITIAL_BOOT_STATE)
|
|
|
|
function clampProgress(value: number) {
|
|
if (!Number.isFinite(value)) {
|
|
return 0
|
|
}
|
|
|
|
return Math.max(0, Math.min(100, Math.round(value)))
|
|
}
|
|
|
|
export function applyDesktopBootProgress(progress: DesktopBootProgress) {
|
|
const current = $desktopBoot.get()
|
|
const nextProgress = clampProgress(progress.progress)
|
|
const mergedProgress = progress.running ? Math.max(current.progress, nextProgress) : nextProgress
|
|
|
|
// Don't let a late progress event (error: null) clobber a previously-set
|
|
// boot failure — failDesktopBoot is terminal for this boot cycle.
|
|
const error = progress.error ?? (current.running ? null : current.error)
|
|
|
|
$desktopBoot.set({
|
|
...current,
|
|
...progress,
|
|
error,
|
|
progress: mergedProgress,
|
|
visible: progress.running || mergedProgress < 100 || Boolean(error)
|
|
})
|
|
}
|
|
|
|
export function setDesktopBootStep(step: {
|
|
phase: string
|
|
message: string
|
|
progress: number
|
|
running?: boolean
|
|
fakeMode?: boolean
|
|
error?: string | null
|
|
}) {
|
|
const current = $desktopBoot.get()
|
|
applyDesktopBootProgress({
|
|
error: step.error ?? null,
|
|
fakeMode: step.fakeMode ?? current.fakeMode,
|
|
message: step.message,
|
|
phase: step.phase,
|
|
progress: step.progress,
|
|
running: step.running ?? true,
|
|
timestamp: Date.now()
|
|
})
|
|
}
|
|
|
|
/**
|
|
* Re-arm the boot overlay for an automatic bounded retry of a failed REMOTE
|
|
* boot (#82679). Unlike setDesktopBootStep — whose null `error` intentionally
|
|
* cannot clear a latched failure — this explicitly lifts the error so the
|
|
* overlay shows the retry status instead of the terminal failure surface
|
|
* while the retry is in flight. failDesktopBoot() re-latches when the
|
|
* bounded retries are exhausted.
|
|
*/
|
|
export function resumeDesktopBootForRetry(message: string) {
|
|
const current = $desktopBoot.get()
|
|
$desktopBoot.set({
|
|
...current,
|
|
error: null,
|
|
message,
|
|
phase: 'renderer.boot.retry',
|
|
running: true,
|
|
timestamp: Date.now(),
|
|
visible: true
|
|
})
|
|
}
|
|
|
|
export function completeDesktopBoot(message = translateNow('boot.ready')) {
|
|
const current = $desktopBoot.get()
|
|
$desktopBoot.set({
|
|
...current,
|
|
error: null,
|
|
message,
|
|
phase: 'renderer.ready',
|
|
progress: 100,
|
|
running: false,
|
|
timestamp: Date.now(),
|
|
visible: false
|
|
})
|
|
}
|
|
|
|
export function failDesktopBoot(message: string) {
|
|
const current = $desktopBoot.get()
|
|
$desktopBoot.set({
|
|
...current,
|
|
error: message,
|
|
message: translateNow('boot.desktopBootFailedWithMessage', message),
|
|
phase: 'renderer.error',
|
|
progress: clampProgress(current.progress),
|
|
running: false,
|
|
timestamp: Date.now(),
|
|
visible: true
|
|
})
|
|
}
|