The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): an unwritable NVIDIA witness relaunches with SwiftShader on argv, not a repeat launch
Tekniumfc43e1b33fe2
diff --git a/apps/desktop/electron/linux-nvidia-egl-recovery.test.ts b/apps/desktop/electron/linux-nvidia-egl-recovery.test.tsindex 4a1aca91cb5..35e015fb0f8 100644--- a/apps/desktop/electron/linux-nvidia-egl-recovery.test.ts+++ b/apps/desktop/electron/linux-nvidia-egl-recovery.test.ts@@ -1,4 +1,4 @@-import { mkdtempSync, readFileSync, rmSync } from 'node:fs'+import { mkdirSync, mkdtempSync, readFileSync, rmSync } from 'node:fs'import { tmpdir } from 'node:os'import path from 'node:path'@@ -162,6 +162,21 @@ describe('NVIDIA persisted recovery lifecycle', () => {})})+describe('NVIDIA witness that cannot be persisted', () => {+ it('relaunches with SwiftShader on argv instead of repeating the launch, and that relaunch cannot loop', () => {+ mkdirSync(nvidiaEglMarkerPath(userData))+ const details = { type: 'GPU', reason: 'crashed', exitCode: 139 } as const+ const first = launch()++ expect(first.gpuDied(details)).toBe(true)+ expect(first.relaunch).toHaveBeenCalledWith(['--use-angle=swiftshader'])++ const relaunched = launch({ argv: ['electron', '.', '--use-angle=swiftshader'] })+ expect(relaunched.gpuDied(details)).toBe(false)+ expect(relaunched.relaunch).not.toHaveBeenCalled()+ })+})+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_000diff --git a/apps/desktop/electron/linux-nvidia-egl-recovery.ts b/apps/desktop/electron/linux-nvidia-egl-recovery.tsindex 946901a70b3..a98ff378e4e 100644--- a/apps/desktop/electron/linux-nvidia-egl-recovery.ts+++ b/apps/desktop/electron/linux-nvidia-egl-recovery.ts@@ -14,7 +14,9 @@ import {interface NvidiaEglRecoveryOptions extends Omit<NvidiaEglFallbackOptions, 'marker'> {userData: stringqueueMarker: (write: () => void) => void- relaunch: () => void+ /** Extra argv for the relaunch; non-empty only when the witness could not be persisted. */+ relaunch: (extraArgs: readonly string[]) => void+ argv?: readonly string[]log: (message: string) => voidnow?: () => number}@@ -28,6 +30,8 @@ interface NvidiaEglRecoveryOptions extends Omit<NvidiaEglFallbackOptions, 'marke*/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. */export function createNvidiaEglRecovery(options: NvidiaEglRecoveryOptions) {const previous = readNvidiaEglMarker(options.userData)@@ -40,11 +44,18 @@ export function createNvidiaEglRecovery(options: NvidiaEglRecoveryOptions) {const now = options.now ?? Date.nowconst afterBootWindow = (): boolean => healthyAt !== null && now() - healthyAt > NVIDIA_GPU_DEATH_WITNESS_GRACE_MS- const persist = (marker: NvidiaEglMarker): void => {+ // A relaunch that carried the fallback on argv because the marker was unwritable.+ const argvFallback = (options.argv ?? process.argv).includes(SWIFTSHADER_SWITCH)++ const persist = (marker: NvidiaEglMarker): boolean => {try {writeNvidiaEglMarker(options.userData, marker)++ return true} catch (error) {options.log(`[gpu] could not persist NVIDIA recovery state: ${String(error)}`)++ return false}}@@ -98,7 +109,7 @@ export function createNvidiaEglRecovery(options: NvidiaEglRecoveryOptions) {!shouldRelaunchForNvidiaGpuDeath({platform: options.platform,details,- fallbackActive: decision.enable,+ fallbackActive: decision.enable || argvFallback,relaunchAttempted})) {@@ -106,19 +117,22 @@ export function createNvidiaEglRecovery(options: NvidiaEglRecoveryOptions) {}relaunchAttempted = true- persist(++ const persisted = persist(nvidiaEglFallbackMarker(options.appVersion ?? '',options.driverVersion ?? String(options.driverMajor),options.buildIdentity))+options.log(- `[gpu] NVIDIA GPU process died (${details.reason}, exit=${details.exitCode}); relaunching with SwiftShader`+ `[gpu] NVIDIA GPU process died (${details.reason}, exit=${details.exitCode}); relaunching with SwiftShader${persisted ? '' : ' on argv (marker unwritable)'}`)try {- options.relaunch()+ // Without the witness on disk the next launch would repeat this one.+ options.relaunch(persisted ? [] : [SWIFTSHADER_SWITCH])} catch (error) {options.log(`[gpu] NVIDIA SwiftShader relaunch failed: ${String(error)}`)}diff --git a/apps/desktop/electron/main.ts b/apps/desktop/electron/main.tsindex 94f89e88425..cd3fbc96d75 100644--- a/apps/desktop/electron/main.ts+++ b/apps/desktop/electron/main.ts@@ -883,10 +883,9 @@ const nvidiaEglRecovery = createNvidiaEglRecovery({flushDesktopLogBufferSync()})},- relaunch: () => {- // The persisted witness selects ANGLE on the next launch. Do not carry an- // automatic --use-angle flag into later update relaunches.- app.relaunch({ args: process.argv.slice(1) })+ relaunch: extraArgs => {+ // The persisted witness selects ANGLE next launch; argv carries it only when unwritable.+ app.relaunch({ args: [...process.argv.slice(1), ...extraArgs] })void exitAfterBackendShutdown(0)}})