The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): Linux GPU recovery matches Electron's launch-failed and ignores post-boot GPU kills
Tekniumf6535342dbc8
diff --git a/apps/desktop/electron/linux-gpu-fallback.test.ts b/apps/desktop/electron/linux-gpu-fallback.test.tsindex fb38f1dc4e3..c71e97422b7 100644--- a/apps/desktop/electron/linux-gpu-fallback.test.ts+++ b/apps/desktop/electron/linux-gpu-fallback.test.ts@@ -5,6 +5,7 @@ import {disableGpuSwitchNeededForReason,linuxGpuChildDeathPath,linuxGpuFallbackMarker,+ linuxGpuFallbackReasonForDeath,linuxGpuMarkerAfterSuccessfulBoot,parseLinuxGpuMarker,shouldEngageSilentGpuRetryFallback,@@ -323,3 +324,15 @@ describe('shouldEngageSilentGpuRetryFallback', () => {)})})++describe("Electron's real GPU launch-failure reason", () => {+ // Electron emits `launch-failed`; the recovery matched only `launch-failure`,+ // so a GPU child that never launched left Chromium's retry loop spinning (#134888).+ it('takes the bounded --disable-gpu step and records a launch failure', () => {+ const details = { type: 'GPU', reason: 'launch-failed', exitCode: 1002 }++ expect(linuxGpuChildDeathPath({ platform: 'linux', details })).toBe('disable-gpu')+ expect(shouldRelaunchForLinuxGpuCrash({ platform: 'linux', details })).toBe(true)+ expect(linuxGpuFallbackReasonForDeath(details.reason)).toBe('gpu-launch-failure')+ })+})diff --git a/apps/desktop/electron/linux-gpu-fallback.ts b/apps/desktop/electron/linux-gpu-fallback.tsindex 101c66bccdf..f2aa4ca26c9 100644--- a/apps/desktop/electron/linux-gpu-fallback.ts+++ b/apps/desktop/electron/linux-gpu-fallback.ts@@ -43,7 +43,16 @@ export const BOOT_ABORTS_BEFORE_LINUX_GPU_FALLBACK = 2export const LINUX_GPU_SILENT_RETRY_GRACE_S = 30/** `child-process-gone` reasons that witness a broken GPU child. */-const GPU_FAILURE_REASONS = new Set(['crashed', 'launch-failure'])+// `launch-failed` is the reason Electron actually emits (`Details['reason']`);+// `launch-failure` never arrives but stays so a legacy spelling still matches.+const GPU_FAILURE_REASONS = new Set(['crashed', 'launch-failed', 'launch-failure'])++/** Marker reason for a GPU-child death, keyed on Electron's real reason spelling. */+export function linuxGpuFallbackReasonForDeath(reason: unknown): LinuxGpuFallbackReason {+ const normalized = String(reason || '').toLowerCase()++ return normalized === 'launch-failed' || normalized === 'launch-failure' ? 'gpu-launch-failure' : 'gpu-crash'+}export type LinuxGpuMarkerState = 'booting' | 'fallback' | 'ok'diff --git a/apps/desktop/electron/linux-nvidia-egl-fallback.test.ts b/apps/desktop/electron/linux-nvidia-egl-fallback.test.tsindex 7ebf8704bd2..ff4775e6542 100644--- a/apps/desktop/electron/linux-nvidia-egl-fallback.test.ts+++ b/apps/desktop/electron/linux-nvidia-egl-fallback.test.ts@@ -101,10 +101,7 @@ describe('decideNvidiaEglFallback — behavioral probe', () => {// Chromium's "GPU process isn't usable" FATAL abort can kill the process// before the child-process-gone handler runs; the unresolved `booting`// marker is the evidence it leaves behind.- const decision = decideNvidiaEglFallback({- ...PROBE,- marker: { state: 'booting', version: PROBE.appVersion, driverVersion: PROBE.driverVersion }- })+ const decision = decideNvidiaEglFallback({ ...PROBE, marker: { state: 'booting' } })expect(decision.enable).toBe(true)expect(decision.reason).toContain('aborted')@@ -173,6 +170,8 @@ describe('shouldRelaunchForNvidiaGpuDeath', () => {})it('relaunches on a GPU launch failure', () => {+ expect(shouldRelaunchForNvidiaGpuDeath({ ...BASE, details: { type: 'GPU', reason: 'launch-failure' } })).toBe(true)+ // Electron's real spelling (`Details['reason']`); the recovery never fired on it before.expect(shouldRelaunchForNvidiaGpuDeath({ ...BASE, details: { type: 'GPU', reason: 'launch-failed' } })).toBe(true)})diff --git a/apps/desktop/electron/linux-nvidia-egl-fallback.ts b/apps/desktop/electron/linux-nvidia-egl-fallback.tsindex 3295c6a9ad6..5b6f44eb856 100644--- a/apps/desktop/electron/linux-nvidia-egl-fallback.ts+++ b/apps/desktop/electron/linux-nvidia-egl-fallback.ts@@ -57,9 +57,11 @@ export const NVIDIA_EGL_FALLBACK_MARKER_FILENAME = 'nvidia-egl-fallback.json'* included on purpose: in #40077 the GPU process exited with exit_code=15 —* Chromium's own GPU health check SIGTERM — not a crash reason.*/-export const NVIDIA_GPU_DEATH_REASONS: ReadonlySet<Details['reason']> = new Set<Details['reason']>([+export const NVIDIA_GPU_DEATH_REASONS: ReadonlySet<string> = new Set<string>(['crashed',- 'launch-failed',+ 'launch-failed' satisfies Details['reason'],+ // Never emitted by Electron; kept so a recorded/legacy spelling still matches.+ 'launch-failure','killed'])@@ -275,8 +277,12 @@ export function decideNvidiaEglFallback(options: NvidiaEglFallbackOptions): Nvid}// An abort is evidence only for the build and driver that actually attempted it.- // Legacy unqualified booting records get one fresh probe, as do stale fallbacks.- if (marker?.state === 'booting' && sameBuild) {+ // A legacy unqualified booting record is trusted only when this launch has no+ // stronger identity to compare it with; a stamped build re-probes it once.+ const unqualified = !marker?.version && !marker?.driverVersion && !marker?.build+ const hasBuildIdentity = Boolean(buildIdentity && buildIdentity !== appVersion)++ if (marker?.state === 'booting' && (sameBuild || (unqualified && !hasBuildIdentity))) {return {enable: true,reason: 'previous launch aborted mid-boot with the GPU probe live',@@ -289,7 +295,7 @@ export function decideNvidiaEglFallback(options: NvidiaEglFallbackOptions): Nvidexport interface NvidiaGpuDeathOptions {platform?: NodeJS.Platform | string- details: { type?: string; reason?: Details['reason'] } | null+ details: { type?: string; reason?: string } | null/** The fallback is already active this launch (sticky marker or override). */fallbackActive: boolean/** This process already attempted the one-shot relaunch. */@@ -313,9 +319,9 @@ export function shouldRelaunchForNvidiaGpuDeath({}const type = String(details?.type ?? '').toLowerCase()- const reason = details?.reason+ const reason = String(details?.reason ?? '').toLowerCase()- return (type === 'gpu' || type === 'gpu-process') && Boolean(reason && NVIDIA_GPU_DEATH_REASONS.has(reason))+ return (type === 'gpu' || type === 'gpu-process') && NVIDIA_GPU_DEATH_REASONS.has(reason)}/**diff --git a/apps/desktop/electron/linux-nvidia-egl-recovery.test.ts b/apps/desktop/electron/linux-nvidia-egl-recovery.test.tsindex cee43c85dfa..c1ae6e5528d 100644--- a/apps/desktop/electron/linux-nvidia-egl-recovery.test.ts+++ b/apps/desktop/electron/linux-nvidia-egl-recovery.test.ts@@ -7,7 +7,7 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'import { launchBuildIdentity } from './launch-build-identity'import { createLaunchMarkerWriter } from './launch-marker-writer'import { nvidiaEglMarkerPath, readNvidiaEglMarker, writeNvidiaEglMarker } from './linux-nvidia-egl-fallback'-import { createNvidiaEglRecovery } from './linux-nvidia-egl-recovery'+import { createNvidiaEglRecovery, NVIDIA_GPU_DEATH_WITNESS_GRACE_MS } from './linux-nvidia-egl-recovery'let userData: stringconst driverVersion = '600.1.2'@@ -160,3 +160,26 @@ describe('NVIDIA persisted recovery lifecycle', () => {expect(readNvidiaEglMarker(userData)?.state).toBe('fallback')})})++describe('NVIDIA GPU-death witness window', () => {+ it('a GPU child killed long after a healthy boot (logout, OOM) does not pin the next launch to SwiftShader', () => {+ let clock = 1_000+ const first = launch({ now: () => clock })+ first.healthy()+ clock += NVIDIA_GPU_DEATH_WITNESS_GRACE_MS + 1++ expect(first.gpuDied({ type: 'GPU', reason: 'killed', exitCode: 15 })).toBe(false)+ expect(first.relaunch).not.toHaveBeenCalled()+ expect(launch().decision.enable).toBe(false)+ })++ it('a GPU death right after the first reveal is still this launch failing', () => {+ let clock = 1_000+ const first = launch({ now: () => clock })+ first.healthy()+ clock += 5_000++ expect(first.gpuDied({ type: 'GPU', reason: 'killed', exitCode: 15 })).toBe(true)+ expect(launch().decision.enable).toBe(true)+ })+})diff --git a/apps/desktop/electron/linux-nvidia-egl-recovery.ts b/apps/desktop/electron/linux-nvidia-egl-recovery.tsindex c209e67c3b4..5627ac9140f 100644--- a/apps/desktop/electron/linux-nvidia-egl-recovery.ts+++ b/apps/desktop/electron/linux-nvidia-egl-recovery.ts@@ -16,8 +16,18 @@ interface NvidiaEglRecoveryOptions extends Omit<NvidiaEglFallbackOptions, 'markequeueMarker: (write: () => void) => voidrelaunch: () => voidlog: (message: string) => void+ now?: () => number}+/**+ * How long after the first window reveals a GPU-process death still counts as+ * this launch failing to bring the GPU up. Later deaths (session logout or OOM+ * killing the GPU child, a driver reset after suspend) are runtime events that+ * Chromium recovers from itself; pinning every future launch to SwiftShader for+ * them turned healthy hosts into 4-9 core CPU burns (#131321, #141753).+ */+export const NVIDIA_GPU_DEATH_WITNESS_GRACE_MS = 60_000+/** Persist only for the lock owner, and never turn intentional teardown into GPU failure. */export function createNvidiaEglRecovery(options: NvidiaEglRecoveryOptions) {const previous = readNvidiaEglMarker(options.userData)@@ -26,6 +36,8 @@ export function createNvidiaEglRecovery(options: NvidiaEglRecoveryOptions) {let primary = falselet quitting = falselet relaunchAttempted = false+ let healthyAt: number | null = null+ const now = options.now ?? Date.nowconst persist = (marker: NvidiaEglMarker): void => {try {@@ -50,6 +62,8 @@ export function createNvidiaEglRecovery(options: NvidiaEglRecoveryOptions) {return}+ healthyAt ??= now()+persist(nvidiaEglMarkerAfterSuccessfulBoot({ ...options, fallbackActive: decision.enable }))},cleanExit(): void {@@ -76,6 +90,7 @@ export function createNvidiaEglRecovery(options: NvidiaEglRecoveryOptions) {!primary ||quitting ||teardownInProgress ||+ (healthyAt !== null && now() - healthyAt > NVIDIA_GPU_DEATH_WITNESS_GRACE_MS) ||!nvidiaEglFallbackAllowed(options) ||!shouldRelaunchForNvidiaGpuDeath({platform: options.platform,diff --git a/apps/desktop/electron/main.ts b/apps/desktop/electron/main.tsindex 097495c7d2f..ceee9eca3a9 100644--- a/apps/desktop/electron/main.ts+++ b/apps/desktop/electron/main.ts@@ -333,6 +333,7 @@ import {LINUX_GPU_SILENT_RETRY_GRACE_S,linuxGpuChildDeathPath,linuxGpuFallbackMarker,+ linuxGpuFallbackReasonForDeath,linuxGpuMarkerAfterSuccessfulBoot,readLinuxGpuMarker,shouldEngageSilentGpuRetryFallback,@@ -1123,8 +1124,7 @@ if (IS_WINDOWS || process.platform === 'linux') {linuxGpuFallbackActive = truelinuxGpuFallbackSticky = true- const reason =- String(details?.reason || '').toLowerCase() === 'launch-failure' ? 'gpu-launch-failure' : 'gpu-crash'+ const reason = linuxGpuFallbackReasonForDeath(details?.reason)try {writeLinuxGpuMarker(app.getPath('userData'), linuxGpuFallbackMarker(reason, app.getVersion()))