fix(desktop): pass --disable-gpu on 0xC0000409 relaunch so marker write failure cannot loop
Co-authored-by: Cursor <cursoragent@cursor.com> (cherry picked from commit ecaf213873ca00654d1b3cf543eb56e5bf3279c3)
This commit is contained in:
1 parent
2e36513ef9
commit
085d9ee608
3 files changed
+112
-3
No files matched your search
@@ -576,6 +576,8 @@ import {
|
||||
writeSandboxMarker
|
||||
} from './windows-sandbox-fallback'
|
||||
import {
|
||||
alreadyHasDisableGpu,
|
||||
buildDisableGpuRelaunchArgs,
|
||||
decideWindowsGpuStackCookieLaunch,
|
||||
gpuStackCookieFallbackMarker,
|
||||
isHermesDesktopGpuOverrideOff,
|
||||
@@ -653,17 +655,20 @@ if (REMOTE_DISPLAY_REASON) {
|
||||
// `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 windowsGpuStackCookieFallbackSticky = false
|
||||
let windowsGpuStackCookieRelaunchAttempted = false
|
||||
|
||||
if (IS_WINDOWS) {
|
||||
const windowsGpuUserData = app.getPath('userData')
|
||||
const gpuStackCookieDecision = decideWindowsGpuStackCookieLaunch({
|
||||
argv: process.argv,
|
||||
marker: readGpuStackCookieMarker(windowsGpuUserData),
|
||||
env: process.env,
|
||||
appVersion: app.getVersion()
|
||||
})
|
||||
|
||||
windowsGpuStackCookieFallbackActive = gpuStackCookieDecision.enable
|
||||
windowsGpuStackCookieFallbackSticky = gpuStackCookieDecision.nextMarker.state === 'fallback'
|
||||
|
||||
try {
|
||||
writeGpuStackCookieMarker(windowsGpuUserData, gpuStackCookieDecision.nextMarker)
|
||||
@@ -14636,7 +14641,7 @@ function createWindow() {
|
||||
writeGpuStackCookieMarker(
|
||||
app.getPath('userData'),
|
||||
markerAfterSuccessfulGpuStackCookieBoot({
|
||||
fallbackActive: windowsGpuStackCookieFallbackActive,
|
||||
fallbackActive: windowsGpuStackCookieFallbackSticky,
|
||||
appVersion: app.getVersion()
|
||||
})
|
||||
)
|
||||
@@ -14699,7 +14704,10 @@ function createWindow() {
|
||||
const stackCookieCrashLoop = {
|
||||
reason: details?.reason,
|
||||
exitCode: details?.exitCode,
|
||||
alreadyGpuDisabled: Boolean(REMOTE_DISPLAY_REASON) || windowsGpuStackCookieFallbackActive,
|
||||
alreadyGpuDisabled:
|
||||
Boolean(REMOTE_DISPLAY_REASON) ||
|
||||
windowsGpuStackCookieFallbackActive ||
|
||||
alreadyHasDisableGpu(process.argv, process.env),
|
||||
relaunchAttempted: windowsGpuStackCookieRelaunchAttempted,
|
||||
gpuOverrideOff: isHermesDesktopGpuOverrideOff(process.env)
|
||||
}
|
||||
@@ -14707,6 +14715,7 @@ function createWindow() {
|
||||
if (shouldRelaunchForRendererStackCookieCrashLoop(stackCookieCrashLoop)) {
|
||||
windowsGpuStackCookieRelaunchAttempted = true
|
||||
windowsGpuStackCookieFallbackActive = true
|
||||
windowsGpuStackCookieFallbackSticky = true
|
||||
|
||||
try {
|
||||
writeGpuStackCookieMarker(
|
||||
@@ -14722,7 +14731,7 @@ function createWindow() {
|
||||
)
|
||||
|
||||
try {
|
||||
app.relaunch({ args: process.argv.slice(1) })
|
||||
app.relaunch({ args: buildDisableGpuRelaunchArgs(process.argv.slice(1)) })
|
||||
void exitAfterBackendShutdown(0)
|
||||
} catch (err) {
|
||||
rememberLog(`[renderer] GPU-disable relaunch failed: ${err?.message || err}`)
|
||||
|
||||
@@ -7,6 +7,8 @@ import { test } from 'vitest'
|
||||
|
||||
import { shouldRelaunchForRendererSandboxCrashLoop } from './windows-sandbox-fallback'
|
||||
import {
|
||||
alreadyHasDisableGpu,
|
||||
buildDisableGpuRelaunchArgs,
|
||||
decideWindowsGpuStackCookieLaunch,
|
||||
gpuStackCookieFallbackMarker,
|
||||
gpuStackCookieMarkerPath,
|
||||
@@ -172,6 +174,58 @@ test('decideWindowsGpuStackCookieLaunch enables sticky fallback, re-probes on ve
|
||||
assert.equal(legacy.enable, true)
|
||||
})
|
||||
|
||||
test('alreadyHasDisableGpu honors argv and HERMES_DESKTOP_DISABLE_GPU', () => {
|
||||
assert.equal(alreadyHasDisableGpu(['--foo', '--disable-gpu'], {}), true)
|
||||
assert.equal(alreadyHasDisableGpu([], { HERMES_DESKTOP_DISABLE_GPU: '1' }), true)
|
||||
assert.equal(alreadyHasDisableGpu([], { HERMES_DESKTOP_DISABLE_GPU: 'true' }), true)
|
||||
assert.equal(alreadyHasDisableGpu(['--disable-gpu-compositing'], {}), false)
|
||||
assert.equal(alreadyHasDisableGpu(['--no-sandbox'], {}), false)
|
||||
})
|
||||
|
||||
test('buildDisableGpuRelaunchArgs appends a single GPU-off pair', () => {
|
||||
assert.deepEqual(buildDisableGpuRelaunchArgs(['--foo', '--disable-gpu', 'hermes://x']), [
|
||||
'--foo',
|
||||
'hermes://x',
|
||||
'--disable-gpu',
|
||||
'--disable-gpu-compositing'
|
||||
])
|
||||
})
|
||||
|
||||
test('decideWindowsGpuStackCookieLaunch honors argv --disable-gpu even without a marker', () => {
|
||||
const viaArgs = decideWindowsGpuStackCookieLaunch({
|
||||
platform: 'win32',
|
||||
argv: ['--disable-gpu'],
|
||||
env: {},
|
||||
marker: null,
|
||||
appVersion: '1.2.3'
|
||||
})
|
||||
|
||||
assert.equal(viaArgs.enable, true)
|
||||
assert.equal(viaArgs.reason, 'already-enabled')
|
||||
assert.deepEqual(viaArgs.nextMarker, { state: 'booting' })
|
||||
|
||||
const viaArgsKeepsSticky = decideWindowsGpuStackCookieLaunch({
|
||||
platform: 'win32',
|
||||
argv: ['--disable-gpu'],
|
||||
env: {},
|
||||
marker: { state: 'fallback', reason: 'renderer-crash-loop', version: '1.2.3' },
|
||||
appVersion: '1.2.3'
|
||||
})
|
||||
|
||||
assert.equal(viaArgsKeepsSticky.enable, true)
|
||||
assert.equal(viaArgsKeepsSticky.nextMarker.state, 'fallback')
|
||||
|
||||
const overrideOffBeatsArgv = decideWindowsGpuStackCookieLaunch({
|
||||
platform: 'win32',
|
||||
argv: ['--disable-gpu'],
|
||||
env: { HERMES_DESKTOP_DISABLE_GPU: '0' },
|
||||
marker: { state: 'fallback', reason: 'renderer-crash-loop', version: '1.2.3' },
|
||||
appVersion: '1.2.3'
|
||||
})
|
||||
|
||||
assert.equal(overrideOffBeatsArgv.enable, false)
|
||||
})
|
||||
|
||||
test('CONTROL: sandbox relaunch stays false for 0xC0000409 (do not piggyback --no-sandbox)', () => {
|
||||
assert.equal(
|
||||
shouldRelaunchForRendererSandboxCrashLoop({
|
||||
|
||||
@@ -32,7 +32,10 @@ export const WINDOWS_GPU_STACK_COOKIE_MARKER_FILENAME = 'windows-gpu-stack-cooki
|
||||
/** STATUS_STACK_BUFFER_OVERRUN as a signed Win32 exit code (WER / Chromium). */
|
||||
export const WINDOWS_STACK_COOKIE_EXIT = -1073740791
|
||||
|
||||
const GPU_OVERRIDE_ON = new Set(['1', 'true', 'yes', 'on'])
|
||||
const GPU_OVERRIDE_OFF = new Set(['0', 'false', 'no', 'off'])
|
||||
const DISABLE_GPU_SWITCH = '--disable-gpu'
|
||||
const DISABLE_GPU_COMPOSITING_SWITCH = '--disable-gpu-compositing'
|
||||
|
||||
export type GpuStackCookieMarkerState = 'booting' | 'fallback' | 'ok'
|
||||
|
||||
@@ -86,6 +89,35 @@ export function isHermesDesktopGpuOverrideOff(env: NodeJS.ProcessEnv = process.e
|
||||
return GPU_OVERRIDE_OFF.has(override)
|
||||
}
|
||||
|
||||
/**
|
||||
* True when this process already launched with GPU off — Chromium argv
|
||||
* (`--disable-gpu`) or HERMES_DESKTOP_DISABLE_GPU on. Mirrors
|
||||
* `alreadyHasNoSandbox`: the crash-loop relaunch MUST pass these switches so
|
||||
* the next process is protected even if the sticky marker write failed.
|
||||
*/
|
||||
export function alreadyHasDisableGpu(argv: readonly string[] = [], env: NodeJS.ProcessEnv = process.env): boolean {
|
||||
if (Array.isArray(argv) && argv.some(arg => arg === DISABLE_GPU_SWITCH)) {
|
||||
return true
|
||||
}
|
||||
|
||||
const override = String(env.HERMES_DESKTOP_DISABLE_GPU || '')
|
||||
.trim()
|
||||
.toLowerCase()
|
||||
|
||||
return GPU_OVERRIDE_ON.has(override)
|
||||
}
|
||||
|
||||
/** Relaunch argv with a single `--disable-gpu` + compositing switch. */
|
||||
export function buildDisableGpuRelaunchArgs(argv: readonly string[]): string[] {
|
||||
const args = (Array.isArray(argv) ? argv : []).filter(
|
||||
arg => arg !== DISABLE_GPU_SWITCH && arg !== DISABLE_GPU_COMPOSITING_SWITCH
|
||||
)
|
||||
|
||||
args.push(DISABLE_GPU_SWITCH, DISABLE_GPU_COMPOSITING_SWITCH)
|
||||
|
||||
return args
|
||||
}
|
||||
|
||||
export function parseGpuStackCookieMarker(raw: unknown): GpuStackCookieMarker | null {
|
||||
if (!raw || typeof raw !== 'object') {
|
||||
return null
|
||||
@@ -231,18 +263,23 @@ export function shouldSurfaceErrorForRendererStackCookieCrashLoop(
|
||||
* - `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).
|
||||
* - `--disable-gpu` already in argv (crash-loop relaunch / Chromium switch)
|
||||
* is honored even if the sticky marker write failed, but is NOT made sticky
|
||||
* from argv alone.
|
||||
* - `HERMES_DESKTOP_DISABLE_GPU` explicitly off (`0`/`false`/`no`/`off`)
|
||||
* fail-opens: do not disable GPU.
|
||||
*/
|
||||
export function decideWindowsGpuStackCookieLaunch(
|
||||
options: {
|
||||
platform?: NodeJS.Platform | string
|
||||
argv?: readonly string[]
|
||||
env?: NodeJS.ProcessEnv
|
||||
marker?: GpuStackCookieMarker | null
|
||||
appVersion?: string
|
||||
} = {}
|
||||
): GpuStackCookieLaunchDecision {
|
||||
const appVersion = String(options.appVersion || '')
|
||||
const argv = options.argv ?? process.argv
|
||||
const env = options.env ?? process.env
|
||||
const marker = options.marker ?? null
|
||||
|
||||
@@ -256,6 +293,15 @@ export function decideWindowsGpuStackCookieLaunch(
|
||||
return { enable: false, reason: null, nextMarker }
|
||||
}
|
||||
|
||||
// Honor an in-process `--disable-gpu` relaunch (or env override) even when
|
||||
// the sticky marker write failed. Not made sticky from argv alone — the
|
||||
// marker lifecycle stays unchanged, matching sandbox's already-enabled path.
|
||||
if (alreadyHasDisableGpu(argv, env)) {
|
||||
const nextMarker: GpuStackCookieMarker = marker?.state === 'fallback' ? marker : { state: 'booting' }
|
||||
|
||||
return { enable: true, reason: 'already-enabled', nextMarker }
|
||||
}
|
||||
|
||||
if (marker?.state === 'fallback') {
|
||||
if (marker.version && appVersion && marker.version !== appVersion) {
|
||||
return {
|
||||
|
||||
Reference in new issue
Block a user