Repository navigation
[CTX-1669] fix(runtime): arm a bounded wake when damage is retained and no deadline exists - #2853
Conversation
…nd no deadline exists AboutToWait joins the app deadline array (hover/animation/bell/capture/ kitty/coalesced/timers/parked/shell-exit/selection/surface-retry/hidden repair) and answers set_wait() when all of them are None. A frame can still be owed at that point - a rejected stale-atlas frame keeps pending_full_redraw and arms no timer, and a plugin scene revision can advance after the tick presented - so the loop parked in ControlFlow::Wait with nothing to wake it. That is the reported 'unresponsive until I click' and the deterministic CI hang where a lost redraw left the arm empty. Runtime: present_owed() is the single retained-damage predicate (shared with hidden_retained_work) plus the plugin scene revision, false right after a committed present and always false while hidden (the occlusion gate's repair wake owns that). App: PresentNudge arms now + 50 ms when a frame is owed and no other deadline is armed, doubling to a 500 ms ceiling, never overriding or shortening an existing deadline, and clearing the instant the present drains. No watchdog timeout was widened; a stuck present still reaches the no-present detector. Refs #2830
|
No actionable comments were generated in the recent review.
|
| Layer / File(s) | Summary |
|---|---|
Detect owed presentation work crates/bitty-runtime/src/runtime/present.rs |
The runtime centralizes retained-work checks and adds present_owed for visible surfaces. Tests cover retained redraw work, idle frames, new output, and hidden-surface repair behavior. |
Schedule terminal wake nudges crates/bitty-terminal/src/terminal_app.rs, crates/bitty-terminal/src/tests.rs |
TerminalApp combines the runtime’s owed-work status with existing deadlines. When work is owed without another deadline, it schedules a checked wake with a 50 ms initial delay and a 500 ms cap. Tests cover backoff, reset, and deadline preservation. |
Estimated code review effort: 3 (Moderate) | ~20 minutes
Change: Bug fix
Sequence Diagram(s)
sequenceDiagram
participant EventLoop
participant TerminalApp
participant Runtime
EventLoop->>TerminalApp: AboutToWait
TerminalApp->>Runtime: Query present_owed
Runtime-->>TerminalApp: Return owed status
TerminalApp->>EventLoop: Set WaitUntil deadline
Possibly related issues
- [0.0.32] Bitty becomes unresponsive after long uptime #2830: The pull request fixes a lost-wakeup path that can leave owed presentation work idle, but the provided context does not establish that this path caused the reported long-uptime unresponsiveness.
Merge Risk: 
Minimal · up to 601a8
-
This change adds a bounded wake so a frame left owed with no other deadline is retried instead of waiting for external input. No concrete merge-blocking defect remains. The author notes the original long-uptime freeze was not reproduced and a long soak test is still open.
Pre-merge checks: 
5
-
Full details: Title check
-
Explanation
The title names the fix and its trigger: a bounded wake is armed when presentation damage is retained and no deadline exists. The changeset adds a PresentNudge that schedules a 50 ms to 500 ms bounded wake in AboutToWait when a frame is owed and no other deadline is armed, and adds present_owed() in the runtime. The title matches the main change. The ticket prefix and the conventional commit prefix are present and do not affect the assessment.
Full details: Docstring Coverage
-
Explanation
Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 7 functions across 2 files. (1 skipped: 1 too large.)
-
Finishing Touches
-
Generate docstrings
-
- Commit to this branch
- Create a new PR
Generate unit tests (beta)
-
- Commit to this branch
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
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.
Xuepoo
left a comment
There was a problem hiding this comment.
Guard verification (bitty-guard-cron tick, independent of the implementer)
Verified on head 601a8b4877cc0632ad1a94353bd9d0f015329cfe.
Scope matches the remaining in-scope item of bitty#2830 (PR #2834 already landed
instrumentation + soak + self-heal; the owner's issue comment pinned the
lost-redraw-with-empty-deadline-array mechanism):
Runtime::retained_present_work()becomes the single "damage retained"
definition;hidden_retained_work()now delegates to it instead of duplicating
the predicate, so the occlusion gate and the new nudge cannot drift apart.- New
Runtime::present_owed()isfalsewhile hidden (the repair wake owns that
state) andfalseafter a committed present, so an idle surface still arms
nothing — the PB-7 zero-periodic-wakeup posture is preserved by construction,
and there are two dedicated tests pinning it (an_idle_surface_owes_nothing_after_its_present,
a_hidden_surface_is_covered_by_the_repair_wake_not_the_nudge). PresentNudge::armnever overrides an existing deadline and never returns
now; it doubles 50 ms -> 500 ms and clears when the present drains, so a stuck
frame self-heals at 2 Hz instead of spinning or parking. Unrepresentable
now + delayfails closed to plainWait.- The
AboutToWaitarm is the only production wiring point, and the wiring test
asserts on recorded loop-control operations (noWaitwhen a frame is owed, a
future and bounded deadline when it is).
Test honesty spot-check: the runtime test builds the state through the real
reject_stale_atlas_frame path rather than a synthetic flag, and the child
reported the red proof (removing only the wiring fails
an owed frame must never be handed plain Wait).
CI on this exact SHA: 18/18 required checks pass — Quality gates (1)/(2), MSRV
1.85, Linux X11 (xvfb), Linux Wayland, both compat matrices, macOS ARM64, Windows,
Supply chain, CodeQL, CodeRabbit, extension pin drift, VM tier (PR), M1 and Compat
release aggregates. VM tier (main) / VM tier (nightly ARM64) are the usual
conditional skips. Note the X11 leg finished in 15m50s, i.e. the job that used to
hang for 18 minutes to the job timeout now completes.
Not a blocker but recorded: Refs #2830 is correct — the long-duration soak
campaign acceptance bullet stays open, and the original field freeze was never
reproduced, so this closes the lost-wakeup class rather than claiming a root
cause.
Merge decision: green required checks + this verification; merging as a P0 runtime
fix.
Symptom
After long uptime Bitty can go unresponsive with no CPU use and come back the moment the user clicks. The same shape is deterministic in CI:
winit_windowonLinux X11 (xvfb), run 41280906272, sat for 18 minutes inApp::runand was cancelled by the job timeout.Mechanism
TerminalApp::handle_event(PlatformEvent::AboutToWait) joins every deadline the app can arm into one array — hover, animation, bell/notification, overlay capture, kitty-local worker, coalesced present, plugin timers, parked command, shell-exit reap, selection autoscroll, surface retry, hidden-surface repair — and then:A frame can still be owed when that array is empty. Two reachable examples:
reject_stale_atlas_framedrops the assembled frame, setspending_full_redraw = trueand arms no timer (the intended rebuild happens on the "next tick" — which, under plainWait, never comes).deliver_runtime_events/pump_cold_commandsrun afterdrive_tick), leaving the attached scene newer than the frame on screen with nothing armed.The embedder then hands itself
ControlFlow::Waitwith retained damage: CPU-idle and frozen until unrelated input arrives — exactly the field report, and exactly the lost-redraw CI shape where the redraw request never comes back.Fix
Runtime (
crates/bitty-runtime/src/runtime/present.rs)retained_present_work()is now the single definition of "damage is retained" (pending_paint_redraw/coalesced_pending/pending_full_redraw/ per-origin generation mismatch).hidden_retained_work()is!surface_visible && retained_present_work(), so the occlusion gate and the new nudge cannot drift apart.pub fn present_owed(&self) -> bool=retained_present_work() || plugin_scene_owed(), with a deliberatefalsewhile hidden (thehidden_repair_deadlinewake from [0.0.32] fix(runtime): built-in hang watchdog and long-run accumulation fixes (part of #2830) #2834 owns that case) andfalseimmediately after a committed present (so an idle surface arms nothing and PB-7's zero-periodic-wakeup idle budget is preserved).App (
crates/bitty-terminal/src/terminal_app.rs)PresentNudge— a bounded, self-clearing nudge.arm(now, owed, wake):wakeuntouched whenever any other deadline is armed (never suppressed, shortened, or moved into the past);Nonewhen nothing is owed, so the arm still falls back toset_wait();now + 50 ms, doubling to a 500 ms ceiling while the same frame stays owed;now— a past-due deadline would re-enterAboutToWaitimmediately and spin a loop with nothing new to present; an unrepresentable deadline fails closed toWait.AboutToWaitarm after the tick and the cold pump, so it observes post-present state (self.present_owed()).No timeout was widened and no counter was repurposed: the nudge only guarantees another loop turn, so
presented_frames/present_stale_ms/trigger=no-presentstill name a genuinely stuck present instead of being masked. First attempt lands in 50 ms (≈3 frames at 60 Hz) and the worst case is 2 Hz, not the 0 ms spin the previous parked-command fix had to remove.Tests
New regression coverage:
bitty-runtimeatlas_epoch_guard_tests::a_rejected_frame_owes_a_present_and_arms_no_deadline— builds the real "damage retained, deadline array empty" state throughreject_stale_atlas_frameand assertspresent_owed()pluspresent_coalescing_deadline() == None,hidden_repair_deadline() == None,surface_retry_deadline() == None. This is the state that used to park the loop.bitty-runtimepresent_owed_tests— idle surface owes nothing after its present (PB-7 guard), new output owes before it is consumed and clears with the present, hidden work belongs to the repair wake not the nudge.bitty-terminalabout_to_wait_arms_a_bounded_present_nudge_when_a_frame_is_owed— drives the realAppHandler::handle_event(AboutToWait)against the recordingEventContextwith a frame owed and asserts the loop-control operation is a boundedWaitUntil, neverWait.bitty-terminalabout_to_wait_returns_to_wait_once_the_present_drainsandpresent_nudge_is_bounded_and_resets— self-clearing half, non-zero first attempt, monotone backoff to the cap, reset after draining, existing deadline wins.Red proof (wiring removed on purpose, everything else kept, same test binary):
With the wiring restored:
Full runs on this branch:
(That last one took the
DisplayUnavailablebranch — this host has no display server, so the live-window path is not exercised here; the bounded harness itself landed in #2843.)Gates:
No
Cargo.toml/Cargo.lockedge changed (no new dependency).What stays open on #2830
This closes the lost-wakeup mechanism for the product path, not the whole issue:
opencodepane). This is a coverage fix that makes the class unrecoverable-by-parking, not a proven root cause for every field report.opencode_soak, ~2 min on unoptimized runners, 240 s guard) and the daemonlongrun_hangevent-ring assertions. A genuine long-duration campaign (hours) is still not automated — this PR does not add one, so that acceptance bullet remains open.winit_windowtest-side bound (retry the redraw, re-arm a 50 ms wake, fail in 20 s) is fix(test): bound the winit window lifecycle test instead of hanging CI #2843, already merged; this PR is the product-side safety net that comment asked for.Per the above, this uses
Refs #2830.Refs #2830
Summary by CodeRabbit