The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
refactor(desktop): decide the supervisor-respawn latch inside shouldLatchBackendStartFailure
kshitijk4poor774d851756dd
diff --git a/apps/desktop/electron/backend-start-failure.test.ts b/apps/desktop/electron/backend-start-failure.test.tsindex ef488e79684..b3c12477874 100644--- a/apps/desktop/electron/backend-start-failure.test.ts+++ b/apps/desktop/electron/backend-start-failure.test.ts@@ -23,6 +23,13 @@ test('never latches a REMOTE failure so recovery stays retryable without a restaassert.equal(shouldLatchBackendStartFailure({ attemptedRemote: true }), false)})+test('never latches a supervisor-owned respawn failure (it has its own bounded crash-loop budget)', () => {+ // A pre-ready child exit during a supervisor respawn must be able to spend+ // the remaining crash-loop slots instead of becoming a permanent local latch.+ assert.equal(shouldLatchBackendStartFailure({ attemptedRemote: false, supervisorRecovery: true }), false)+ assert.equal(shouldLatchBackendStartFailure({ attemptedRemote: false, supervisorRecovery: false }), true)+})+test('the two branches are mutually exclusive (a failure either latches or stays retryable)', () => {for (const attemptedRemote of [true, false]) {const latched = shouldLatchBackendStartFailure({ attemptedRemote })diff --git a/apps/desktop/electron/backend-start-failure.ts b/apps/desktop/electron/backend-start-failure.tsindex 66ea47a0a35..5134290d595 100644--- a/apps/desktop/electron/backend-start-failure.ts+++ b/apps/desktop/electron/backend-start-failure.ts@@ -28,6 +28,11 @@ export interface BackendStartFailureContext {* cloud) primary backend rather than spawning a local child.*/attemptedRemote: boolean+ /**+ * True when the boot that just failed was a supervisor-owned respawn after+ * an unexpected primary exit, not an initial or user-driven start.+ */+ supervisorRecovery?: boolean}/**@@ -35,9 +40,14 @@ export interface BackendStartFailureContext {* Latch local failures (prevent install-restart loops); never latch remote* failures (they are transient and must stay retryable so recovery paths work* without an app restart).+ *+ * A supervisor-owned respawn never latches either: it already has its own+ * bounded crash-loop budget, so a pre-ready child exit must not become a+ * permanent local boot latch before that budget can run. Initial and+ * user-driven starts keep the fail-closed latch.*/export function shouldLatchBackendStartFailure(context: BackendStartFailureContext): boolean {- return !context.attemptedRemote+ return !context.attemptedRemote && !context.supervisorRecovery}export interface RemoteReauthFailureContext {diff --git a/apps/desktop/electron/main.ts b/apps/desktop/electron/main.tsindex 6a093ba343b..24de4821590 100644--- a/apps/desktop/electron/main.ts+++ b/apps/desktop/electron/main.ts@@ -13713,11 +13713,8 @@ async function runHermesStart({ supervisorRecovery = false }: { supervisorRecove// child 'exit' handler to clear the cache — latching it would wedge the app// on "session expired" until a full restart, defeating reconnect, the// "Sign out & sign in" reload, and the wake-recovery revalidate path.- // A supervisor-owned respawn already has its own bounded crash-loop- // budget. Do not turn a pre-ready child exit into a permanent local boot- // latch before that budget can run; initial/user-driven starts keep the- // existing fail-closed latch.- if (!supervisorRecovery && shouldLatchBackendStartFailure({ attemptedRemote })) {+ // A supervisor-owned respawn never latches (see the predicate).+ if (shouldLatchBackendStartFailure({ attemptedRemote, supervisorRecovery })) {backendStartFailure = error instanceof Error ? error : new Error(message)}