The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): a late GPU crash on Mesa/AMD/Intel Linux no longer pins software rendering
Teknium198f6ad53c66
diff --git a/apps/desktop/electron/fixtures/nvidia-recovery.ts b/apps/desktop/electron/fixtures/nvidia-recovery.tsindex 67940936ecc..780addd9cd7 100644--- a/apps/desktop/electron/fixtures/nvidia-recovery.ts+++ b/apps/desktop/electron/fixtures/nvidia-recovery.ts@@ -6,6 +6,7 @@ import { app } from 'electron'import { INSTALL_STAMP } from '../install-stamp'import { launchBuildIdentity } from '../launch-build-identity'+import { createLinuxGpuBootWindow } from '../linux-gpu-fallback'import { readNvidiaEglMarker } from '../linux-nvidia-egl-fallback'import { createNvidiaEglRecovery } from '../linux-nvidia-egl-recovery'@@ -27,7 +28,10 @@ const report = (event: string, data: Record<string, unknown> = {}) => {appendFileSync(options.eventsFile, `${JSON.stringify({ event, ...data })}\n`, 'utf8')}+const bootWindow = createLinuxGpuBootWindow({ platform: 'linux' })+const recovery = createNvidiaEglRecovery({+ bootWindow,userData: options.userData,appVersion: app.getVersion(),buildIdentity: launchBuildIdentity({ appVersion: app.getVersion(), installStamp: INSTALL_STAMP }),@@ -54,6 +58,7 @@ if (!primary) {return}+ bootWindow.revealed()recovery.healthy()report('ready', { software: recovery.decision.enable, marker: readNvidiaEglMarker(options.userData) })diff --git a/apps/desktop/electron/linux-gpu-fallback.test.ts b/apps/desktop/electron/linux-gpu-fallback.test.tsindex c71e97422b7..c63eba67845 100644--- a/apps/desktop/electron/linux-gpu-fallback.test.ts+++ b/apps/desktop/electron/linux-gpu-fallback.test.ts@@ -1,8 +1,10 @@import { describe, expect, it } from 'vitest'import {+ createLinuxGpuBootWindow,decideLinuxGpuLaunch,disableGpuSwitchNeededForReason,+ LINUX_GPU_DEATH_WITNESS_GRACE_MS,linuxGpuChildDeathPath,linuxGpuFallbackMarker,linuxGpuFallbackReasonForDeath,@@ -336,3 +338,23 @@ describe("Electron's real GPU launch-failure reason", () => {expect(linuxGpuFallbackReasonForDeath(details.reason)).toBe('gpu-launch-failure')})})++describe('Linux GPU boot window on a host without an NVIDIA driver', () => {+ // Mesa/AMD/Intel: the witness window gated only the NVIDIA ladder, so a GPU crash+ // hours after a healthy boot relaunched with --disable-gpu and pinned software forever.+ it('a crash long after the first reveal takes no --disable-gpu relaunch; a crash during boot still does', () => {+ let clock = 1_000+ const bootWindow = createLinuxGpuBootWindow({ platform: 'linux', now: () => clock })+ const details = { type: 'GPU', reason: 'crashed', exitCode: 139 }++ const path = () =>+ linuxGpuChildDeathPath({ platform: 'linux', details, runtimeDeath: bootWindow.afterBootWindow() })++ expect(path()).toBe('disable-gpu')+ bootWindow.revealed()+ clock += 5_000+ expect(path()).toBe('disable-gpu')+ clock += LINUX_GPU_DEATH_WITNESS_GRACE_MS+ expect(path()).toBeNull()+ })+})diff --git a/apps/desktop/electron/linux-gpu-fallback.ts b/apps/desktop/electron/linux-gpu-fallback.tsindex e630b1e6f51..203526de81f 100644--- a/apps/desktop/electron/linux-gpu-fallback.ts+++ b/apps/desktop/electron/linux-gpu-fallback.ts@@ -35,6 +35,44 @@ export const LINUX_GPU_FALLBACK_MARKER_FILENAME = 'linux-gpu-fallback.json'/** Consecutive mid-boot aborts required before falling back to software. */export const BOOT_ABORTS_BEFORE_LINUX_GPU_FALLBACK = 2+/**+ * How long after the first window reveals a GPU-child 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 software+ * rendering for them turned healthy hosts into 4-9 core CPU burns (#131321, #141753).+ */+export const LINUX_GPU_DEATH_WITNESS_GRACE_MS = 60_000++export interface LinuxGpuBootWindow {+ /** The first window is on screen. Only the first call counts. */+ revealed: () => void+ /** A GPU death now is a runtime event: no recovery ladder may relaunch or write a fallback for it. */+ afterBootWindow: () => boolean+}++/**+ * One boot clock per Linux launch, whatever the GPU vendor: the `--disable-gpu`+ * ladder (Mesa, AMD, Intel, NVIDIA) and the NVIDIA ANGLE ladder both read it,+ * so a late crash pins neither.+ */+export function createLinuxGpuBootWindow(+ options: { platform?: NodeJS.Platform | string; now?: () => number } = {}+): LinuxGpuBootWindow {+ const linux = (options.platform ?? process.platform) === 'linux'+ const now = options.now ?? Date.now+ let revealedAt: number | null = null++ return {+ revealed: () => {+ if (linux) {+ revealedAt ??= now()+ }+ },+ afterBootWindow: () => revealedAt !== null && now() - revealedAt > LINUX_GPU_DEATH_WITNESS_GRACE_MS+ }+}+/*** Seconds after the main window reveals before the #124843 silent-retry check* looks for a GPU child: long enough that a healthy host's GPU child exists,diff --git a/apps/desktop/electron/linux-nvidia-egl-recovery.test.ts b/apps/desktop/electron/linux-nvidia-egl-recovery.test.tsindex 4178588df06..592e99ee7aa 100644--- a/apps/desktop/electron/linux-nvidia-egl-recovery.test.ts+++ b/apps/desktop/electron/linux-nvidia-egl-recovery.test.ts@@ -5,9 +5,13 @@ import path from 'node:path'import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'import { launchBuildIdentity } from './launch-build-identity'-import { linuxGpuChildDeathPath } from './linux-gpu-fallback'+import {+ createLinuxGpuBootWindow,+ LINUX_GPU_DEATH_WITNESS_GRACE_MS,+ linuxGpuChildDeathPath+} from './linux-gpu-fallback'import { nvidiaEglMarkerPath, readNvidiaEglMarker, writeNvidiaEglMarker } from './linux-nvidia-egl-fallback'-import { createNvidiaEglRecovery, NVIDIA_GPU_DEATH_WITNESS_GRACE_MS } from './linux-nvidia-egl-recovery'+import { createNvidiaEglRecovery } from './linux-nvidia-egl-recovery'let userData: stringconst driverVersion = '600.1.2'@@ -18,11 +22,15 @@ const build = (commit = 'a'.repeat(40)) =>installStamp: { commit, builtAt: '2026-10-23T00:00:00Z', dirty: false }})-function launch(overrides: Partial<Parameters<typeof createNvidiaEglRecovery>[0]> = {}, primary = true) {+type RecoveryOptions = Parameters<typeof createNvidiaEglRecovery>[0]++function launch({ now, ...overrides }: Partial<RecoveryOptions> & { now?: () => number } = {}, primary = true) {const relaunch = vi.fn()const log = vi.fn()+ const bootWindow = createLinuxGpuBootWindow({ platform: 'linux', now })const recovery = createNvidiaEglRecovery({+ bootWindow,userData,driverMajor: 600,driverVersion,@@ -36,7 +44,13 @@ function launch(overrides: Partial<Parameters<typeof createNvidiaEglRecovery>[0]...overrides})- return { ...recovery, relaunch, log }+ // main.ts's window reveal: the shared boot clock first, then the NVIDIA marker.+ const healthy = () => {+ bootWindow.revealed()+ recovery.healthy()+ }++ return { ...recovery, healthy, afterBootWindow: bootWindow.afterBootWindow, relaunch, log }}beforeEach(() => {@@ -178,7 +192,7 @@ describe('NVIDIA GPU-death witness window', () => {let clock = 1_000const first = launch({ now: () => clock })first.healthy()- clock += NVIDIA_GPU_DEATH_WITNESS_GRACE_MS + 1+ clock += LINUX_GPU_DEATH_WITNESS_GRACE_MS + 1expect(first.gpuDied({ type: 'GPU', reason: 'killed', exitCode: 15 })).toBe(false)expect(first.relaunch).not.toHaveBeenCalled()@@ -199,7 +213,7 @@ describe('NVIDIA GPU-death witness window', () => {let clock = 1_000const first = launch({ now: () => clock })first.healthy()- clock += NVIDIA_GPU_DEATH_WITNESS_GRACE_MS + 1+ clock += LINUX_GPU_DEATH_WITNESS_GRACE_MS + 1const details = { type: 'GPU', reason: 'crashed', exitCode: 139 } as const// main.ts asks both ladders about the same death.diff --git a/apps/desktop/electron/linux-nvidia-egl-recovery.ts b/apps/desktop/electron/linux-nvidia-egl-recovery.tsindex b609dc073e3..fe7e3c52cbb 100644--- a/apps/desktop/electron/linux-nvidia-egl-recovery.ts+++ b/apps/desktop/electron/linux-nvidia-egl-recovery.ts@@ -1,5 +1,6 @@import type { Details } from 'electron'+import type { LinuxGpuBootWindow } from './linux-gpu-fallback'import type { NvidiaEglFallbackOptions, NvidiaEglMarker } from './linux-nvidia-egl-fallback'import {decideNvidiaEglFallback,@@ -19,18 +20,10 @@ interface NvidiaEglRecoveryOptions extends Omit<NvidiaEglFallbackOptions, 'markerelaunch: (extraArgs: readonly string[]) => voidargv?: readonly string[]log: (message: string) => void- now?: () => number+ /** The launch's shared Linux boot clock; the caller records the first reveal on it. */+ bootWindow: LinuxGpuBootWindow}-/**- * 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-const SWIFTSHADER_SWITCH = '--use-angle=swiftshader'/** Persist only for the lock owner, and never turn intentional teardown into GPU failure. */@@ -41,9 +34,6 @@ export function createNvidiaEglRecovery(options: NvidiaEglRecoveryOptions) {const primary = supported && options.primarylet quitting = falselet relaunchAttempted = false- let healthyAt: number | null = null- const now = options.now ?? Date.now- const afterBootWindow = (): boolean => healthyAt !== null && now() - healthyAt > NVIDIA_GPU_DEATH_WITNESS_GRACE_MS// A relaunch that carried the fallback on argv because the marker was unwritable.const argvFallback = (options.argv ?? process.argv).includes(SWIFTSHADER_SWITCH)@@ -68,15 +58,11 @@ export function createNvidiaEglRecovery(options: NvidiaEglRecoveryOptions) {return {decision,startupMessage: `[gpu] NVIDIA ANGLE fallback=${decision.enable} (${decision.reason ?? 'not selected'}); previous=${previous?.state ?? 'none'}; build=${options.buildIdentity ?? options.appVersion}; driver=${options.driverVersion}`,- /** A GPU death now is a runtime event: no recovery ladder may relaunch or write a fallback for it. */- afterBootWindow,healthy(): void {if (!primary || quitting || relaunchAttempted) {return}- healthyAt ??= now()-persist(nvidiaEglMarkerAfterSuccessfulBoot({ ...options, fallbackActive: decision.enable }))},cleanExit(): void {@@ -103,7 +89,7 @@ export function createNvidiaEglRecovery(options: NvidiaEglRecoveryOptions) {!primary ||quitting ||teardownInProgress ||- afterBootWindow() ||+ options.bootWindow.afterBootWindow() ||!nvidiaEglFallbackAllowed(options) ||!shouldRelaunchForNvidiaGpuDeath({platform: options.platform,diff --git a/apps/desktop/electron/main.ts b/apps/desktop/electron/main.tsindex b26fda126df..b56aa76723c 100644--- a/apps/desktop/electron/main.ts+++ b/apps/desktop/electron/main.ts@@ -328,6 +328,7 @@ import { applyLaunchProfileOverride } from './launch-profile'import { fetchLinkTitle, resolveFaviconCached } from './link-metadata'import { CHROMIUM_LOG_FILENAME, enableLinuxCrashDiagnostics, linuxCrashDiagnostics } from './linux-crash-diagnostics'import {+ createLinuxGpuBootWindow,decideLinuxGpuLaunch,disableGpuSwitchNeededForReason,LINUX_GPU_SILENT_RETRY_GRACE_S,@@ -906,7 +907,11 @@ const NVIDIA_PROC_VERSION = (() => {const NVIDIA_DRIVER_MAJOR = parseNvidiaDriverMajor(NVIDIA_PROC_VERSION)const NVIDIA_DRIVER_VERSION = parseNvidiaDriverVersion(NVIDIA_PROC_VERSION)+// Every Linux launch's boot clock, NVIDIA or not; set at the first window reveal.+const linuxGpuBootWindow = createLinuxGpuBootWindow()+const nvidiaEglRecovery = createNvidiaEglRecovery({+ bootWindow: linuxGpuBootWindow,driverMajor: NVIDIA_DRIVER_MAJOR,driverVersion: NVIDIA_DRIVER_VERSION,userData: app.getPath('userData'),@@ -1134,7 +1139,7 @@ if (IS_WINDOWS || process.platform === 'linux') {alreadySoftware,sandboxRelaunchAttempted: windowsNoSandboxRelaunchAttempted,softwareRelaunchAttempted: linuxGpuRelaunchAttempted,- runtimeDeath: nvidiaEglRecovery.afterBootWindow()+ runtimeDeath: linuxGpuBootWindow.afterBootWindow()})// One event must not schedule both ANGLE and disable-gpu relaunches.@@ -13694,6 +13699,7 @@ function createWindow() {// window is on screen (a STARTING gnome-shell app must not see its entry change).notifyLauncherWindowRevealed()+ linuxGpuBootWindow.revealed()nvidiaEglRecovery.healthy()// #38216/#121954: clear the mid-boot marker only after a window is