Skip to content

fix(desktop): cap consecutive renderer crash reloads - #2600

Closed
koeria wants to merge 1 commit into
vastsa:mainfrom
koeria:fix/cap-renderer-crash-recovery
Closed

koeria wants to merge 1 commit into
vastsa:mainfrom
koeria:fix/cap-renderer-crash-recovery

Conversation

@koeria

@koeria koeria commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

Summary / 概要

Renderer crash recovery now stops after 5 consecutive reloads that never survive the 30s recovery window, instead of reloading every 2s forever.

On some Windows + NVIDIA setups the renderer crashes at startup (renderer-process-gone, STATUS_BREAKPOINT), so recoverRendererAfterGone reloaded the hidden window every cooldown interval indefinitely — users saw the app stuck on a black launch screen, and the host logged 10,000+ renderer crashes per day (see issue diagnostics comment).

A renderer that stays up past the recovery window resets the counter, so normal transient-crash recovery is unchanged.

fixes #2595

Requirement link / 需求关联

  • Linked requirement issue / 已关联对应的需求 Issue:fixes #2595
  • Issue explains the background and the expected outcome / Issue 已说明需求背景和期望效果
  • UI changes carry a fitting reference / N/A — main-process recovery logic only
  • UI changes include before / after screenshots / N/A

… recovery loop

A renderer that crashes on every startup (e.g. GPU-related
STATUS_BREAKPOINT on some Windows NVIDIA setups) was reloaded every
cooldown interval forever, burning thousands of crash events per day
while the never-shown window left the app stuck at launch.

Stop automatic recovery after 5 consecutive reloads that never survive
the 30s recovery window; a renderer that stays up past the window
resets the counter so normal recovery behavior is unchanged.

@aiuo-codepilot aiuo-codepilot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AIUO CodePilot · Preliminary review

Diff-only preliminary review of renderer crash-recovery cap and its tests. The main-process logic correctly limits consecutive reloads and resets after a healthy window; one test ordering issue is reported below. Verification is limited to the supplied diff and test text: no repository access, execution, or runtime checks were performed.

  • medium apps/desktop/test/renderer\-recovery\.test\.mjs:120: The test asserts `i < 5` for the return value of `recoverRendererAfterGone` on every iteration, but each `recovery()` call constructs a fresh dependencies object with its own reload callback; the module-level `consecutiveReloads` counter is what enforces the cap, and the assertion assumes reload count increments before the cap check. After the fifth successful reload the sixth call returns false, so `assert.equal(..., i < 5)` holds only if the counter increments exactly once per attempt including attempts skipped by the cooldown delay. Because `mock.timers.tick(2_100)` occurs after the assertion and the cooldown branch schedules rather than performs reloads immediately, this assertion ties correctness to timing details not visible in the diff; if `elapsed < CRASH_COOLDOWN_MS` defers the reload while still incrementing `consecutiveReloads`, the returned value and the intended recovered count may diverge from the test's expectation.
    Evidence: assert\.equal\(recoverRendererAfterGone\(details, attempt\.dependencies\), i &lt; 5\);

Head: 1dc6271
Base: 720bbe1
CI: pending; mergeable: true.

Validation: code/tests NOT EXECUTED. Diff-only preliminary analysis; not approval. Human review and repository gates remain required.

@SeanLiu326

Copy link
Copy Markdown
Contributor

Heads-up: I independently filed #2597 against the same issue (#2595) — the two overlap and combine cleanly.

Your cap (5 reloads, 30s recovery window, counter reset) and the breaker in #2597 are the same idea; #2597 then adds what happens after the cap trips, which is the part the #2595 reporter is still blocked on: a first-trip relaunch with --disable-gpu (userData marker-guarded, so it can only happen once per fallback cycle), a boot-time disableHardwareAcceleration() for manual launches while the marker is set, and a localized dialog (9 locales) offering the log folder or quit once the fallback is spent. A cap alone stops the 2s flashing but leaves that user on a black screen with a working-looking app that never opens.

Also FYI: your CI failure is not your change — packages/agent-runtime/src/system-proxy-relay.test.ts hit a real-socket flake (HTTPParserError: Response does not match the HTTP/1.1 protocol from undici), same class as the codemode/tool.test.ts:138 flake that hit #2597's first run yesterday. An empty commit retrigger clears it.

Happy to land this either way: I can rebase #2597's escalation on top of your cap (your reset heuristic is nice and self-contained — no did-finish-load wiring needed, unlike mine), or fold your cap into #2597 with your authorship preserved, maintainer's choice. If #2600 merges first I'll rebase immediately.

@koeria

koeria commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the heads-up, and good catch on the CI flake — agreed it's the undici real-socket flake, unrelated to the cap change.

On coordination: no preference on our side, maintainer's choice. Both options work for me — if #2597 lands first I'll rebase #2600 on top; if #2600 merges first, folding the escalation in with authorship preserved sounds right. The cap is intentionally self-contained (no did-finish-load wiring), so it should compose cleanly with the marker-guarded --disable-gpu fallback either way.

@vastsa

vastsa commented Nov 27, 2026

Copy link
Copy Markdown
Owner

Thanks for coordinating with #2597. I checked the #2595 report against current main: the reload has a cooldown but no stop condition. The recovery suite passed 7/7 on this head. The cap addresses the repeated reloads, but after the last reload still leaves the startup window hidden if did-finish-load never fires. Retrying from the tray or by restarting is not a recovery path for the reported persistent failure, so this should not land on its own as fixes #2595.

I suggest keeping one breaker and carrying the bounded reload behavior into #2597 with your authorship preserved, as discussed. Please count actual reloads in the cap regression (instead of incrementing the test's own counter) and distinguish a renderer that stayed healthy from time after the breaker already stopped it. I left the fallback-path acceptance criteria on #2597.

@koeria

koeria commented Nov 28, 2026

Copy link
Copy Markdown
Contributor Author

Per vastsa's direction, carried the bounded-reload behavior into #2597 rather than landing it here. Commit 1bb54efa on koeria/PI-Desktop:carry-2600-into-2597 (rebased onto #2597's head) contains:

  1. Uptime-based re-arm (fix(desktop): cap consecutive renderer crash reloads #2600's recovery window) — recovery resets only after a full 30s stretch without a renderer crash. Time passing while the breaker is tripped never counts: the crashes keep arriving, so no window is ever "healthy". This complements noteRendererLoaded() instead of replacing it, so a missed did-finish-load wiring can't strand the breaker.
  2. Latch restarts with the streak — a genuine healthy window also clears crashLoopReported, so a later full crash loop can trip again; the GPU-fallback marker in handleRendererCrashLoop dedupes the relaunch itself, so re-tripping stays bounded.
  3. Cap regression test per vastsa's criteria — counts actual reloads via the reload spy (not a test-local counter), and asserts both halves: 30 crash cycles after the trip produce zero additional reloads, while a real 31s healthy window followed by a crash resumes recovery.

Renderer recovery suite passes 10/10 locally (node --experimental-strip-types --test test/renderer-recovery.test.mjs). I don't have push access to SeanLiu326/PI-Desktop, so this branch is there for cherry-picking into #2597.

With the bounded behavior carried over and the single-breaker decision made, closing this PR as superseded by #2597.

@koeria koeria closed this Nov 28, 2026
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] 莫名不能正常打开,卡死在启动位置。

3 participants