From 4ff7e6a6ba22bbcdcae1252a11a8a30def3b95b1 Mon Sep 17 00:00:00 2001 From: m4air Date: Sat, 31 Oct 2026 17:27:50 -0700 Subject: [PATCH 1/2] fix(window): ride out Windows renderer launch refusals instead of prompting after 1s Windows renderer launch-failed exit 18 is Chromium SBOX_ERROR_CREATE_PROCESS: CreateProcessAsUser for the sandboxed renderer was refused. Field reports show the refusal clears within seconds to minutes and the same webContents reloads fine afterwards, but Windows was kept on the 750ms crash breaker, so three reloads burned in ~1s and a blank window waited on a Try Again prompt. Use the same ~2 minute launch-failure backoff on Windows as on POSIX. --- ...MainWindow-renderer-launch-failure.test.ts | 30 ++++++++++++------- .../window/main-window-focus-lifecycle.ts | 7 ++--- .../window/renderer-launch-failure-backoff.ts | 2 +- 3 files changed, 24 insertions(+), 15 deletions(-) diff --git a/src/main/window/createMainWindow-renderer-launch-failure.test.ts b/src/main/window/createMainWindow-renderer-launch-failure.test.ts index dec6a66def9e..15a5d703264d 100644 --- a/src/main/window/createMainWindow-renderer-launch-failure.test.ts +++ b/src/main/window/createMainWindow-renderer-launch-failure.test.ts @@ -35,7 +35,10 @@ const LAUNCH_FAILED: Electron.RenderProcessGoneDetails = { reason: 'launch-faile const CRASHED: Electron.RenderProcessGoneDetails = { reason: 'crashed', exitCode: 5 } /** Reproduce spawn refusal: launch-failed then ERR_FAILED before a document; the same WebContents loads once process headroom returns. */ -function createSpawnRefusingWindow(platform: NodeJS.Platform = 'darwin') { +function createSpawnRefusingWindow( + platform: NodeJS.Platform = 'darwin', + failure: Electron.RenderProcessGoneDetails = LAUNCH_FAILED +) { const handlers: Record void> = {} const spawn = { refused: true } const webContents = { @@ -58,7 +61,7 @@ function createSpawnRefusingWindow(platform: NodeJS.Platform = 'darwin') { return Promise.resolve() } queueMicrotask(() => - withPlatform(platform, () => handlers['render-process-gone']?.({}, LAUNCH_FAILED)) + withPlatform(platform, () => handlers['render-process-gone']?.({}, failure)) ) return Promise.reject( new Error("ERR_FAILED (-2) loading 'file:///opt/orca/renderer/index.html'") @@ -186,15 +189,22 @@ describe('renderer launch-failed recovery', () => { expect(onRendererRecoveryExhausted).not.toHaveBeenCalled() }) - it('keeps Windows launch failures on the short recovery schedule', async () => { - const { load } = createSpawnRefusingWindow('win32') - const { onRendererRecoveryExhausted } = open() - await vi.advanceTimersByTimeAsync(1_000) - expect(load).toHaveBeenCalledTimes(4) - expect(onRendererRecoveryExhausted).toHaveBeenCalledOnce() - expect(onRendererRecoveryExhausted).toHaveBeenCalledWith( - expect.objectContaining({ cause: 'launch-failed', recentRecoveryCount: 3 }) + it('rides out a Windows sandbox CreateProcess refusal in place instead of prompting', async () => { + // Windows SBOX_ERROR_CREATE_PROCESS; awin repro (job capped at 1 process for 5s) prompted after ~1s on the 750ms breaker. + const { spawn } = createSpawnRefusingWindow('win32', { + reason: 'launch-failed', + exitCode: 18 + }) + const { onRendererRecoveryExhausted, onRecoveryReloadOutcome } = open() + await vi.advanceTimersByTimeAsync(5_000) + expect(onRendererRecoveryExhausted).not.toHaveBeenCalled() + spawn.refused = false + + await vi.advanceTimersByTimeAsync(4_000) + expect(onRecoveryReloadOutcome).toHaveBeenLastCalledWith( + expect.objectContaining({ status: 'loaded' }) ) + expect(onRendererRecoveryExhausted).not.toHaveBeenCalled() }) it('keeps the crash-loop breaker for renderers that actually crash', async () => { diff --git a/src/main/window/main-window-focus-lifecycle.ts b/src/main/window/main-window-focus-lifecycle.ts index 819b7f4fa39f..544dca29c17c 100644 --- a/src/main/window/main-window-focus-lifecycle.ts +++ b/src/main/window/main-window-focus-lifecycle.ts @@ -208,8 +208,7 @@ export function installMainWindowFocusLifecycle(args: { return } const launchFailed = details.reason === 'launch-failed' - const useLaunchBackoff = launchFailed && process.platform !== 'win32' - const launchRetryDelayMs = useLaunchBackoff ? launchFailureBackoff.nextDelayMs() : null + const launchRetryDelayMs = launchFailed ? launchFailureBackoff.nextDelayMs() : null const goneAt = Date.now() // Read commit at death; the next sampler tick would see memory the dead renderer released. const lowCommit = lowCommitOomGate.assess(details, goneAt) @@ -237,7 +236,7 @@ export function installMainWindowFocusLifecycle(args: { return } // Spawn refusal needs its own bounded backoff, independent of crash-loop accounting. - if (useLaunchBackoff) { + if (launchFailed) { const subject = { details, recentRecoveryCount: launchFailureBackoff.attempts() } if (launchRetryDelayMs === null) { recoveryReloadWatchdog.escalate(subject, 'launch-failed') @@ -251,7 +250,7 @@ export function installMainWindowFocusLifecycle(args: { // Stop repeated crashes through the one-prompt watchdog; it also watches manual retry so another stall cannot strand a blank window. recoveryReloadWatchdog.escalate( { details, recentRecoveryCount: recovery.recentRecoveryCount }, - launchFailed ? 'launch-failed' : 'crash-loop' + 'crash-loop' ) return } diff --git a/src/main/window/renderer-launch-failure-backoff.ts b/src/main/window/renderer-launch-failure-backoff.ts index 4dc33b2741d5..19d7485e157c 100644 --- a/src/main/window/renderer-launch-failure-backoff.ts +++ b/src/main/window/renderer-launch-failure-backoff.ts @@ -1,4 +1,4 @@ -// Refused spawns can last minutes (macOS 1003/process limit); spread retries over ~2min instead of the crash breaker's 750ms. +// Refused spawns last seconds to minutes (macOS 1003 process limit, Windows sandbox CreateProcess 18); spread retries over ~2min, not the crash breaker's 750ms. export const RENDERER_LAUNCH_FAILURE_RETRY_DELAYS_MS: readonly number[] = [ 250, 1_000, 2_000, 4_000, 8_000, 15_000, 30_000, 60_000 ] From 9c1e975d02005b13a869b0256cc5c0d2c0da7160 Mon Sep 17 00:00:00 2001 From: Neil Date: Mon, 2 Nov 2026 21:14:34 -0800 Subject: [PATCH 2/2] test(window): pin bounded prompt for persistent Windows exit-18 refusal --- ...MainWindow-renderer-launch-failure.test.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/main/window/createMainWindow-renderer-launch-failure.test.ts b/src/main/window/createMainWindow-renderer-launch-failure.test.ts index 15a5d703264d..9f0b1c83ca89 100644 --- a/src/main/window/createMainWindow-renderer-launch-failure.test.ts +++ b/src/main/window/createMainWindow-renderer-launch-failure.test.ts @@ -207,6 +207,25 @@ describe('renderer launch-failed recovery', () => { expect(onRendererRecoveryExhausted).not.toHaveBeenCalled() }) + it('still prompts on Windows once a persistent CreateProcess refusal spends the schedule', async () => { + const SANDBOX_REFUSED = { reason: 'launch-failed', exitCode: 18 } as const + const { load } = createSpawnRefusingWindow('win32', SANDBOX_REFUSED) + const { onRendererRecoveryExhausted } = open() + await vi.advanceTimersByTimeAsync(BACKOFF_TOTAL_MS - 1) + expect(onRendererRecoveryExhausted).not.toHaveBeenCalled() + + await vi.advanceTimersByTimeAsync(251) + expect(load).toHaveBeenCalledTimes(1 + RENDERER_LAUNCH_FAILURE_RETRY_DELAYS_MS.length) + expect(onRendererRecoveryExhausted).toHaveBeenCalledOnce() + expect(onRendererRecoveryExhausted).toHaveBeenCalledWith( + expect.objectContaining({ + details: SANDBOX_REFUSED, + cause: 'launch-failed', + recentRecoveryCount: RENDERER_LAUNCH_FAILURE_RETRY_DELAYS_MS.length + }) + ) + }) + it('keeps the crash-loop breaker for renderers that actually crash', async () => { const { handlers, load, spawn } = createSpawnRefusingWindow() spawn.refused = false