The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): route ANGLE through SwiftShader on NVIDIA 580+ Linux drivers
Austin Pickett7262ab2d9af3
diff --git a/apps/desktop/electron/linux-nvidia-egl-fallback.test.ts b/apps/desktop/electron/linux-nvidia-egl-fallback.test.tsnew file mode 100644index 00000000000..ab23c3cb5e9--- /dev/null+++ b/apps/desktop/electron/linux-nvidia-egl-fallback.test.ts@@ -0,0 +1,101 @@+import { describe, expect, it } from 'vitest'++import {+ decideNvidiaEglFallback,+ NVIDIA_BROKEN_EGL_MAJOR,+ parseNvidiaDriverMajor+} from './linux-nvidia-egl-fallback'++const LINUX = { env: {}, platform: 'linux' as const, isWsl: false, remoteDisplayReason: null }++describe('parseNvidiaDriverMajor', () => {+ it('parses the major from /proc/driver/nvidia/version content', () => {+ const text =+ 'NVRM version: NVIDIA UNIX x86_64 Kernel Module 580.82.09 Mon Jul 21 19:44:16 UTC 2025\n'++ expect(parseNvidiaDriverMajor(text)).toBe(580)+ })++ it('parses 3-digit majors like 570 and 550', () => {+ expect(parseNvidiaDriverMajor('NVRM version: ... 570.133.07 ...\n')).toBe(570)+ expect(parseNvidiaDriverMajor('NVRM version: ... 550.107.02 ...\n')).toBe(550)+ })++ it('returns null for garbage or empty input', () => {+ expect(parseNvidiaDriverMajor('')).toBeNull()+ expect(parseNvidiaDriverMajor('no driver version here')).toBeNull()+ })+})++describe('decideNvidiaEglFallback', () => {+ it('enables on linux with driver >= 580', () => {+ const decision = decideNvidiaEglFallback({ ...LINUX, driverMajor: 580 })+ expect(decision.enable).toBe(true)+ expect(decision.reason).toContain('580')+ })++ it('enables on newer majors (570-series is fine, 580+ is not)', () => {+ expect(decideNvidiaEglFallback({ ...LINUX, driverMajor: 570 }).enable).toBe(false)+ expect(decideNvidiaEglFallback({ ...LINUX, driverMajor: 580 + 5 }).enable).toBe(true)+ expect(NVIDIA_BROKEN_EGL_MAJOR).toBe(580)+ })++ it('stays off below the broken major and when detection finds no driver', () => {+ expect(decideNvidiaEglFallback({ ...LINUX, driverMajor: 570 }).enable).toBe(false)+ expect(decideNvidiaEglFallback({ ...LINUX, driverMajor: null }).enable).toBe(false)+ })++ it('stays off on non-linux platforms', () => {+ expect(+ decideNvidiaEglFallback({ ...LINUX, platform: 'darwin', driverMajor: 580 }).enable+ ).toBe(false)+ expect(+ decideNvidiaEglFallback({ ...LINUX, platform: 'win32', driverMajor: 580 }).enable+ ).toBe(false)+ })++ it('stays off under WSLg', () => {+ expect(decideNvidiaEglFallback({ ...LINUX, isWsl: true, driverMajor: 580 }).enable).toBe(false)+ })++ it('stays off when a remote display already forced software rendering', () => {+ expect(+ decideNvidiaEglFallback({+ ...LINUX,+ driverMajor: 580,+ remoteDisplayReason: 'ssh-session'+ }).enable+ ).toBe(false)+ })++ it('HERMES_DESKTOP_DISABLE_GPU=0 keeps the GPU (and the fallback) off', () => {+ expect(+ decideNvidiaEglFallback({+ ...LINUX,+ driverMajor: 580,+ env: { HERMES_DESKTOP_DISABLE_GPU: '0' }+ }).enable+ ).toBe(false)+ })++ it('HERMES_DESKTOP_NVIDIA_SWIFTSHADER forces the fallback on without detection', () => {+ const decision = decideNvidiaEglFallback({+ ...LINUX,+ driverMajor: null,+ env: { HERMES_DESKTOP_NVIDIA_SWIFTSHADER: '1' }+ })++ expect(decision.enable).toBe(true)+ expect(decision.reason).toContain('override')+ })++ it('HERMES_DESKTOP_NVIDIA_SWIFTSHADER=0 opts out even on affected drivers', () => {+ expect(+ decideNvidiaEglFallback({+ ...LINUX,+ driverMajor: 580,+ env: { HERMES_DESKTOP_NVIDIA_SWIFTSHADER: 'off' }+ }).enable+ ).toBe(false)+ })+})diff --git a/apps/desktop/electron/linux-nvidia-egl-fallback.ts b/apps/desktop/electron/linux-nvidia-egl-fallback.tsnew file mode 100644index 00000000000..cda71c33771--- /dev/null+++ b/apps/desktop/electron/linux-nvidia-egl-fallback.ts@@ -0,0 +1,109 @@+/**+ * Linux NVIDIA 580+ EGL fallback for #40077.+ *+ * NVIDIA driver 580+ breaks ANGLE's EGL probing on X11/Wayland: the bundled+ * ANGLE `libEGL.so` probes the driver's EGL implementation, hits the 580+ * EGL/X11 bug ("Invalid visual ID requested"), and the GPU process dies —+ * taking the app with it. Rendering through ANGLE's SwiftShader backend+ * (`--use-angle=swiftshader`) skips the NVIDIA EGL probe entirely, so the app+ * launches and stays up; the cost is CPU rendering (slow but stable).+ *+ * Deliberately NOT `app.disableHardwareAcceleration()`: on 580.173.02 ++ * Electron 40 that path SIGKILLs the renderer (see #40077 discussion, and the+ * closed #40119 which was rejected for exactly this). We only reroute ANGLE;+ * we never disable the GPU pipeline wholesale.+ *+ * Skipped when a remote display already forced software rendering (the+ * `--disable-gpu-compositing` path covers it), under WSLg (vGPU is healthy+ * there), or when `HERMES_DESKTOP_DISABLE_GPU=0` keeps the GPU on.+ * `HERMES_DESKTOP_NVIDIA_SWIFTSHADER` overrides detection both ways.+ *+ * Pure + dependency-free so it can be unit-tested and called before app ready.+ */++const OVERRIDE_ON = new Set(['1', 'true', 'yes', 'on'])+const OVERRIDE_OFF = new Set(['0', 'false', 'no', 'off'])++/** First driver major with the broken EGL/X11 probing (580.x and newer). */+export const NVIDIA_BROKEN_EGL_MAJOR = 580++export interface NvidiaEglFallbackDecision {+ enable: boolean+ reason: string | null+}++/**+ * Extract the driver major version from /proc/driver/nvidia/version content.+ * Format: "NVRM version: NVIDIA UNIX x86_64 Kernel Module 580.82.09 ..."+ */+export function parseNvidiaDriverMajor(procVersion: string): number | null {+ const match = /\b(\d{3,})\.\d+\.\d+\b/.exec(String(procVersion || ''))++ if (!match) {+ return null+ }++ const major = Number.parseInt(match[1], 10)++ return Number.isFinite(major) ? major : null+}++export function decideNvidiaEglFallback(options: {+ driverMajor: number | null+ env?: NodeJS.ProcessEnv+ platform?: NodeJS.Platform+ isWsl?: boolean+ remoteDisplayReason?: string | null+}): NvidiaEglFallbackDecision {+ const env = options.env ?? process.env+ const platform = options.platform ?? process.platform+ const isWsl = options.isWsl ?? false+ const remoteDisplayReason = options.remoteDisplayReason ?? null+ const driverMajor = options.driverMajor++ const nvidiaOverride = String(env.HERMES_DESKTOP_NVIDIA_SWIFTSHADER || '')+ .trim()+ .toLowerCase()++ if (OVERRIDE_OFF.has(nvidiaOverride)) {+ return { enable: false, reason: null }+ }++ if (platform !== 'linux') {+ return { enable: false, reason: null }+ }++ // A user who forced GPU back on (HERMES_DESKTOP_DISABLE_GPU=0) owns that call.+ const gpuOverride = String(env.HERMES_DESKTOP_DISABLE_GPU || '')+ .trim()+ .toLowerCase()++ if (OVERRIDE_OFF.has(gpuOverride)) {+ return { enable: false, reason: null }+ }++ // The remote-display path already forces full software rendering; don't pile+ // ANGLE switches on top of `disableHardwareAcceleration`.+ if (remoteDisplayReason) {+ return { enable: false, reason: null }+ }++ // WSLg reports a healthy vGPU; NVIDIA 580 EGL probing hasn't been reported+ // broken there. Keep the WSL GPU passthrough path untouched.+ if (isWsl) {+ return { enable: false, reason: null }+ }++ const detected =+ driverMajor !== null && driverMajor >= NVIDIA_BROKEN_EGL_MAJOR++ if (!detected && !OVERRIDE_ON.has(nvidiaOverride)) {+ return { enable: false, reason: null }+ }++ const reason = detected+ ? `NVIDIA driver ${driverMajor} (>= ${NVIDIA_BROKEN_EGL_MAJOR})`+ : 'override (HERMES_DESKTOP_NVIDIA_SWIFTSHADER)'++ return { enable: true, reason }+}diff --git a/apps/desktop/electron/main.ts b/apps/desktop/electron/main.tsindex 9c60ee65445..1d592125030 100644--- a/apps/desktop/electron/main.ts+++ b/apps/desktop/electron/main.ts@@ -304,6 +304,7 @@ import { isAuthWall, resolveLinkTitle } from './link-title-wall'import { createLinkTitleWindow, guardLinkTitleSession, readLinkTitleWindowTitle } from './link-title-window'import { CHROMIUM_LOG_FILENAME, enableLinuxCrashDiagnostics, linuxCrashDiagnostics } from './linux-crash-diagnostics'import { notifyLauncherWindowRevealed } from './linux-launcher-ready'+import { decideNvidiaEglFallback, parseNvidiaDriverMajor } from './linux-nvidia-egl-fallback'import { createLocalBackendLifecycle, waitForTeardown } from './local-backend-lifecycle'import { localSkinProfileKey, readLocalSkinPayload } from './local-skin'import { ACTIVE_LOG_POLL_MS, planLogRotation, reclaimActiveLogIfOversized } from './log-rotation'@@ -720,6 +721,38 @@ if (IS_WSL && !REMOTE_DISPLAY_REASON && fs.existsSync('/dev/dxg')) {console.log('[hermes] WSL GPU passthrough (/dev/dxg) detected; enabling GPU acceleration')}+// #40077: NVIDIA driver 580+ breaks ANGLE's EGL probing (Invalid visual ID),+// killing the GPU process at startup. Route ANGLE through its SwiftShader+// backend instead — the app then launches and stays up (CPU rendering, slow+// but stable). Deliberately NOT disableHardwareAcceleration(): on 580.173.02 ++// Electron 40 that SIGKILLs the renderer (see the closed #40119). Must run+// before app `ready` — the switch only applies pre-launch. Override with+// HERMES_DESKTOP_NVIDIA_SWIFTSHADER (1/true → force on, 0/false → never).+const NVIDIA_EGL_FALLBACK = decideNvidiaEglFallback({+ driverMajor: parseNvidiaDriverMajor(+ (() => {+ try {+ return fs.readFileSync('/proc/driver/nvidia/version', 'utf8')+ } catch {+ return ''+ }+ })()+ ),+ env: process.env,+ platform: process.platform,+ isWsl: IS_WSL,+ remoteDisplayReason: REMOTE_DISPLAY_REASON+})++if (NVIDIA_EGL_FALLBACK.enable) {+ app.commandLine.appendSwitch('use-angle', 'swiftshader')+ console.log(+ `[hermes] NVIDIA EGL fallback enabled (${NVIDIA_EGL_FALLBACK.reason}); routing ANGLE ` ++ 'through SwiftShader to avoid the NVIDIA 580+ EGL probe crash (#40077). ' ++ 'HERMES_DESKTOP_NVIDIA_SWIFTSHADER=0 to opt out.'+ )+}+// Linux: point Chromium at the session's keychain backend so safeStorage can// encrypt remote gateway tokens (hardening.ts refuses to persist them without// it). The value arrives via HERMES_DESKTOP_PASSWORD_STORE, bridged by the