Skip to content

fix(desktop): break renderer crash loops with a GPU-fallback relaunch - #2597

Closed
SeanLiu326 wants to merge 5 commits into
vastsa:mainfrom
SeanLiu326:fix/renderer-crash-loop-breaker
Closed

SeanLiu326 wants to merge 5 commits into
vastsa:mainfrom
SeanLiu326:fix/renderer-crash-loop-breaker

Conversation

@SeanLiu326

Copy link
Copy Markdown
Contributor

Fixes #2595

The failure

The reporter's machine (Win11, RTX 4060 Ti, 150% scaling) renderer-crashes deterministically at startup: did-finish-load never fires, so the show: false main window is never shown, and recoverRendererAfterGone reloads every 2 seconds — forever. The user sees a black screen, a flashing taskbar icon, and can only quit from the tray. Reinstalling does not help because the corrupt state (GPU driver/driver-cache interplay) lives outside the install directory.

The fix

Recovery gains a crash-loop breaker on top of the existing cooldown:

  • recoverRendererAfterGone counts consecutive crashes with no successful load in between (a new noteRendererLoaded() resets the streak from did-finish-load). After 5 consecutive crashes it stops reloading and fires onCrashLoopDetected exactly once; further crashes keep logging (rendererProcessGone diagnostics) but stay inert.
  • First trip: relaunch the app once with --disable-gpu — the standard mitigation for corrupt GPU state, and the one thing a stuck black-screen boot can still do for the user. Guarded by a userData/renderer-crash-loop.json marker so it can only ever happen once per fallback cycle.
  • If the loop survives the fallback: a localized error dialog (new rendererCrash strings in all nine locales) offers opening the log folder — where the crash diagnostics already land — or quitting.
  • Boot: reading a spent marker also calls app.disableHardwareAcceleration() before ready, so manual launches are safe too, not just the relaunch. A run that stays loaded clears the marker after ten stable minutes, so a machine whose driver was updated (or whose corruption was transient) returns to hardware acceleration on a later boot.

Scattered crashes over a long session never trip the breaker — the streak only counts crashes with zero successful loads in between, which is exactly the #2595 signature.

Verification

  • renderer-recovery.test.mjs: 8/8 — new tests cover the trip-once-then-inert behavior across 7 consecutive crashes, streak reset by noteRendererLoaded (6 crash/load cycles never trip), and clean exits never counting. On pre-fix source the suite cannot even import (noteRendererLoaded did not exist), so the tests pin the behavior.
  • pnpm typecheck (desktop) clean after rebuilding @pi-desktop/shared dist; biome lint clean (152 files); pnpm -C packages/i18n build clean with the new rendererCrash section typed into all nine satisfies EnglishCatalog catalogs.
  • Full desktop suite on Windows: 5442 tests / 5357 pass / 72 failures — byte-identical set to the pre-change baseline (all pre-existing platform classes: macOS notarization, ssh transport, path normalization).

