hermes-agent/apps/desktop/electron/guest-onboarding.ts
xiaodu 91617521c6 fix(gateway): stay alive on all-adapters-down when no service manager supervises
A gateway whose last messaging adapter hits a retryable fatal error exits
with the failure verdict (EX_TEMPFAIL) so a supervising service manager
restarts it. The desktop app launches `hermes serve` directly with no
supervisor: the exit only severs the UI's websocket connections and drops
in-flight assistant messages, which then 'disappear' from chat (#118080 —
334 fatal events over 6 days on one profile, mostly email IMAP fetch
failures marked retryable).

Add gateway.on_all_adapters_down: exit | stay_alive (default exit — zero
behavior change for service-managed deployments). At both stranded-exit
sites in gateway/run_adapters.py, the stay_alive policy keeps the process
running (reconnect watcher owns recovery) instead of setting
_exit_with_failure; non-retryable adapter loss still exits. The desktop
launcher stamps GATEWAY_ON_ALL_ADAPTERS_DOWN=stay_alive last into the
child env (same rule as HERMES_GUEST_ONBOARDING); older runtimes ignore
the unknown variable and keep the historical behavior.

Fixes #118080
2026-09-29 19:33:09 -05:00

23 lines
1.1 KiB
TypeScript

export const GUEST_ONBOARDING_ENV = 'HERMES_GUEST_ONBOARDING'
export const GUEST_ONBOARDING_FLAG = '--guest-onboarding'
export function guestOnboardingEnabled(
argv: readonly string[] = process.argv,
env: NodeJS.ProcessEnv = process.env
): boolean {
return env[GUEST_ONBOARDING_ENV] === '1' || argv.includes(GUEST_ONBOARDING_FLAG)
}
export function desktopBackendSpawnEnv(base: NodeJS.ProcessEnv, guestOnboarding: boolean): NodeJS.ProcessEnv {
return {
...base,
[GUEST_ONBOARDING_ENV]: guestOnboarding ? '1' : '0',
// The desktop spawns `hermes serve` directly — no systemd/launchd supervisor will
// revive a failure exit, so EX_TEMPFAIL only severs the UI's websockets and drops
// in-flight assistant messages (#118080). Tell the gateway to stay alive on
// all-adapters-down and let the reconnect watcher recover instead. Written LAST
// (same rule as GUEST_ONBOARDING_ENV) so no earlier spread can override it. Older
// runtimes ignore the unknown variable and keep the historical exit behavior.
GATEWAY_ON_ALL_ADAPTERS_DOWN: 'stay_alive'
}
}