The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): surface an externally-terminated renderer with a recovery page (#116472)
Chukuwebuka-2003338b31226d65
diff --git a/apps/desktop/electron/main.ts b/apps/desktop/electron/main.tsindex 0db0c5e22f1..12f06f30ff4 100644--- a/apps/desktop/electron/main.ts+++ b/apps/desktop/electron/main.ts@@ -14927,6 +14927,28 @@ function createWindow() {repairHint: 'hermes desktop --force-build',reloadUrl: DEV_SERVER || pathToFileURL(resolveRendererIndex()).toString()})+ },+ // #116472: the OS/Chromium can SIGKILL a renderer while the window is live (memory+ // reclaim, an external kill). Hermes never does this itself and never reloads it+ // (a killed-after-close window must not pop back up), so without this the window sat+ // silent with only a desktop.log line. Surface the reason + a recovery button instead.+ onRendererTerminated: details => {+ // An intentional quit/handoff also tears the renderer down; never pop a+ // recovery page for it (its window may still be alive when this fires).+ if (isQuittingForHandoff || backendShutdown.hasStarted() || mainWindow.isDestroyed()) {+ return+ }++ const reason = details?.reason ? String(details.reason) : 'unknown'+ const exit = details?.exitCode === undefined ? '' : `, exit code ${String(details.exitCode)}`+ rememberLog(`[renderer:main] renderer terminated while live (reason=${reason}${exit}); surfacing recovery page`)+ void loadRendererLoadErrorPage(mainWindow, {+ title: 'Hermes desktop UI was terminated',+ errorDescription:+ `The desktop UI process was terminated unexpectedly (reason: ${reason}${exit}). ` ++ 'Your sessions and the background gateway are unaffected — reload to continue.',+ reloadUrl: DEV_SERVER || pathToFileURL(resolveRendererIndex()).toString()+ })}},reloadWindowMs: RENDERER_RELOAD_WINDOW_MS,diff --git a/apps/desktop/electron/renderer-load-error-page.test.ts b/apps/desktop/electron/renderer-load-error-page.test.tsindex 903fb10b55a..93d3f297045 100644--- a/apps/desktop/electron/renderer-load-error-page.test.ts+++ b/apps/desktop/electron/renderer-load-error-page.test.ts@@ -61,6 +61,16 @@ test('reloadUrl cannot break out of the inline script block', () => {assert.match(html, /\\u003cscript\\u003ealert/)})+test('a custom title overrides the default heading', () => {+ const html = buildRendererLoadErrorPage({+ title: 'Hermes desktop UI was terminated',+ errorDescription: 'The UI process was terminated unexpectedly (reason: killed).'+ })++ assert.match(html, /Hermes desktop UI was terminated/)+ assert.doesNotMatch(html, /Hermes couldn.t start the desktop UI/)+})+test('error page renders without any details', () => {const html = buildRendererLoadErrorPage()diff --git a/apps/desktop/electron/renderer-load-error-page.ts b/apps/desktop/electron/renderer-load-error-page.tsindex 772b68d6ac3..d701ab58788 100644--- a/apps/desktop/electron/renderer-load-error-page.ts+++ b/apps/desktop/electron/renderer-load-error-page.ts@@ -27,6 +27,8 @@ export interface RendererLoadErrorDetails {errorCode?: number | string | undefined/** Human description of the failure, e.g. the renderer bundle is torn. */errorDescription?: string+ /** Page heading; defaults to the load-failure title. A terminated-renderer notice supplies its own. */+ title?: string/** The URL that failed to load, when known. */url?: string/** Module files index.html declares but that are missing on disk. */@@ -102,7 +104,7 @@ export function buildRendererLoadErrorPage(details: RendererLoadErrorDetails = {const code =details.errorCode === undefined || details.errorCode === null ? '' : ` (${escapeHtml(details.errorCode)})`- const title = 'Hermes couldn\u2019t start the desktop UI'+ const title = escapeHtml(details.title || 'Hermes couldn\u2019t start the desktop UI')const description = escapeHtml(details.errorDescription || 'The desktop renderer failed to load.')const url = details.url ? `<p><code>${escapeHtml(details.url)}</code></p>` : ''const repair = details.repairHint ? `<p>Repair with: <code>hermes desktop --force-build</code></p>` : ''diff --git a/apps/desktop/electron/window-renderer-lifecycle.test.ts b/apps/desktop/electron/window-renderer-lifecycle.test.tsindex 9203cdb2fa7..468c3d03844 100644--- a/apps/desktop/electron/window-renderer-lifecycle.test.ts+++ b/apps/desktop/electron/window-renderer-lifecycle.test.ts@@ -545,3 +545,51 @@ test('ERR_ABORTED does not consume the load-failure budget', async () => {await flushDeferred()assert.equal(win.reloadCalls.length, 1)})++test('onRendererTerminated surfaces an external kill on a live window, never a reload or teardown', async () => {+ const terminated: any[] = []+ const win = makeFakeWindow()++ const { options } = makeOptions(win, 'main', {+ callbacks: {+ log: () => undefined,+ reload: () => win.webContents.reload(),+ onRendererTerminated: (details: any) => {+ terminated.push(details)+ }+ }+ })++ installWindowRendererLifecycle(win, options)++ // Live window killed externally (OS reclaim / SIGKILL) → surfaced, never reloaded.+ win.webContents.emit('render-process-gone', {}, { reason: 'killed', exitCode: 9 })+ await flushDeferred()+ assert.equal(win.reloadCalls.length, 0)+ assert.deepEqual(terminated, [{ reason: 'killed', exitCode: 9 }])++ // A recoverable crash reloads and must NOT surface the termination page.+ win.webContents.emit('render-process-gone', {}, { reason: 'crashed', exitCode: 3 })+ await flushDeferred()+ assert.equal(win.reloadCalls.length, 1)+ assert.equal(terminated.length, 1)++ // Expected teardown (window destroyed) is neither reloaded nor surfaced.+ const closing = makeFakeWindow({ destroyed: true })++ const closingOptions = makeOptions(closing, 'main', {+ callbacks: {+ log: () => undefined,+ reload: () => closing.webContents.reload(),+ onRendererTerminated: (details: any) => {+ terminated.push(details)+ }+ }+ })++ installWindowRendererLifecycle(closing, closingOptions.options)+ closing.webContents.emit('render-process-gone', {}, { reason: 'killed', exitCode: 9 })+ await flushDeferred()+ assert.equal(closing.reloadCalls.length, 0)+ assert.equal(terminated.length, 1)+})diff --git a/apps/desktop/electron/window-renderer-lifecycle.ts b/apps/desktop/electron/window-renderer-lifecycle.tsindex d536538fcff..50d82371d1b 100644--- a/apps/desktop/electron/window-renderer-lifecycle.ts+++ b/apps/desktop/electron/window-renderer-lifecycle.ts@@ -91,6 +91,12 @@ export interface WindowRendererLifecycleOptions {* (`reloadOnFailedLoad`): the window would otherwise stay blank, so the* caller should load a visible error page in its place. */onFailedLoadBudgetExhausted?: (details?: FailedLoadDetails) => void+ /** Called when a LIVE window's renderer is terminated by something other than a+ * recoverable crash or an expected teardown (e.g. an external SIGKILL / OS+ * reclaim). Deliberately never reloaded — reloading a killed-after-close window+ * would pop it back up — so this is the caller's chance to surface WHY instead+ * of a silent loss (#116472). */+ onRendererTerminated?: (details?: RendererLifecycleDetails) => void}/** Rolling crash-loop window, ms. Defaults to 60_000 (RENDERER_RELOAD_WINDOW_MS). */reloadWindowMs?: number@@ -265,7 +271,7 @@ export function installWindowRendererLifecycle(options: WindowRendererLifecycleOptions): () => void {const kind = options.kind- const { log, reload, onCrashLoopSuppressed } = options.callbacks+ const { log, reload, onCrashLoopSuppressed, onRendererTerminated } = options.callbacksconst reloadWindowMs = options.reloadWindowMs ?? DEFAULT_RELOAD_WINDOW_MSconst reloadMax = options.reloadMax ?? DEFAULT_RELOAD_MAXconst now = options.now@@ -298,6 +304,19 @@ export function installWindowRendererLifecycle(`[renderer:${kind}] suppressing reload: ${budgetRef.current.length} crashes within ${reloadWindowMs}ms (likely a crash loop)`)onCrashLoopSuppressed?.(details)++ return+ }++ // A live window whose renderer was lost to something other than a recoverable+ // crash (e.g. an external SIGKILL / OS reclaim). We deliberately do not reload,+ // but the loss must not be silent — let the caller surface WHY (#116472).+ if (decision.suppressedReason === 'unrecoverable-reason' && !destroyed) {+ log(+ `[renderer:${kind}] renderer terminated while live (reason=${String(details?.reason || 'unknown')}` ++ `${details?.exitCode === undefined ? '' : `, exitCode=${String(details.exitCode)}`}); not reloading`+ )+ onRendererTerminated?.(details)}return