Skip to content

The agent that grows with you

fix(desktop): recover Windows 0xC0000409 renderer crash loops by disabling GPU

KoNit-K2e36513ef9b2
diff --git a/apps/desktop/electron/main.ts b/apps/desktop/electron/main.ts
index 32975bae9bd..43505177841 100644
--- a/apps/desktop/electron/main.ts
+++ b/apps/desktop/electron/main.ts
@@ -575,6 +575,16 @@ import {
shouldRelaunchForRendererSandboxCrashLoop,
writeSandboxMarker
} from './windows-sandbox-fallback'
+import {
+ decideWindowsGpuStackCookieLaunch,
+ gpuStackCookieFallbackMarker,
+ isHermesDesktopGpuOverrideOff,
+ markerAfterSuccessfulGpuStackCookieBoot,
+ readGpuStackCookieMarker,
+ shouldRelaunchForRendererStackCookieCrashLoop,
+ shouldSurfaceErrorForRendererStackCookieCrashLoop,
+ writeGpuStackCookieMarker
+} from './windows-stack-cookie-fallback'
import { installWindowsSystemCaTrust } from './windows-system-ca'
import { readWindowsUserEnvVar } from './windows-user-env'
import { isPackagedInstallPath as isPackagedInstallPathUnderRoots } from './workspace-cwd'
@@ -637,6 +647,39 @@ if (REMOTE_DISPLAY_REASON) {
)
}
+// #108047: a local Windows renderer crash loop with STATUS_STACK_BUFFER_OVERRUN
+// (0xC0000409) is recovered by disabling GPU — NOT by dropping the sandbox
+// (that path stays owned by STATUS_BREAKPOINT / #38216). Must run before app
+// `ready`. Skip applying switches when the remote-display block above already
+// did; still honor a sticky per-version marker so Start Menu launches recover.
+let windowsGpuStackCookieFallbackActive = false
+let windowsGpuStackCookieRelaunchAttempted = false
+
+if (IS_WINDOWS) {
+ const windowsGpuUserData = app.getPath('userData')
+ const gpuStackCookieDecision = decideWindowsGpuStackCookieLaunch({
+ marker: readGpuStackCookieMarker(windowsGpuUserData),
+ env: process.env,
+ appVersion: app.getVersion()
+ })
+
+ windowsGpuStackCookieFallbackActive = gpuStackCookieDecision.enable
+
+ try {
+ writeGpuStackCookieMarker(windowsGpuUserData, gpuStackCookieDecision.nextMarker)
+ } catch {
+ void 0
+ }
+
+ if (gpuStackCookieDecision.enable && !REMOTE_DISPLAY_REASON) {
+ app.disableHardwareAcceleration()
+ app.commandLine.appendSwitch('disable-gpu-compositing')
+ console.log(
+ `[hermes] Windows GPU stack-cookie fallback enabled (${gpuStackCookieDecision.reason}); disabling GPU hardware acceleration (0xC0000409 / #108047)`
+ )
+ }
+}
+
// Renderer debugging port. On for dev-server runs (`hgui` / `npm run dev`) so
// the CDP tooling in scripts/ can attach; never for a packaged build — see
// electron/dev-cdp.ts. Must run before app `ready` like the switches above;
@@ -14588,6 +14631,18 @@ function createWindow() {
} catch (error) {
rememberLog(`[sandbox] marker update after main-window reveal failed: ${error?.message || error}`)
}
+
+ try {
+ writeGpuStackCookieMarker(
+ app.getPath('userData'),
+ markerAfterSuccessfulGpuStackCookieBoot({
+ fallbackActive: windowsGpuStackCookieFallbackActive,
+ appVersion: app.getVersion()
+ })
+ )
+ } catch (error) {
+ rememberLog(`[gpu] stack-cookie marker update after main-window reveal failed: ${error?.message || error}`)
+ }
}
}
})
@@ -14637,6 +14692,60 @@ function createWindow() {
mainWindow.webContents.reload()
},
onCrashLoopSuppressed: details => {
+ // #108047: STATUS_STACK_BUFFER_OVERRUN crash loops get a one-shot GPU
+ // disable relaunch. Checked BEFORE the sandbox path so 0xC0000409 never
+ // piggybacks --no-sandbox. If GPU fallback cannot run, surface the
+ // visible error page instead of leaving a blank window.
+ const stackCookieCrashLoop = {
+ reason: details?.reason,
+ exitCode: details?.exitCode,
+ alreadyGpuDisabled: Boolean(REMOTE_DISPLAY_REASON) || windowsGpuStackCookieFallbackActive,
+ relaunchAttempted: windowsGpuStackCookieRelaunchAttempted,
+ gpuOverrideOff: isHermesDesktopGpuOverrideOff(process.env)
+ }
+
+ if (shouldRelaunchForRendererStackCookieCrashLoop(stackCookieCrashLoop)) {
+ windowsGpuStackCookieRelaunchAttempted = true
+ windowsGpuStackCookieFallbackActive = true
+
+ try {
+ writeGpuStackCookieMarker(
+ app.getPath('userData'),
+ gpuStackCookieFallbackMarker('renderer-crash-loop', app.getVersion())
+ )
+ } catch {
+ void 0
+ }
+
+ rememberLog(
+ '[renderer] Windows stack-cookie crash loop (0xC0000409); relaunching once with GPU disabled (#108047)'
+ )
+
+ try {
+ app.relaunch({ args: process.argv.slice(1) })
+ void exitAfterBackendShutdown(0)
+ } catch (err) {
+ rememberLog(`[renderer] GPU-disable relaunch failed: ${err?.message || err}`)
+ }
+
+ return
+ }
+
+ if (shouldSurfaceErrorForRendererStackCookieCrashLoop(stackCookieCrashLoop)) {
+ rememberLog(
+ '[renderer] Windows stack-cookie crash loop (0xC0000409) with GPU fallback unavailable; surfacing error page (#108047)'
+ )
+ void loadRendererLoadErrorPage(mainWindow, {
+ errorCode: details?.exitCode,
+ errorDescription:
+ 'The desktop renderer crashed repeatedly (Windows STATUS_STACK_BUFFER_OVERRUN / 0xC0000409). GPU fallback could not recover the window.',
+ repairHint: 'hermes desktop --force-build',
+ reloadUrl: DEV_SERVER || pathToFileURL(resolveRendererIndex()).toString()
+ })
+
+ return
+ }
+
// #38216 renderer flavor (same recovery as #56726, credit @Sahil-SS9):
// a deterministic Windows renderer crash loop with the sandbox
// breakpoint signature gets one --no-sandbox relaunch instead of a
diff --git a/apps/desktop/electron/windows-stack-cookie-fallback.test.ts b/apps/desktop/electron/windows-stack-cookie-fallback.test.ts
new file mode 100644
index 00000000000..9adddf777fc
--- /dev/null
+++ b/apps/desktop/electron/windows-stack-cookie-fallback.test.ts
@@ -0,0 +1,272 @@
+import assert from 'node:assert/strict'
+import fs from 'node:fs'
+import os from 'node:os'
+import path from 'node:path'
+
+import { test } from 'vitest'
+
+import { shouldRelaunchForRendererSandboxCrashLoop } from './windows-sandbox-fallback'
+import {
+ decideWindowsGpuStackCookieLaunch,
+ gpuStackCookieFallbackMarker,
+ gpuStackCookieMarkerPath,
+ isWindowsStackCookieExit,
+ readGpuStackCookieMarker,
+ shouldRelaunchForRendererStackCookieCrashLoop,
+ shouldSurfaceErrorForRendererStackCookieCrashLoop,
+ WINDOWS_GPU_STACK_COOKIE_MARKER_FILENAME,
+ WINDOWS_STACK_COOKIE_EXIT,
+ writeGpuStackCookieMarker
+} from './windows-stack-cookie-fallback'
+
+test('isWindowsStackCookieExit recognizes the issue signed exitCode', () => {
+ assert.equal(isWindowsStackCookieExit(-1073740791), true)
+ assert.equal(isWindowsStackCookieExit(WINDOWS_STACK_COOKIE_EXIT), true)
+})
+
+test('isWindowsStackCookieExit recognizes unsigned STATUS_STACK_BUFFER_OVERRUN', () => {
+ assert.equal(isWindowsStackCookieExit(0xc0000409), true)
+})
+
+test('isWindowsStackCookieExit rejects STATUS_BREAKPOINT (sandbox owns that code)', () => {
+ assert.equal(isWindowsStackCookieExit(-2147483645), false)
+})
+
+test('isWindowsStackCookieExit rejects unrelated and non-finite values', () => {
+ assert.equal(isWindowsStackCookieExit(1), false)
+ assert.equal(isWindowsStackCookieExit(Number.NaN), false)
+ assert.equal(isWindowsStackCookieExit(Number.POSITIVE_INFINITY), false)
+ assert.equal(isWindowsStackCookieExit('nope'), false)
+ assert.equal(isWindowsStackCookieExit(undefined), false)
+})
+
+test('shouldRelaunchForRendererStackCookieCrashLoop fires for the issue signature', () => {
+ assert.equal(
+ shouldRelaunchForRendererStackCookieCrashLoop({
+ platform: 'win32',
+ reason: 'crashed',
+ exitCode: -1073740791,
+ alreadyGpuDisabled: false,
+ relaunchAttempted: false,
+ gpuOverrideOff: false
+ }),
+ true
+ )
+})
+
+test('shouldRelaunchForRendererStackCookieCrashLoop stays off outside Windows', () => {
+ const base = {
+ reason: 'crashed' as const,
+ exitCode: -1073740791,
+ alreadyGpuDisabled: false,
+ relaunchAttempted: false,
+ gpuOverrideOff: false
+ }
+
+ assert.equal(shouldRelaunchForRendererStackCookieCrashLoop({ ...base, platform: 'linux' }), false)
+ assert.equal(shouldRelaunchForRendererStackCookieCrashLoop({ ...base, platform: 'darwin' }), false)
+})
+
+test('shouldRelaunchForRendererStackCookieCrashLoop stays off for oom or killed', () => {
+ const base = {
+ platform: 'win32' as const,
+ exitCode: -1073740791,
+ alreadyGpuDisabled: false,
+ relaunchAttempted: false,
+ gpuOverrideOff: false
+ }
+
+ assert.equal(shouldRelaunchForRendererStackCookieCrashLoop({ ...base, reason: 'oom' }), false)
+ assert.equal(shouldRelaunchForRendererStackCookieCrashLoop({ ...base, reason: 'killed' }), false)
+})
+
+test('shouldRelaunchForRendererStackCookieCrashLoop stays off when GPU is already disabled', () => {
+ assert.equal(
+ shouldRelaunchForRendererStackCookieCrashLoop({
+ platform: 'win32',
+ reason: 'crashed',
+ exitCode: -1073740791,
+ alreadyGpuDisabled: true,
+ relaunchAttempted: false,
+ gpuOverrideOff: false
+ }),
+ false
+ )
+})
+
+test('shouldRelaunchForRendererStackCookieCrashLoop stays off after a relaunch attempt', () => {
+ assert.equal(
+ shouldRelaunchForRendererStackCookieCrashLoop({
+ platform: 'win32',
+ reason: 'crashed',
+ exitCode: -1073740791,
+ alreadyGpuDisabled: false,
+ relaunchAttempted: true,
+ gpuOverrideOff: false
+ }),
+ false
+ )
+})
+
+test('shouldRelaunchForRendererStackCookieCrashLoop stays off when GPU override is explicitly off', () => {
+ assert.equal(
+ shouldRelaunchForRendererStackCookieCrashLoop({
+ platform: 'win32',
+ reason: 'crashed',
+ exitCode: -1073740791,
+ alreadyGpuDisabled: false,
+ relaunchAttempted: false,
+ gpuOverrideOff: true
+ }),
+ false
+ )
+})
+
+test('decideWindowsGpuStackCookieLaunch enables sticky fallback, re-probes on version change, and fail-opens', () => {
+ const sticky = decideWindowsGpuStackCookieLaunch({
+ platform: 'win32',
+ marker: { state: 'fallback', reason: 'renderer-crash-loop', version: '1.2.3' },
+ env: {},
+ appVersion: '1.2.3'
+ })
+
+ assert.equal(sticky.enable, true)
+ assert.equal(sticky.nextMarker.state, 'fallback')
+
+ const linux = decideWindowsGpuStackCookieLaunch({
+ platform: 'linux',
+ marker: { state: 'fallback', reason: 'renderer-crash-loop', version: '1.2.3' },
+ env: {},
+ appVersion: '1.2.3'
+ })
+
+ assert.equal(linux.enable, false)
+
+ const overrideOff = decideWindowsGpuStackCookieLaunch({
+ platform: 'win32',
+ marker: { state: 'fallback', reason: 'renderer-crash-loop', version: '1.2.3' },
+ env: { HERMES_DESKTOP_DISABLE_GPU: '0' },
+ appVersion: '1.2.3'
+ })
+
+ assert.equal(overrideOff.enable, false)
+
+ const reprobe = decideWindowsGpuStackCookieLaunch({
+ platform: 'win32',
+ marker: { state: 'fallback', reason: 'renderer-crash-loop', version: '1.2.3' },
+ env: {},
+ appVersion: '1.3.0'
+ })
+
+ assert.equal(reprobe.enable, false)
+ assert.equal(reprobe.nextMarker.state, 'booting')
+ assert.equal(reprobe.nextMarker.reprobe, true)
+
+ const legacy = decideWindowsGpuStackCookieLaunch({
+ platform: 'win32',
+ marker: { state: 'fallback' },
+ env: {},
+ appVersion: '1.3.0'
+ })
+
+ assert.equal(legacy.enable, true)
+})
+
+test('CONTROL: sandbox relaunch stays false for 0xC0000409 (do not piggyback --no-sandbox)', () => {
+ assert.equal(
+ shouldRelaunchForRendererSandboxCrashLoop({
+ platform: 'win32',
+ reason: 'crashed',
+ exitCode: -1073740791,
+ alreadyNoSandbox: false,
+ relaunchAttempted: false
+ }),
+ false
+ )
+ assert.notEqual(WINDOWS_GPU_STACK_COOKIE_MARKER_FILENAME, 'windows-sandbox-fallback.json')
+})
+
+test('shouldSurfaceErrorForRendererStackCookieCrashLoop when GPU fallback cannot run', () => {
+ const signature = {
+ platform: 'win32' as const,
+ reason: 'crashed' as const,
+ exitCode: -1073740791
+ }
+
+ assert.equal(
+ shouldSurfaceErrorForRendererStackCookieCrashLoop({
+ ...signature,
+ alreadyGpuDisabled: true,
+ relaunchAttempted: false,
+ gpuOverrideOff: false
+ }),
+ true
+ )
+ assert.equal(
+ shouldSurfaceErrorForRendererStackCookieCrashLoop({
+ ...signature,
+ alreadyGpuDisabled: false,
+ relaunchAttempted: true,
+ gpuOverrideOff: false
+ }),
+ true
+ )
+ assert.equal(
+ shouldSurfaceErrorForRendererStackCookieCrashLoop({
+ ...signature,
+ alreadyGpuDisabled: false,
+ relaunchAttempted: false,
+ gpuOverrideOff: true
+ }),
+ true
+ )
+ assert.equal(
+ shouldSurfaceErrorForRendererStackCookieCrashLoop({
+ ...signature,
+ alreadyGpuDisabled: false,
+ relaunchAttempted: false,
+ gpuOverrideOff: false
+ }),
+ false
+ )
+ assert.equal(
+ shouldSurfaceErrorForRendererStackCookieCrashLoop({
+ ...signature,
+ platform: 'linux',
+ alreadyGpuDisabled: true,
+ relaunchAttempted: false,
+ gpuOverrideOff: false
+ }),
+ false
+ )
+ assert.equal(
+ shouldSurfaceErrorForRendererStackCookieCrashLoop({
+ platform: 'win32',
+ reason: 'crashed',
+ exitCode: -2147483645,
+ alreadyGpuDisabled: true,
+ relaunchAttempted: false,
+ gpuOverrideOff: false
+ }),
+ false
+ )
+})
+
+test('GPU stack-cookie marker lives in its own file and round-trips', () => {
+ const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'hermes-stack-cookie-marker-'))
+
+ try {
+ assert.equal(gpuStackCookieMarkerPath(dir), path.join(dir, WINDOWS_GPU_STACK_COOKIE_MARKER_FILENAME))
+ assert.equal(WINDOWS_GPU_STACK_COOKIE_MARKER_FILENAME, 'windows-gpu-stack-cookie-fallback.json')
+ assert.equal(readGpuStackCookieMarker(dir), null)
+
+ writeGpuStackCookieMarker(dir, gpuStackCookieFallbackMarker('renderer-crash-loop', '1.2.3'))
+ assert.deepEqual(readGpuStackCookieMarker(dir), {
+ state: 'fallback',
+ reason: 'renderer-crash-loop',
+ version: '1.2.3'
+ })
+ } finally {
+ fs.rmSync(dir, { recursive: true, force: true })
+ }
+})
diff --git a/apps/desktop/electron/windows-stack-cookie-fallback.ts b/apps/desktop/electron/windows-stack-cookie-fallback.ts
new file mode 100644
index 00000000000..14cd662fc42
--- /dev/null
+++ b/apps/desktop/electron/windows-stack-cookie-fallback.ts
@@ -0,0 +1,276 @@
+/**
+ * Windows Chromium renderer recovery for #108047.
+ *
+ * On some local Windows hosts the renderer dies with
+ * STATUS_STACK_BUFFER_OVERRUN (`0xC0000409` / signed exit `-1073740791`,
+ * FAST_FAIL_STACK_COOKIE_CHECK_FAILURE). After the shared crash-loop budget
+ * (3 / 60s) is exhausted, the window would otherwise stay blank: the
+ * existing #38216 sandbox fallback only matches STATUS_BREAKPOINT
+ * (`0x80000003`) and must not drop the sandbox for this signature.
+ *
+ * Recovery, all scoped to win32 renderer `crashed` + this exit code:
+ *
+ * 1. One-shot relaunch with GPU disabled (sticky per app version). Next
+ * launch, before app `ready`, reads the marker and applies the same
+ * switches as the remote-display path (`disableHardwareAcceleration` +
+ * `disable-gpu-compositing`).
+ * 2. If GPU is already off, the override forbids disabling GPU, or this
+ * process already attempted the relaunch — do not loop; the caller
+ * surfaces the visible renderer error page instead of a blank window.
+ *
+ * An app update re-probes GPU once (a new Electron may have fixed the host).
+ * Successful boot keeps the sticky fallback within the same version.
+ *
+ * Pure helpers stay injectable so tests never boot Electron.
+ */
+
+import fs from 'node:fs'
+import path from 'node:path'
+
+export const WINDOWS_GPU_STACK_COOKIE_MARKER_FILENAME = 'windows-gpu-stack-cookie-fallback.json'
+
+/** STATUS_STACK_BUFFER_OVERRUN as a signed Win32 exit code (WER / Chromium). */
+export const WINDOWS_STACK_COOKIE_EXIT = -1073740791
+
+const GPU_OVERRIDE_OFF = new Set(['0', 'false', 'no', 'off'])
+
+export type GpuStackCookieMarkerState = 'booting' | 'fallback' | 'ok'
+
+export type GpuStackCookieFallbackReason = 'renderer-crash-loop'
+
+export interface GpuStackCookieMarker {
+ state: GpuStackCookieMarkerState
+ /** Why the fallback engaged (state === 'fallback'). */
+ reason?: GpuStackCookieFallbackReason
+ /** App version that entered fallback — a version change triggers a re-probe. */
+ version?: string
+ /** This boot is a GPU re-probe after an app update. */
+ reprobe?: boolean
+}
+
+export interface GpuStackCookieLaunchDecision {
+ enable: boolean
+ reason: string | null
+ nextMarker: GpuStackCookieMarker
+}
+
+export interface RendererStackCookieCrashLoopOptions {
+ platform?: NodeJS.Platform | string
+ reason?: string
+ exitCode?: number | string
+ alreadyGpuDisabled?: boolean
+ relaunchAttempted?: boolean
+ gpuOverrideOff?: boolean
+}
+
+export function gpuStackCookieMarkerPath(userDataDir: string): string {
+ return path.join(String(userDataDir || ''), WINDOWS_GPU_STACK_COOKIE_MARKER_FILENAME)
+}
+
+export function isWindowsStackCookieExit(exitCode: unknown): boolean {
+ const n = Number(exitCode)
+
+ if (!Number.isFinite(n)) {
+ return false
+ }
+
+ // Signed STATUS_STACK_BUFFER_OVERRUN, or the same 32-bit pattern as unsigned.
+ return n === WINDOWS_STACK_COOKIE_EXIT || n >>> 0 === 0xc0000409
+}
+
+export function isHermesDesktopGpuOverrideOff(env: NodeJS.ProcessEnv = process.env): boolean {
+ const override = String(env.HERMES_DESKTOP_DISABLE_GPU || '')
+ .trim()
+ .toLowerCase()
+
+ return GPU_OVERRIDE_OFF.has(override)
+}
+
+export function parseGpuStackCookieMarker(raw: unknown): GpuStackCookieMarker | null {
+ if (!raw || typeof raw !== 'object') {
+ return null
+ }
+
+ const record = raw as Record<string, unknown>
+ const state = record.state
+
+ if (state !== 'booting' && state !== 'fallback' && state !== 'ok') {
+ return null
+ }
+
+ const marker: GpuStackCookieMarker = { state }
+
+ if (record.reason === 'renderer-crash-loop') {
+ marker.reason = 'renderer-crash-loop'
+ }
+
+ if (typeof record.version === 'string' && record.version) {
+ marker.version = record.version
+ }
+
+ if (record.reprobe === true) {
+ marker.reprobe = true
+ }
+
+ return marker
+}
+
+export function readGpuStackCookieMarker(
+ userDataDir: string,
+ { readFileSync = fs.readFileSync } = {}
+): GpuStackCookieMarker | null {
+ try {
+ const raw = JSON.parse(readFileSync(gpuStackCookieMarkerPath(userDataDir), 'utf8'))
+
+ return parseGpuStackCookieMarker(raw)
+ } catch {
+ return null
+ }
+}
+
+export function writeGpuStackCookieMarker(
+ userDataDir: string,
+ marker: GpuStackCookieMarker,
+ {
+ mkdirSync = fs.mkdirSync,
+ writeFileSync = fs.writeFileSync
+ }: {
+ mkdirSync?: typeof fs.mkdirSync
+ writeFileSync?: typeof fs.writeFileSync
+ } = {}
+): void {
+ const dir = String(userDataDir || '')
+
+ if (!dir) {
+ return
+ }
+
+ mkdirSync(dir, { recursive: true })
+ writeFileSync(gpuStackCookieMarkerPath(dir), `${JSON.stringify(marker)}\n`, 'utf8')
+}
+
+export function gpuStackCookieFallbackMarker(
+ reason: GpuStackCookieFallbackReason,
+ appVersion?: string
+): GpuStackCookieMarker {
+ const marker: GpuStackCookieMarker = { state: 'fallback', reason }
+
+ if (appVersion) {
+ marker.version = appVersion
+ }
+
+ return marker
+}
+
+/**
+ * After the main window reaches ready-to-show: keep the sticky GPU fallback
+ * when this launch disabled GPU for #108047, otherwise mark a clean boot so
+ * a later app update can re-probe hardware acceleration.
+ */
+export function markerAfterSuccessfulGpuStackCookieBoot(options: {
+ fallbackActive: boolean
+ appVersion?: string
+}): GpuStackCookieMarker {
+ if (!options.fallbackActive) {
+ return { state: 'ok' }
+ }
+
+ return gpuStackCookieFallbackMarker('renderer-crash-loop', options.appVersion)
+}
+
+/**
+ * True when a renderer crash loop carries the #108047 stack-cookie signature
+ * and a one-shot GPU-disable relaunch should replace the dead window.
+ * Gated on the exit code so unrelated crash loops (sandbox breakpoint, OOM)
+ * don't silently disable GPU, and so an explicit GPU-off override is honored.
+ */
+export function shouldRelaunchForRendererStackCookieCrashLoop(options: RendererStackCookieCrashLoopOptions): boolean {
+ if ((options.platform ?? process.platform) !== 'win32') {
+ return false
+ }
+
+ if (options.alreadyGpuDisabled || options.relaunchAttempted || options.gpuOverrideOff) {
+ return false
+ }
+
+ if (String(options.reason || '') !== 'crashed') {
+ return false
+ }
+
+ return isWindowsStackCookieExit(options.exitCode)
+}
+
+/**
+ * True when the #108047 signature matched but GPU fallback cannot run
+ * (already disabled, override off, or this process already relaunched).
+ * The caller should load the visible renderer error page instead of a blank
+ * window. Does not drop the Chromium sandbox.
+ */
+export function shouldSurfaceErrorForRendererStackCookieCrashLoop(
+ options: RendererStackCookieCrashLoopOptions
+): boolean {
+ if ((options.platform ?? process.platform) !== 'win32') {
+ return false
+ }
+
+ if (String(options.reason || '') !== 'crashed') {
+ return false
+ }
+
+ if (!isWindowsStackCookieExit(options.exitCode)) {
+ return false
+ }
+
+ return Boolean(options.alreadyGpuDisabled || options.relaunchAttempted || options.gpuOverrideOff)
+}
+
+/**
+ * Launch-time transition: decide whether this Windows launch disables GPU
+ * for the sticky #108047 stack-cookie fallback AND what the marker becomes.
+ *
+ * - `fallback` is sticky within one app version. A version change re-probes
+ * GPU once so a fixed host returns to hardware acceleration.
+ * - A marker without a version stays sticky (legacy / no-version contract).
+ * - `HERMES_DESKTOP_DISABLE_GPU` explicitly off (`0`/`false`/`no`/`off`)
+ * fail-opens: do not disable GPU.
+ */
+export function decideWindowsGpuStackCookieLaunch(
+ options: {
+ platform?: NodeJS.Platform | string
+ env?: NodeJS.ProcessEnv
+ marker?: GpuStackCookieMarker | null
+ appVersion?: string
+ } = {}
+): GpuStackCookieLaunchDecision {
+ const appVersion = String(options.appVersion || '')
+ const env = options.env ?? process.env
+ const marker = options.marker ?? null
+
+ if ((options.platform ?? process.platform) !== 'win32') {
+ return { enable: false, reason: null, nextMarker: { state: 'booting' } }
+ }
+
+ if (isHermesDesktopGpuOverrideOff(env)) {
+ const nextMarker: GpuStackCookieMarker = marker?.state === 'fallback' ? marker : { state: 'booting' }
+
+ return { enable: false, reason: null, nextMarker }
+ }
+
+ if (marker?.state === 'fallback') {
+ if (marker.version && appVersion && marker.version !== appVersion) {
+ return {
+ enable: false,
+ reason: null,
+ nextMarker: { state: 'booting', reprobe: true }
+ }
+ }
+
+ return {
+ enable: true,
+ reason: 'sticky-fallback',
+ nextMarker: { ...marker, version: marker.version || appVersion || undefined }
+ }
+ }
+
+ return { enable: false, reason: null, nextMarker: { state: 'booting' } }
+}