Repository navigation
[0.0.28] fix(runtime): retry failed GPU presents and capture surface evidence (#2570) - #2588
Conversation
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 41 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
27bb9a0 to
f7a4f15
Compare
NEEDS-FIX update at
|
Xuepoo
left a comment
There was a problem hiding this comment.
INDEPENDENT REVIEW (guard-tick, agent: guard-review-2588) - head 5bc4d3e
Static review of the full diff (gh pr diff), issue #2570, follow-up #2589, and the touched files in context. No workspace build was run; CI at this head is green, including MSRV 1.85 check, Linux Wayland, Linux X11, Windows, macOS.
Findings
-
[MAJOR - blocking]
crates/bitty-runtime/src/runtime/present.rs:2183-2191- the new backoff early-return can turn the retry into an event-loop wake storm, via a deadline this gate stops servicing. The gate returns beforedefer_coalesced_present(present.rs:1553) andcollect_tick_basis, which are the only placescoalesced_pending/coalesced_deadlineare cleared (mark_frame_presented,present.rs:1431; idle path,present.rs:2544).defer_coalesced_presentreturnsfalseatpresent.rs:1575(now >= open_at) without clearing the flag, andpresent_coalescing_deadline()(present.rs:1524-1529) returns the raw deadline. Sequence: a dirty tick defers (flag set, deadlineopen_at), the next tick atopen_atreaches the present, the present fails -> retry armed 50 ms ->AboutToWaitcomputesmin(...)overcoalesced(already past) andsurface_retry(terminal_app.rs:4425-4446) ->set_wait_until(past)-> winit re-enters immediately -> gate returnsNone-> same past wake, forever, because nothing in the gated region clears the flag. Result is 100% CPU for as long as presents keep failing (and it repeats every cycle), i.e. exactly the "spin, not a present" your own sync-update gate already documents and defends against atpresent.rs:2344-2353. The cheap gated iterations make it worse than before, when each loop turn at least attempted an expensive present. The retry deadline itself is correct (see below) - it is the sibling deadlines that are left stale. Suggested fix: in the gate, before returningNone, re-point the coalesced wake at the retry deadline (mirroringpresent.rs:2347-2353), or havepresent_coalescing_deadline()clamp withmax(deadline, now), or clearcoalesced_pendingthere (safe:pending_full_redrawalready forces the retry frame).pending_backoff_does_not_tick_stormdoes not cover this - it counts present attempts, not wakes. Add a test asserting the app's wake-min is never<= nowwhile a backoff is pending. -
[LOW]
present.rs:5769-5774- the comment (and the PR description) says the old CPU fallback "consumed the frame's damage". It could not:Surface::headless_presenthard-errors on a real surface (gpu.rs:1789-1794,"headless_present called on a real surface"), so the pre-PR failure path already landed inreturn Nonewith damage retained. What this PR actually fixes is the unbounded per-tick present retry plus the silence. Worth rewording, because the current text will mislead the next person debugging #2570 into looking for a damage-consumption bug that does not exist. -
[LOW]
crates/bitty-render/src/telemetry.rs:240-243+present.rs:2157-retry_armed()bumpsRETRY_FAILURES, and it is also called from the wrapper re-arm on a no-frame tick (no present attempted). Soretry_failuresin the crash/exit/watchdog reports counts backoff arms, not failed presents, contradicting its own doc (telemetry.rs:432-433). For a PR whose deliverable is evidence, split the counter (arms vs. present failures) or relabel it in the report. -
[LOW]
present.rs:5509-5523-note_surface_present_failureruns afterarm_surface_retry(present.rs:5775-5776), sofailuresis already incremented andnext_delayis computed asdelay(failures + 1)- one step beyond the deadline that was actually armed. Every loggednext_delayis wrong by one doubling. Compute the delay once in the caller and pass it in. -
[LOW]
crates/bitty-terminal/src/crash_report.rs:294-300- thread rows (up toMAX_THREAD_ROWS = 64) are written before the backtrace, so on a thread-heavy run the 8 KiB budget is consumed by thread rows and the backtrace - the most valuable panic evidence - is whattruncate()drops first. Emit the backtrace before the rows, or reserve a fixed slice for it. -
[LOW]
crash_report.rs:476-484-remove_file+create_newmeans two concurrent Bitty instances silently lose the report (AlreadyExists), and the error is discarded. For a P0 whose evidence may be collected while the owner is dogfooding with other instances open, a pid-suffixed fallback slot would be safer. -
[LOW]
crates/bitty-render/src/gpu.rs:1283-1313,1601-1635- the real acquire-retry paths (Outdated/Lost reconfigure + re-acquire, plus the new counters) have no coverage; the runtime seam substitutesheadless_presentfor a successful present (present.rs:5781-5795), sopresent_draw_list'sOk/Errbranches are never executed. Understandable without an adapter in CI, but say so in the PR body instead of leaving "tests cover the retry path" to imply the GPU path. -
[LOW]
crates/bitty-terminal/src/tests.rs:1119-1136- the AboutToWait test installstest_surface_retry_deadline(terminal_app.rs:985-991), which returns beforeRuntime::surface_retry_deadline()is consulted. It cannot fail if the runtime never arms a deadline or arms one in the past. Drive it from a runtime that actually armed a retry. -
[NIT]
gpu.rs:1283-1313,1601-1635-OutdatedandLostare now byte-identical arms within each function: four copies of the same ~25 lines.Outdated | Lost =>(as before) or a small helper would be shorter and cannot drift. -
[NIT]
gpu.rs:1285,1603-self.configure(ctx, config.extent)?propagates a reconfigure failure withouttelemetry::present_err(), so that failure class appears only asconfigure_errand never as a present failure in the reports.
Verified clean
- Retry cannot spin on its own deadline. The
tick_atwrapper (present.rs:2146-2162) re-arms any past-due deadline when the tick produced no frame, andsurface_retry_delay(present.rs:30-36) has a 50 ms floor withsaturating_mul/min(1 s), so the deadline always moves forward and attempts are capped at one per deadline. The reasoning holds for every early return intick_at_inner(time gates, coalescing, idle, atlas reject). - Backoff and cap. 50 ms -> 1 s, doubling, saturating; no attempt-count cap, i.e. a permanently lost surface retries at 1 Hz forever. That is the right trade for workspace-return recovery, but it is undocumented as a give-up policy - worth one line in the module docs.
- Evidence capture is bounded and leak-free. 8 KiB crash / 1 KiB exit, truncation before and after scrubbing (
crash_report.rs:462-470),MAX_MESSAGE_CHARS,MAX_BACKTRACE_FRAMES, thread rows capped at 64,Filescoped (no leaked handle), atomicrename, mode 0600, stale temp unlinked and re-created withcreate_new(no symlink follow - regression test present), home redaction plus source-path stripping including Windows\separators. - No hardcoded host paths in production code; the state path is XDG -> HOME -> LOCALAPPDATA (
stall_watchdog.rs:1367-1385), and tests use/example/.... - MSRV 1.85 / no let-chains. None of the new code uses a let-chain (nested
if letthroughout, e.g.present.rs:2155-2159,2187-2191,5582-5586);const {}array repeat (1.79), let-else (1.65),PanicHookInfo(1.81) andu8::try_fromare all within 1.85, and theMSRV 1.85 checkjob passes at this head. - Residual P0 risk, correctly scoped.
get_current_texturestill runs on the winit main thread and the retry re-enters it once per <= 1 s; the driver-wait freeze the issue suspects is not removed here. That is honestly stated in the body and tracked in #2589 - keep it there.
VERDICT: NEEDS-FIX
…ale coalesced wake (#2570) Review PR #2588 (independent review 5635163222) MAJOR finding: the retry gate returns before `defer_coalesced_present`/`collect_tick_basis`, the only places that clear `coalesced_pending`. A frame deferred when the present failed therefore kept `present_coalescing_deadline()` in the past, and `AboutToWait` clamped `set_wait_until` at it every loop turn: a 100% CPU spin for as long as presents kept failing. `tick_at` now re-points a pending coalesced wake at the surface-retry deadline (`align_coalesced_wake_with_retry`), which is the only wake that can do useful work while the backoff holds presentation. New regression `backoff_never_leaves_a_past_due_coalesced_wake` asserts the wake minimum handed back to the event loop is never earlier than `now`; it fails (wake 1 ms in the past) with the re-point removed. Also from the same review: - LOW: the comment no longer claims the retired CPU fallback consumed the frame's damage. It could not: `headless_present` hard-errors on a real surface, so the old path already retained damage; the fix is the unbounded per-tick retry plus the silence. - LOW: `retry_failures` now counts real failed GPU presents only. The no-frame backoff re-arm reports through the new `telemetry::retry_rearmed`, which refreshes the armed delay and last event without counting a failure; the snapshot doc says so. - `note_surface_present_failure` logs the delay the caller actually armed instead of `delay(failures + 1)`, so every logged `next_delay` was one doubling step too long.
…ale coalesced wake (#2570) Review PR #2588 (independent review 5635163222) MAJOR finding: the retry gate returns before `defer_coalesced_present`/`collect_tick_basis`, the only places that clear `coalesced_pending`. A frame deferred when the present failed therefore kept `present_coalescing_deadline()` in the past, and `AboutToWait` clamped `set_wait_until` at it every loop turn: a 100% CPU spin for as long as presents kept failing. `tick_at` now re-points a pending coalesced wake at the surface-retry deadline (`align_coalesced_wake_with_retry`), which is the only wake that can do useful work while the backoff holds presentation. New regression `backoff_never_leaves_a_past_due_coalesced_wake` asserts the wake minimum handed back to the event loop is never earlier than `now`; it fails (wake 1 ms in the past) with the re-point removed. Also from the same review: - LOW: the comment no longer claims the retired CPU fallback consumed the frame's damage. It could not: `headless_present` hard-errors on a real surface, so the old path already retained damage; the fix is the unbounded per-tick retry plus the silence. - LOW: `retry_failures` now counts real failed GPU presents only. The no-frame backoff re-arm reports through the new `telemetry::retry_rearmed`, which refreshes the armed delay and last event without counting a failure; the snapshot doc says so. - `note_surface_present_failure` logs the delay the caller actually armed instead of `delay(failures + 1)`, so every logged `next_delay` was one doubling step too long.
30935fb to
f552d82
Compare
Guard note (cron tick, agent: bitty-guard-cron, ~12:15 CST): red is MAIN-origin, not this PRForensics on the current The same single failure reproduces on
Fix is in flight in the ctx-1487 lane ( |
Priority: P0 | Area: stability/platform | Labels: bug, P0, area:stability, area:platform | Milestone: v0.0.28 | Task: CTX-1482
Refs #2570. This PR does not close the issue: the Hyprland freeze/termination was not reproduced in isolation (environment blocker documented below). It removes a silent surface-failure dead end and adds bounded evidence capture for the next occurrence.
Review NEEDS-FIX disposition (head ee9f13f)
Independent review 5635163222 raised one MAJOR (spin) and LOW polish items.
MAJOR (wake spin): the retry gate returned before
defer_coalesced_present/collect_tick_basis, the only places that clearcoalesced_pending, so a deferral pending when a present failed left a past-duepresent_coalescing_deadline()andAboutToWaitclampedset_wait_untilat it every loop turn — a 100% CPU spin while presents kept failing.tick_atnow re-points a pending coalesced wake at the surface-retry deadline (align_coalesced_wake_with_retry); nothing can present before that deadline anyway, so it is the only wake that can do work. New regressionbackoff_never_leaves_a_past_due_coalesced_wakeasserts the wake minimum handed back to the event loop is never earlier thannow; with the re-point removed it fails with a wake 1 ms in the past. It asserts wakes, not the present-attempt counter (that counter was already capped by the old code).LOW (damage claim): the comment no longer says the retired CPU fallback consumed the frame's damage. It could not —
headless_presenthard-errors on a real surface, so the old failure path already retained damage and retried once per tick. What this PR fixes is the unbounded per-tick retry plus the silence. The root-cause paragraph below is corrected the same way.LOW (
retry_failuressemantics): the counter now means real failed GPU presents only. The no-frame backoff re-arm goes through the newtelemetry::retry_rearmed, which refreshes the armed delay and last event without counting a failure; the snapshot docs say so.LOW (log delay, found while fixing the above):
note_surface_present_failureloggeddelay(failures + 1)because the counter was already incremented. It now logs the delay the caller actually armed, so the reportednext_delaymatches the deadline.Deferred, not fixed here: crash-report section order vs the 8 KiB budget (5), concurrent-instance report collision (6), the duplicated
Outdated/Lostarms and missingpresent_erronconfigurefailure (9, 10), and strengtheningabout_to_wait_arms_the_surface_retry_deadlineto drive a runtime that actually armed a retry (8). The real acquire-retry branches ingpu.rsstill have no coverage: the runtime seam substitutesheadless_presentfor a successful present, so only the failure/backoff/clear path is exercised without an adapter (7).B1 (regression coverage): added
runtime::present::surface_retry_testswith a test-only present-failure seam. It forces the real-GPU route and injects failures without an adapter. Tests cover repeated failures retaining damage and re-arming, the backoff gate (no attempt/tick storm before the deadline), recovery clearing state and presenting the retained frame, the past-due re-arm guard, and the bounded log policy. Addedabout_to_wait_arms_the_surface_retry_deadlinein the cold-delivery feature suite. Each fails if the retry gate/arm/clear logic is removed.1 (backoff gate):
tick_at_innernow returns before frame rebuild andpresent_assembled_framegates the present call while the deadline is in the future; damage andpending_full_redrawstay retained, then one retry runs at the deadline.2 (dead lifecycle): removed
Lifecycle::SurfaceRetry; retry failures, attempts, recoveries, and last delay now live inbitty_render::telemetryand appear in crash, exit, and stall-watchdog reports.3 (unbounded logs): replaced the per-second throttle with a total policy: first 8 failures individually, then every 60th, constants
GPU_PRESENT_LOG_BURST/GPU_PRESENT_LOG_EVERY, aggregate count in every line.4 (size cap):
write_slottruncates before and after secret scrubbing, so redaction growth cannot exceed 8 KiB / 1 KiB.5 (Windows state path): state resolution falls back to
%LOCALAPPDATA%after XDG/HOME, with a unit test.6 (temp symlink): the stale temp is unlinked, the new slot is opened with
create_new(no symlink follow), mode 0600 on Unix; symlink regression added.7 (comment): the
main.rscomment now states thatDisplayUnavailablerecords its exit reason before headless smoke, while normal--headlessnever installs.8 (docs): tracked docs follow-up [0.0.28] docs: document crash/exit diagnostics and BITTY_CRASH_REPORT #2593 (canonical crash/exit/watchdog diagnostics and
BITTY_CRASH_REPORT).Host evidence collected (read-only)
/usr/bin/bittyPID 1289315 was alive at 01:09 local with 19 threads, 63 fds, 73 MiB RSS, main thread parked indo_epoll_wait, and no matching Hyprland client inhyprctl clients. The process was gone by 01:28 with no core (coredumpctl list bittyonly has the two 0.0.25 entries), no journal entry, no OOM kill, and no exit-save.pixman_region32_union_rect: Invalid rectangle passedlines coincide withapp-ghostty-surface-transient-*scopes; at 22:52:36/46/48 theerror marshalling arguments for leave ... nulllines coincide withapp-org.chromium.Chromium-*launches. Temporal correlation attributes those compositor messages to Ghostty/Chromium, not Bitty; per-surface attribution is still unproven.systemd-oomdkill.Isolated reproduction attempt (blocked)
AQ_NO_KMS_REQUIREMENT=1aborts inCBackend::create(); the nested Wayland backend starts but its headless outputs fail GBM allocation (bo null) on this NVIDIA-only host, so a real headless output cannot be used.WAYLAND-1output was used instead: the built 0.0.27 binary ran with a real wgpu/Vulkan surface, survived 120 workspace switch-away/back cycles, and exited cleanly onCloseRequested. That exercises map/unmap and surface lifecycle, but the nested host window could not stay visible without covering the owner's desktop, so frame pacing while hidden was not representative.Root-cause analysis and change
The audit found a concrete silent dead end in the real-GPU present path:
Runtime::present_assembled_frameused to catch every GPU present error and run an invisible CPUheadless_present. That fallback could never composite a real surface (headless_presenthard-errors on one), so the damage was retained but the retry was unbounded — once per tick — and silent: no stderr, no counter, no backoff. A failed acquire/present after a workspace return could therefore leave the window stale while burning the loop, with nothing to diagnose it by.get_current_texture()still runs on the winit main thread; driver waits there (thedrm_syncobj_array_wait_timeoutobservation from [0.0.27] Bitty freezes and terminates by itself after <=15 minutes #2525) remain the strongest freeze suspect. This PR does not move presentation to a render thread; it makes the failure recoverable and observable.Changes:
bitty-render::telemetry— allocation-free, process-wide surface counters (configure/acquire/present/resize outcomes, last event).Runtime— on a real-GPU present failure: keep the damage, setpending_full_redraw, log a rate-limited warning, and arm a bounded exponential retry (50 ms → 1 s) thatAboutToWaitincludes in its wake selection. A retry tick that produces no frame pushes the deadline out instead of spinning. The invisible CPU fallback is removed.crash_report(new, default-on,BITTY_CRASH_REPORT=0opts out) — bounded 8 KiB panic report under$XDG_STATE_HOME/bitty/crash-report.logwith phase, lifecycle counters, surface counters, thread rows, and a path-redacted backtrace; a 1 KiBexit-report.logrecords every clean exit reason. Mode0600, atomic replace, no host paths.stall_watchdog— its report now carries the surface counters and last lifecycle event; phase marks feed the crash context even when the watchdog is disabled.Verification
cargo nextest run -p bitty-terminal -p bitty-runtime -p bitty-render --lib --bins --locked→ 2757 passed.cargo nextest run -p bitty-terminal --features input-vm-test-support -E 'test(input_vm_boundary)'→ 15 passed (includes the AboutToWait wake test).cargo nextest run -p bitty-runtime --test runtime_soft_present -p bitty-render --test wgpu_surface --locked→ 6 passed.New regression
headless_surface_survives_120_resize_present_cycles(120 reconfigure + present cycles).cargo fmt --all -- --checkandcargo clippy -p bitty-render -p bitty-runtime -p bitty-terminal --all-targets --locked -- -D warningsclean.Real-process check on the nested compositor: clean close wrote
exit-report.log(282 bytes, mode 0600) withreason=event-loop-returned phase=shutdown ... acquire_ok=2 present_ok=2 resize=4; a temporary panic probe wrote a 3358-byte report with no checkout/home path in it (probe removed before the final commit).Review-fix verification (head ee9f13f):
just fmt-checkclean;cargo clippy -p bitty-runtime -p bitty-render --all-targets --locked -- -D warningsclean;cargo +1.85 check -p bitty-runtime/-p bitty-render/-p bitty-terminal--offline --all-targetsclean (no let-chains);cargo nextest run -p bitty-runtime --lib→ 1269 passed,-p bitty-render --lib→ 325 passed, including the new spin regression.just ci-localwas not run locally because another agent'sactjob is active; remote CI is the acceptance gate. Targeted gates above match the task scope.Residual risk and follow-up
SIGTERM/SIGHUP) is still uncaptured:#![forbid(unsafe_code)]blocks an async-signal-safe handler and no safe signal crate is in the dependency graph.