A renderer that crashes deterministically at startup (GPU driver or
cache corruption, issue vastsa#2595) turned the automatic recovery into an
infinite loop: did-finish-load never fires, so the hidden main window
is never shown, and recoverRendererAfterGone reloads every 2s until
the user force-quits. A plain reinstall does not help because the
corrupt state lives in userData.

Recovery now counts consecutive crashes with no successful load in
between and stops reloading after five: the first trip relaunches the
app once with --disable-gpu (the classic mitigation for corrupt GPU
state), guarded by a userData marker so a loop that survives the
fallback surfaces a localized dialog instead of relaunching forever.
Boot reads the same marker to disable hardware acceleration for
manual launches too, and a run that stays loaded for ten minutes
clears it again. Successful loads reset the streak, so scattered
crashes over a long session never trip the breaker.

The dialog offers opening the log folder (where the rendererProcessGone
diagnostics already land) or quitting; strings are added to all nine
locales.
@SeanLiu326

Copy link
Copy Markdown
Contributor Author

Overlap note: #2600 (filed ~10h earlier) caps the same recovery loop at 5 reloads with a 30s recovery window — same breaker idea, self-contained reset heuristic (crash spacing instead of did-finish-load wiring). #2597's breaker is that cap plus the escalation the #2595 reporter still needs after it trips: one --disable-gpu relaunch (marker-guarded), boot-time hardware-acceleration disable while the marker is set, and a localized dialog once the fallback is spent — a cap alone leaves that machine on a black screen. I commented on #2600 proposing a combination; happy to rebase onto theirs if it lands first, or fold their cap in with authorship preserved — maintainer's choice. Cross-checked CI flake context there too (system-proxy-relay real-socket flake).

@vastsa

vastsa commented Nov 27, 2026

Copy link
Copy Markdown
Owner

I confirmed the unbounded reload in current main against the #2595 diagnostics. This head's renderer recovery suite passed 8/8. A bounded fallback with a visible failure path is the right direction, but the existing suite only tests the breaker callback, not what happens after it fires:

  • Every did-finish-load starts a timer that neither renderer failure nor window disposal cancels. In a fallback boot, an earlier load’s timer can clear the marker after the renderer has already crashed again, even while the terminal dialog is open. Tie one timer to the current fallback renderer, cancel it on crash/close/replacement, and clear the marker only after continuous healthy uptime.
  • writeGpuFallbackMarker (including the rewrite on read failure) can throw from the crash callback or the boot path. If the fallback attempt cannot be persisted, log the failure and show the terminal recovery dialog; do not silently lose the only exit path or relaunch without a working deduplication guard.

Please coordinate the single breaker with #2600, and add an isolated Electron/integration scenario proving one guarded relaunch, a second failing launch reaching the dialog, and a stable fallback clearing the marker. GPU acceleration is a reasonable mitigation to try, but the available diagnostics do not establish a GPU/cache root cause; please avoid presenting it as confirmed without a comparison on the affected Windows setup.

@vastsa

vastsa commented Nov 28, 2026

Copy link
Copy Markdown
Owner

Taken over in #2640, which keeps your commits and authorship. The follow-up commit addresses the review: the healthy-uptime timer is now owned by the current renderer and cancelled on crash/reload/close; a marker write failure goes to the dialog instead of an unguarded relaunch; the boot-time hardware acceleration check moved before ready (in index.ts it could run after ready and have no effect); quits go through the ordered shutdown. An Electron E2E now proves one guarded relaunch, the second failing launch reaching the dialog, and a stable boot clearing the marker. Closing this in favour of #2640 — thanks for the groundwork.

@vastsa vastsa closed this Nov 28, 2026
jiangchuanso pushed a commit to jiangchuanso/PI-Desktop that referenced this pull request Nov 28, 2026
Review of vastsa#2597 found that every did-finish-load started a marker-clearing
timer that no crash, close, or reload cancelled, so a fallback boot could
clear the marker while the renderer was crashing again. A marker write
failure also threw out of the crash callback, losing the only exit path,
and the boot-time hardware acceleration check ran in index.ts after the
async storage bootstrap, possibly after ready, where it has no effect.

A per-window controller now owns one healthy-uptime timer for the current
renderer and cancels it on crash, newer load, escalation, and close. A
failed marker write logs and shows the terminal dialog instead of
relaunching without a guard. Relaunch and dialog quits go through the
confirmed ordered shutdown instead of app.exit. The marker lives in
userData and is read in installation.ts, which runs before ready.

An Electron E2E forces renderer crashes on every load and proves one
guarded relaunch, a second failing launch reaching the dialog, and a
stable fallback boot clearing the marker. GPU state is not claimed as
the vastsa#2595 root cause.

Refs vastsa#2595
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] 莫名不能正常打开,卡死在启动位置。

2 participants