Skip to content

fix(render): keep visible unconfirmed surfaces retrying from truth (bitty#3262) - #3265

Merged
Xuepoo merged 1 commit into
mainfrom
ctx-1907/integrate-present-truth
Nov 19, 2026
Merged

Xuepoo merged 1 commit into
mainfrom
ctx-1907/integrate-present-truth

Conversation

@Xuepoo

@Xuepoo Xuepoo commented Nov 19, 2026

Copy link
Copy Markdown
Contributor

Closes #3262

What this fixes

agy leaving its Swarm view with Esc left the pane showing stale rows: bitty ctl terminal text t:1 returned the complete correct grid while the screen held an older frame, and only a window resize or a layout edit repainted it. The grid was right and the paint path was wrong. This PR integrates the finished CTX-1905 implementation (written in its lane but never committed) onto current origin/main and reconciles it against #3258, which landed after the author's base and touches the same content-layer area.

F1 — a visible surface parked for good

After three unconfirmed presents (#2989's fast budget) with the visibility gate open, the runtime submitted no frame, armed no deadline, and queued no redraw. The fast budget exists so a broken compositor cannot turn the window into a periodic frame source, but "an open gate" is permission to attempt a present, not evidence that a surface is or is not being sampled — so parking on that evidence loses the screen for good.

  • An open, non-speculative gate now keeps a PRESENT_INCARNATION_REPAIR_INTERVAL (5 s) deadline that queues at most one same-extent Configure plus one full repaint rebuilt from truth per interval.
  • An applied Configure (the worker's own success counter, read in poll_presenter) resets the fast miss budget. The request that queued it does not: queue_configure can be replaced or fail, so a queued request is not proof of a new surface incarnation.
  • A hidden surface still parks — a slow Configure never reopens a closed gate. The speculative reopen and the bounded blind probe from render: a present that never reaches the compositor leaves a stale frame and nothing retries it #2989/fix(runtime,render,platform): resolve Hyprland workspace switch frame freeze and reduce font heap footprint #3116 are unchanged.
  • A served compositor callback clears both timers. Configure replaces the swapchain configuration; it does not reset winit's FrameCallbackState::Requested, so only the callback settles the episode.
  • New telemetry present_repair_attempts / _configured / _failed is surfaced in crash_report and stall_watchdog, so a support report can separate "the Configure never applied" from "it applied and the compositor still did not sample".

F2 — same-origin retained leaf reuse

The retained-reuse gate compared origin, scroll offset, fade factor and atlas epochs but not the content extent, and the dx == 0 && dy == 0 shortcut returned before the extent comparison. An interpolated or animated extent at an unchanged origin therefore re-served the stored primitive list of the old size.

F3 — no-draw paths consumed damage

The empty-layout guard and the final DrawList guard published the frame and advanced the primary/pane presented generation even when the composite carried no primitives while the grid held text. The damage was then marked presented and never repainted.

  • finish_without_draw() keeps pending_full_redraw (and clears a spent coalescing wake) whenever a live grid row, or a scrolled viewport, still holds visible text; a blank frame still settles to idle.
  • A grid deliberately displaced by a presented GUI content layer is exempt: the layer owns that content rect and its release already invalidates the frame, so retrying the hidden text would repaint forever.

Reconciliation against #3258 (feat(runtime): choose and change a presented panel's presentation mode)

#3258 changes none of these eight files textually, but it changes the semantics of the content layer, so the overlaps were reconciled by hand rather than trusted to a clean git apply:

  • present.rs, build_leaf_primitives — upstream 228f484c's content_hidden gate is kept and the new F2 content-extent check sits in the same reuse predicate. Neither replaces the other: content_hidden disables reuse entirely for a displaced leaf, the extent check catches a size change on a leaf that is not displaced.
  • present.rs, finish_without_draw — reads content_layer_presented() per view, so the tiled/floating excursions [CTX-1902] feat(runtime): choose and change a presented panel's presentation mode (bitty#2388) #3258 adds stay exempt from the F3 text retry. [CTX-1902] feat(runtime): choose and change a presented panel's presentation mode (bitty#2388) #3258 also drops the retained leaf record and arms a full redraw on a presentation-mode change (set_panel_content_presentation), and its release path sets pending_full_redraw (restore_released_panel_presentation); the F2 extent check backs that up for a pure geometry move the mode verb never sees. When content_layer_presented() answers false on a borrow conflict, the leaf is treated as visible text and a repaint is scheduled — the direction that cannot leave a stale screen.
  • resize.rs — 228f484c/e4415e5e's content and PTY geometry freeze is untouched (primary_content_frozen, content_geometry_freezes, the TIOCGWINSZ gate, the release restore). The CTX-1905 hunk changes only the surface Configure budget: with an off-thread presenter, a resize request no longer resets the fast miss budget, because a queued Configure proves nothing about the new incarnation; the applied-Configure counter does.
  • runtime.rs — both constructors keep the upstream field set and gain present_incarnation_repair_after / presenter_configurations, plus the reset on a surface incarnation change.

Discrimination

The four regressions were run against 83fda62f itself in a scratch archive with a separate target dir, with only the test bodies applied (the F1 telemetry assertions dropped, since those fields do not exist pre-fix):

regression pre-fix result
present_confirm_park_reconfigures_a_visible_surface (F1) FAILED — "visible surface parked with neither an in-flight repair nor a deadline"
retained_reuse_requires_content_size_at_the_same_origin (F2) FAILED — retained (694, 430) vs expected (693, 430)
no_draw_does_not_consume_primary_text (F3) FAILED — presented generation 12, expected 0
no_draw_does_not_consume_pane_text (F3) FAILED — pane generation 10, expected 1

The adjacent pre-existing rows (blank_no_draw_settles_to_idle, no_draw_does_not_retry_text_displaced_by_panel_content) pass in the same archive, so the four failures are the defect and not a broken copy. All four pass after the fix.

Gates actually run

From the worktree, CARGO_TARGET_DIR=.targets/ctx-1907:

gate result
rustfmt +stable --edition 2024 --check on the 8 changed files clean (8/8)
cargo clippy -p bitty-runtime -p bitty-render -p bitty-terminal --all-targets --offline -- -D warnings exit 0
cargo test -p bitty-runtime --lib --offline 1704 passed, 0 failed
cargo test -p bitty-runtime --offline present 223 passed
cargo test -p bitty-runtime --test runtime_present --offline 16 passed
panel_content_presentation / panel_content_presentation_modes 19 / 8 passed
panel_unbind_release / blank_frame_3032 / panel_resize_drag_frame_2789 8 / 12 / 2 passed
cargo +1.85 check -p bitty-runtime --tests --offline exit 0 (no let-chains, no if let match guards)
RUSTFLAGS=-D warnings cargo check -p bitty-runtime --tests --target x86_64-pc-windows-gnu --offline exit 0
RUSTDOCFLAGS=-D warnings cargo doc -p bitty-runtime --no-deps exit 0

just ci-local was not run: github.com over HTTPS is unreachable from this host, so act cannot clone its Nix action. That leg is skipped for connectivity — not reported green.

Evidence boundary

What is proven: headless, deterministic regressions for the three defects; a visible surface retrying from truth across multiple 5 s intervals with exactly one Configure and one text-bearing repaint each; a hidden surface not reconfiguring; a confirmation stopping the retry; and pixel parity between incremental and forced-full-redraw frames in the alt-screen-exit, synchronized-update, scroll and row-update cases.

What is not proven:

  • The reporter's exact agy Swarm escape bytes were never captured, and the installed 0.0.45 logs show first misses but no second or third — nothing here establishes that the reporter's incident spent the fast budget. This fixes a generic present-park defect, not that application sequence.
  • The fake backend verifies Configure and retry, not that a real compositor samples the new buffer or resumes its callback stream. A Configure is not a compositor callback and does not reset winit's callback state. An explicit-sync or compositor stall remains a separate possibility; the unconfirmed-present, repair-outcome and acquire counters are what distinguish them, without logging terminal content.
  • The stale display during the original incident, and the real compositor's behaviour under a wedged callback path, remain unverified on this host. just ci-local was skipped for connectivity as noted above.

No canonical public compatibility claims are changed.

…om truth (bitty#3262)

Integrates the CTX-1905 implementation (finished in its lane but never
committed) onto origin/main 83fda62, reconciled against #3258.

F1 - a visible surface parked for good. After three unconfirmed presents
(#2989's fast budget) with the visibility gate open, the runtime submitted no
frame, armed no deadline, and queued no redraw, so nothing ever forced a
retry: the pane kept an older frame while Terminal Truth moved on. An open,
non-speculative gate now keeps a PRESENT_INCARNATION_REPAIR_INTERVAL (5 s)
deadline that queues at most one same-extent Configure plus one full repaint
rebuilt from truth per interval. The applied Configure (worker counter read in
poll_presenter) resets the fast miss budget, not the request that queued it; a
hidden or speculative surface still parks and keeps #2989/#3116's bounded blind
probe; a served compositor callback clears both timers. New telemetry
(present_repair_attempts/_configured/_failed) is surfaced in crash_report and
stall_watchdog so a support report can tell "configure never applied" from
"applied and still not sampled".

F2 - same-origin retained leaf reuse. The reuse gate compared origin, scroll,
fade and atlas epochs but not the content extent, and the dx==0 && dy==0
shortcut returned before the extent check, so an interpolated or animated
extent at an unchanged origin re-served stored primitives for the old size.
Reuse now requires an equal content_size and the shortcut is gone: the only
translation reuse left is the bit-identical same-size shift #2573 introduced.

F3 - no-draw paths consumed damage. The empty-layout and final-DrawList guards
published the frame and advanced the primary/pane presented generation even
when the composite carried no primitives while the grid held text, so the
pending paint was marked presented and never repainted. finish_without_draw()
now keeps pending_full_redraw (and clears a spent coalescing wake) whenever a
live grid row, or a scrolled viewport, still holds visible text; a blank frame
still settles to idle. A grid deliberately displaced by a presented GUI content
layer is exempt - the layer owns that content rect and its release already
invalidates the frame.

Reconciliation with #3258 (choose and change a presented panel's presentation
mode), which landed after the author's base and touches the same content-layer
area:
- build_leaf_primitives keeps 228f484's content_hidden gate and the new F2
  content-extent check side by side.
- finish_without_draw reads content_layer_presented() per view, so the tiled
  and floating excursions #3258 adds stay exempt from the text retry. #3258
  already drops the retained leaf record and arms a full redraw on a mode
  change; the F2 extent check now also covers a pure geometry move the mode
  verb never sees.
- resize.rs keeps 228f484/e4415e5e's content and PTY geometry freeze untouched
  (primary_content_frozen, content_geometry_freezes, the winsize gate). The
  CTX-1905 hunk is limited to the surface Configure budget: with an off-thread
  presenter a resize request is no longer proof of a new surface incarnation,
  so the fast miss budget is reset only by an applied Configure.
- runtime.rs keeps both upstream constructor field sets and adds
  present_incarnation_repair_after/presenter_configurations to each, plus the
  incarnation reset.

Gates (worktree, CARGO_TARGET_DIR=.targets/ctx-1907):
- rustfmt +stable --edition 2024 --check on the 8 changed files: clean
- cargo clippy -p bitty-runtime -p bitty-render -p bitty-terminal
  --all-targets --offline -- -D warnings: exit 0
- cargo test -p bitty-runtime --lib --offline: 1704 passed
- cargo test -p bitty-runtime --offline present: 223 passed
- cargo test -p bitty-runtime --test runtime_present --offline: 16 passed
- adjacent upstream suites: panel_content_presentation 19 passed,
  panel_content_presentation_modes 8 passed, panel_unbind_release 8 passed,
  blank_frame_3032 12 passed, panel_resize_drag_frame_2789 2 passed
- cargo +1.85 check -p bitty-runtime --tests --offline: exit 0
- RUSTFLAGS=-D warnings cargo check -p bitty-runtime --tests
  --target x86_64-pc-windows-gnu --offline: exit 0
- RUSTDOCFLAGS=-D warnings cargo doc -p bitty-runtime --no-deps: exit 0
- just ci-local: not run. github.com over HTTPS is unreachable from this host,
  so act cannot clone its Nix action; that leg was skipped for connectivity,
  not reported green.

Discrimination: the four regressions fail on 83fda62 itself in a scratch
archive with its own target dir (F1 "visible surface parked with neither an
in-flight repair nor a deadline"; F2 content extent (694,430) vs (693,430);
F3 primary generation 12 vs 0; F3 pane generation 10 vs 1), and pass here.
@Xuepoo Xuepoo added fix Bug fix P1 Priority: high area:render Area: rendering labels Nov 19, 2026
@Xuepoo Xuepoo added this to the v0.1.0 milestone Nov 19, 2026
@coderabbitai

coderabbitai Bot commented Nov 19, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You'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 44 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI (base), Organization UI (inherited)
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: d4a6d316-cc42-4553-b3a0-b12ce89d86c9
Commits

Reviewing files that changed from the base of the PR and between 83fda62 and dcc3668.

Files selected for processing: 8

  • crates/bitty-render/src/present.rs
  • crates/bitty-render/src/telemetry.rs
  • crates/bitty-runtime/src/runtime.rs
  • crates/bitty-runtime/src/runtime/present.rs
  • crates/bitty-runtime/src/runtime/resize.rs
  • crates/bitty-runtime/tests/runtime_present.rs
  • crates/bitty-terminal/src/crash_report.rs
  • crates/bitty-terminal/src/stall_watchdog.rs
  • 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.

Share

@Xuepoo Xuepoo left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Reviewed head dcc36688450333f69128a3f6857f006d9b1b7963 (single commit dcc36688 on top of 83fda62f, lane worktree clean, HEAD verified). Base 83fda62f is post-#3258, so the reconciliation is reviewed against the landed presentation-mode code rather than the author's original 2f6fae3d.

Evidence style: every pre-fix result below was reproduced by me in a scratch archive of 83fda62f (git archive, own CARGO_TARGET_DIR, separate from the lane) with only the PR's test bodies applied; the post-fix results are from dcc36688 itself.

1. Diff hygiene — PASS

  • gh pr diff 3265 --name-only returns exactly the 8 claimed files; git diff --stat 83fda62f dcc36688 = 8 files, +567/−123.
  • Every added line scanned for leftovers: no dbg!, no new println!, no TODO/FIXME/XXX, no absolute paths, IPs, ports, usernames, .unwrap(), unsafe, or std::env/config escapes. The single added eprintln! (crates/bitty-runtime/src/runtime/present.rs:2589-2593) is the pre-existing diagnostic lifted verbatim out of check_present_confirmation — same text at 83fda62f:crates/bitty-runtime/src/runtime/present.rs:2530; no new output surface.
  • The 5 s interval is a named constant (present.rs:124), not a magic literal at the use sites. git diff --check clean; rustfmt +stable --edition 2024 --check clean on all 8 changed files.

2. F1 discrimination — PASS

present_confirm_park_reconfigures_a_visible_surface (crates/bitty-runtime/src/runtime/present.rs:15623) drives the production path end to end: tick_at → check_present_confirmation (:2535) → check_unconfirmed_incarnation_repair (:2610) → real Presenter::repair_unconfirmed (crates/bitty-render/src/present.rs:1107) → worker configure (crates/bitty-render/src/present.rs:721-736), and asserts on the fake backend's own record (control.configured) plus pending_present / present_confirm_deadline. The Configure extents it pins are the live presenter.extent(), so the row cannot be satisfied by a resize.

Pre-fix (test bodies only, telemetry asserts dropped because those fields do not exist pre-fix): FAILED at the intended assertion — present.rs:15534: visible surface parked with neither an in-flight repair nor a deadline. That is the real defect: after the third fast miss the old code returned with nothing submitted, nothing armed and no deadline. Post-fix: ok. Not tautological — the container is the runtime, not a struct the test built.

3. F2 discrimination — PASS

retained_reuse_requires_content_size_at_the_same_origin (present.rs:9452) asserts on rt.presented_leaf_frames[&view].content_size, the record build_leaf_primitives itself writes (present.rs:4634-4654). Its only synthetic input is basis.paint_allocations, the production carrier for interpolated frames (present.rs:4051), not a test container.

Pre-fix: FAILED left: (694, 430) right: (693, 430) — exactly the implementer's claim. Post-fix: ok. The fix is the extent term at present.rs:4643 plus the removal of the dx == 0 && dy == 0 early return; the consumer's zero-delta branch at present.rs:4842 still takes the bit-identical same-size path, so #2573's translation reuse is preserved.

4. F3 discrimination — PASS

no_draw_does_not_consume_primary_text (:9473) and no_draw_does_not_consume_pane_text (:9551) call the production present_assembled_frame and read the production presented generations. Pre-fix: FAILED left: 12 right: 0 (primary) and left: 10 right: 1 (pane) — both as claimed. The pane row forces FrameLayers { any_needs_draw: true } to reach the final DrawList guard rather than the earlier shortcut, which is legitimate input to a production function.

Bonus: empty_layout_does_not_consume_primary_text (:9537) also fails pre-fix (12 vs 0), so the empty-layout arm is genuinely fixed and not only the two guards the body names.

Non-tautology control: in the same pre-fix archive the adjacent rows blank_no_draw_settles_to_idle (:9492) and no_draw_does_not_retry_text_displaced_by_panel_content (:9507) pass (2 passed / 5 failed), so the five failures are the defect, not a broken copy. All 8 rows pass on dcc36688.

5. Reconcile with #3258 (landed at the base) — PASS

  • build_leaf_primitives keeps upstream's content_hidden gate (present.rs:4579 and in the reuse predicate at :4634) and the new content-extent check (:4643); neither replaces the other.
  • finish_without_draw (present.rs:2141) exempts a grid displaced by a presented content layer (:2151), and the host borrow-conflict case (content_layer_presented answers false, crates/bitty-runtime/src/runtime/panel_content.rs:490) falls to "visible text → repaint", the direction that cannot leave a stale screen.
  • resize.rs: the 228f484c/e4415e5e content/PTY freeze is untouched (resize.rs:622, :624, :900; only two hunks in the whole file). The Configure-budget hunk (resize.rs:528-542) drops only present_confirm_at on the presenter path — the fast budget is now reset by the applied-Configure counter (crates/bitty-render/src/present.rs:734 → poll_presenter, present.rs:8227) — and resets both on the synchronous path, where the Configure is not off-thread.
  • runtime.rs: both constructors keep the upstream field set, 266 → 268 fields each, nothing dropped, only present_incarnation_repair_after / presenter_configurations added (runtime.rs:2554-2555, :2900-2901); shutdown_presenter (:3478) clears both (:3496-3499).

6. Boundedness — PASS

The repair wake is armed once when the fast budget is exhausted (present.rs:2562-2570), then only re-armed 5 s later inside check_unconfirmed_incarnation_repair (:2610-2650), so cost is at most one Configure plus one text-bearing repaint per interval, never one per miss; the fast budget itself still caps at 3 (present.rs:118).

It parks when hidden: present_confirm_deadline (:2445) exposes the slow wake only under surface_visible && !speculative_present_reopen, and the hide transition clears the confirmation whenever a repair is armed (:2823-2828), so a slow Configure can never reopen a closed gate. Pinned by an_occluded_surface_still_parks_after_the_repair_budget (:15589, asserts !present_owed(), !probe_full_redraw_armed(), no Configure recorded) — reproduced green here.

No unbounded redraw on a real occlusion: the speculative reopen still spends exactly one blind attempt and restore_hidden_after_blind_repair re-closes the gate.

7. Behavior preservation — PASS

Occluded surface still parks (row above). A no-draw frame with nothing damaged still settles (blank_no_draw_settles_to_idle). The released content layer still invalidates the frame and drops the retained leaf (crates/bitty-runtime/src/runtime/panel_content.rs:289-301, untouched by this PR). No new frame source when nothing is damaged: the repair timer only exists after a committed unconfirmed frame (present.rs:2556-2570), and note_present_confirmed clears it (:2470). Full cargo test -p bitty-runtime --lib on the head: 1704 passed, 0 failed.

8. Gates (independently run, not taken from the body) — PASS

  • cargo clippy -p bitty-runtime -p bitty-render -p bitty-terminal --all-targets --offline -- -D warnings → exit 0.
  • cargo test -p bitty-runtime --test runtime_present --offline → 16 passed, 0 failed, including the new damage_only_present_matches_full_redraw (crates/bitty-runtime/tests/runtime_present.rs:47).
  • cargo +1.85 check -p bitty-runtime --tests --offline → exit 0 (no let-chains / if let guards; MSRV holds).

9. PR body honesty — PASS

The body claims no compositor or winit verification: it says the fake backend proves Configure and the retry, not that a real compositor samples the new buffer or resets its callback stream, and it states plainly that just ci-local was skipped for connectivity rather than reported green. The residual about the reporter's exact agy escape bytes is still there ("never captured ... This fixes a generic present-park defect, not that application sequence"). The "pixel parity" claim maps to a headless test, which is what it says.

Residual findings:

  • finish_without_draw (present.rs:2141-2175) keeps pending_full_redraw for any text-bearing grid the composite cannot paint. For a persistent zero-extent window (the "all zero rects" case the old comment named) or a persistently empty layout, the embedder's nudge caps at 500 ms (crates/bitty-terminal/src/terminal_app.rs:119), so the result is a ≤2 Hz full-frame build that never presents instead of the old settle-to-idle. Rate-bounded and self-healing, but there is no give-up and no test pins it.
  • The flip side of check 6: while the visibility gate reads visible, a surface the compositor never confirms gets one Configure plus one full repaint every 5 s indefinitely. That is the deliberate trade, but there is no give-up counter, so a false-positive visibility signal on a genuinely occluded surface is a permanent 0.2 Hz rebuild.
  • check_unconfirmed_incarnation_repair re-arms the 5 s timer before the !presenter.is_active() return (present.rs:2610-2630), so a presenter that stays inactive leaves a 5 s wake with no frame scheduled forever.
  • The unconfirmed-present diagnostic now prints to stderr once per 5 s for as long as a surface stays unconfirmed (previously three lines then silence) — support logs get noisier on exactly the surfaces this change targets.
  • present_unconfirmed now counts every expired deadline, including the expiry that only arms the slow repair, not only forced corrective repaints (crates/bitty-render/src/telemetry.rs:410-413). The doc comment was updated, but triage habits that read that counter as "repaints forced" will shift.
  • The F1 row hardcodes Duration::from_secs(5) (present.rs:15651) instead of referencing PRESENT_INCARNATION_REPAIR_INTERVAL; a constant change would fail loudly rather than pass silently, so this is duplication only.
  • Same-extent Configure as a repair is still only proven against the fake backend. If wgpu treats an identical-extent reconfigure as a no-op on a wedged swapchain the slow cadence will keep rebuilding without healing; the new counters separate that case from "the Configure never applied", which is the right support story, but it remains unproven on a real compositor.

VERDICT: APPROVE

@Xuepoo
Xuepoo merged commit 733eb7c into main Nov 19, 2026
21 checks passed
@Xuepoo
Xuepoo deleted the ctx-1907/integrate-present-truth branch November 19, 2026 20:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:render Area: rendering fix Bug fix P1 Priority: high

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[0.1.0] render: stale rows survive an alternate-screen exit; only a forced full redraw repaints the pane

1 participant