Repository navigation
[CTX-1746] fix(render): never present an empty leaf when the pane grid holds text (bitty#3032) - #3043
Conversation
…d holds text (bitty#3032) Closes #3032
|
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 10 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. |
|
Independent review (
|
Xuepoo
left a comment
There was a problem hiding this comment.
Independent guard review (reviewer is not the implementer). Reviewed at head 17a2866f (merge of main; the merge only touched .github/workflows/release.yml + AUR scripts, so the crate content equals 3beb98bf). I compiled and ran the new tests in a separate worktree, including a temporary revert of the production hunks to main's versions (restored afterwards; worktree is clean).
1. Production path actually prevents the empty frame — PASS
Traced the call site end to end, not just the new helper:
crates/bitty-terminal/src/terminal_app.rs:4990— every real input event (is_input_visibility_proof,:310) callsreveal_surface_from_input().crates/bitty-terminal/src/terminal_app.rs:1486— the guard now readsis_surface_visible() && !surface_reveal_unproven(), so an already-open gate keeps going;set_surface_gate(true, "input")(:1453) routes toRuntime::set_surface_visibility(present.rs:2245) →set_surface_visibility_at(:2594), whose redundant-reveal branch callsqueue_reveal_repaint(:2691), which armspending_full_redraw, settlesspeculative_present_reopen, and clears the confirmation bound.- Ordering is correct: the #2989 repair sets the flag after the visibility call (
present.rs:2435-2436), so the reopen is not immediately cleared again. - Empty leaves can no longer be retained or reused:
present.rs:4334(epoch/fillsgate),:4342(leaf.glyphs.is_empty()+ viewport text proof → fresh render),:4985-4988(refuses to store, drops the entry, armspending_full_redraw). - The predicate is computed from the snapshot being rendered (
:4782), not from the draw list, so it cannot ratify its own output.
The real mechanism, stated plainly: an all-empty composite returns None at present.rs:8338 while still calling mark_frame_presented (:8339), so the generation advances and the pane stays blank forever — that is the reported defect. The fix converts it into "nothing presented, damage re-armed, retry next tick". That is a heal-and-retry, not a hard block: the empty leaf is still composed into built for that tick (:5003, :5005). Acceptable against the issue's acceptance wording ("paints the grid or fails visibly and retries"), and I verified the retry is real (pending_full_redraw → retained_present_work → present_owed).
2. Regression tests discriminate — FAIL
Measured, not inferred. With crates/bitty-runtime/src/runtime/{present,panes,resize}.rs and runtime.rs reverted to main (69aa4a7c, verified the new helper and color_atlas_epoch are absent from the compiled tree):
cargo test -p bitty-runtime --test blank_frame_3032→ 11 passed, 0 failed — identical to the fixed tree (11/11 pass both ways). Re-confirmed individually forretained_leaf_rebuilds_when_sibling_pane_grows_the_glyph_atlas,coalesced_deferral_preserves_full_redraw_across_alt_latch,captured_agy_help_transcript_never_presents_an_empty_frame.- So none of the 11 tests pins the atlas-epoch validation, the
damage_evictedsentinel, thepending_full_redrawpersistence, or the empty-leaf guard they are named for.
Good news: this is not the same-container tautology — the assertions are on PresentStats and on headless_rgba() ink (blank_frame_3032.rs:35-44), independent of the guard's inputs, and the "from-truth" compare (:332) really does force a full redraw (set_surface_visibility_at(now, true) → queue_reveal_repaint). The suite fails to discriminate because its preconditions are unverified: nothing asserts the atlas epoch actually advanced with evictions unchanged (:311-320), that a retained leaf existed before the incremental tick, or that pending_full_redraw survived the deferral. A fixture that never enters the guarded branch cannot pin it.
The one test that does discriminate is in the app crate: input_proof_during_a_speculative_reopen_queues_a_from_truth_frame — passes with the fix, and with only the guard reverted to is_surface_visible() alone it fails at crates/bitty-terminal/src/tests.rs:1228 ("input proof must queue a from-truth frame with the gate open"). It runs in CI via the input_vm_boundary filter (ci.yml:387), so the feature gating is fine.
3. No let-chains — PASS
No added line mixes && with let (every if let in the diff is a standalone statement, e.g. present.rs:4166, blank_frame_3032.rs:314). Workspace is edition = "2024", rust-version = "1.85" (Cargo.toml:32-33), where let-chains are E0658. RUSTFLAGS=-Dwarnings cargo check -p bitty-runtime --tests compiles clean.
4. No new dead_code behind cfg arms — PASS
RUSTFLAGS=-Dwarnings cargo check -p bitty-runtime --tests and -p bitty-terminal --tests both clean; RUSTDOCFLAGS=-Dwarnings clean. In the new test file the #[cfg(unix)] attribute is mirrored exactly where needed — the View/ViewId import (:15-16) and both PTY tests (:250, :291) carry it, so a Windows build sees no unused import and no orphan helper. All new runtime functions are platform-neutral. I could not execute the Windows/macOS legs locally; this is static + Linux -Dwarnings evidence only.
5. No hardcoded host values, no new dependency edge — PASS
No Cargo.toml/Cargo.lock in the diff. The only literal paths are /bin/sh inside #[cfg(unix)] PTY tests, and the layout constants 100*9+44 / 32*19+44 (blank_frame_3032.rs:121-122) which are font-metric assumptions, immediately guarded by assert_eq!(rt.snapshot().width, 100).
6. No private intra-doc links — PASS
RUSTDOCFLAGS="-D warnings" cargo doc -p bitty-runtime -p bitty-terminal --no-deps succeeds. The new public item Runtime::surface_reveal_unproven (present.rs:2711) has a doc comment with no intra-doc links; the added PresentedLeaf fields are pub(super) inside a pub(super) struct.
7. Scope and gates — PASS (with a note)
All 7 files are in the present/reveal path; no unrelated refactor, no removed assertion, and the changed gates get stricter (:5181 now also requires epochs unchanged; :3612 clears retained frames before the rebuild-limit check instead of only on the counted path). Note: the diff is ~1k lines across four defect families (input reveal, atlas epochs, damage sentinel, redraw persistence) for one symptom. They are cohesive with the issue, but bundling them cost this PR its test discrimination, as #2 shows.
Requests
- Make the runtime regression tests fail on pre-fix code (blocking). At minimum: in
retained_leaf_rebuilds_when_sibling_pane_grows_the_glyph_atlasassert the fixture's own precondition —renderer.atlas_epoch()advanced andatlas_stats().2did not — before comparing RGBA, so a fixture that never bumps the atlas fails loudly instead of passing vacuously. Same shape forcoalesced_deferral_preserves_full_redraw_across_alt_latch(pending_full_redrawobserved after the deferred tick) andcaptured_agy_help_transcript_never_presents_an_empty_frame(assert at least one frame actually took the retained-reuse path). If a test genuinely cannot be made to fail on69aa4a7c, say so in its comment and name what pins the behavior instead. - Bound the empty-leaf retry (non-blocking, but I would fix it here).
present.rs:4985-4987armspending_full_redrawevery time a text-bearing leaf renders empty, with no counter, backoff, or log;present_owed()then drives a full-frame render every tick for as long as the lesion persists (broken shaping, missing font coverage). On the 9,421-line pane from the report that is a sustained full redraw at cadence. Give it theATLAS_REBUILD_LIMITtreatment plus one log/stats line, so the issue's "fails visibly" half is actually satisfied. - Nit:
live_retained_heap_shape_still_paints_after_alt_switch(blank_frame_3032.rs:178) takes 62 s and ~93 MB per run — more than the other ten tests combined. Consider#[ignore]-gating the 9,421-line replay or shrinking it to the smallest ring that reproduces the shape.
VERDICT: CHANGES-REQUESTED
…nd the empty-leaf retry - Never retain a leaf list that rendered empty, and bound the rebuild it owes (EMPTY_LEAF_RETRY_LIMIT, per leaf, one rate-limited stderr line once the bound is exhausted). The previous unconditional `pending_full_redraw` was consumed by the same present, so it could neither heal the leaf nor storm. - Add read-only present probes plus a `#[cfg(test)]` empty-render seam, and in-crate tests that pin the refusal, the retry bound, and the deferred latch change surviving `defer_coalesced_present`. - Assert the fixtures' own preconditions in the runtime regressions (atlas epoch advanced without an eviction; the deferred tick still owes a full redraw; the transcript takes the retained-reuse path), and record per test whether it discriminates on the pre-fix tree, naming what pins the behaviour otherwise. - Replay 600 scrollback lines instead of 9,421 (60 s -> under 1 s), and add a pane-respawn reuse regression.
… and keep shaped_idle quiet
Independent review — APPROVEReviewed commit
Reviewer: |
|
Guard tick forensics (head
Not a flake: the three legs agree, and the shape matches the review's request 2 (an unbounded |
Independent review — APPROVEReviewed commit
|
There was a problem hiding this comment.
Independent guard review, round 2 (reviewer is not the implementer). Judged at head 64c8587e, against the demand in my round-1 review at 17a2866f. Everything below was compiled and executed on copies of the head tree under ~/.hermes/cache/scratch/rv/ (git archive exports, one CARGO_TARGET_DIR per variant, no shared warm dir). The lane worktree is untouched (git status --porcelain empty).
Round-1 asks
| # | Ask | State |
|---|---|---|
| 1 | Runtime regression tests must fail on pre-fix code | Resolved — see §2 |
| 2 | Bound the empty-leaf retry with a limit + log/stats line | Resolved for one leaf, with a measured gap under two — see §3 |
| 3 | The 62 s / 93 MB test | Resolved — 4.10 s / 82 MB — see §6 |
1. (a) Each prior item resolved, with the code that resolves it
- Discriminating tests exist.
runtime::present::empty_leaf_guard_tests::empty_render_is_never_retained_and_the_retry_paints(present.rs:9009) drives the guard through a#[cfg(test)]seam (maybe_inject_test_empty_leaf,present.rs:3648, armed byarm_test_empty_leaf,present.rs:13412) that clears a leaf's primitives immediately before the retained store decides, then asserts the refusal, the owed retry,present_owed(), the heal, and ink. - Defer persistence has its own pin.
runtime::present::coalesced_deferral_tests::deferred_latch_change_persists_the_full_redraw_request(present.rs:8959) desynchroniseskitty_alt_screens_latcheddirectly so the request comes fromcollect_tick_basisalone — the shape a PTY alt switch cannot produce — and assertspending_full_redrawsurvives the deferral. - Preconditions in the integration tests are now asserted instead of assumed:
probe_atlas_epochsattests/blank_frame_3032.rs:463and:489withepoch_after > epoch_before+evictions_after == evictions_before;probe_full_redraw_armedat:556; retained-reuse proof at:202(reused > 0) and:223(a paint-only frame must reuse:glyphs={}, emitted={}), usingreused_retained_leaf(:64) onPresentStatsrather than on the guard's own inputs. - The honest-labeling escape hatch was used. Every integration test now carries a
Pre-fix (69aa4a7c): passes …note naming what pins the behaviour instead (:76,:105,:130,:158,:246,:303,:318,:346,:398,:448,:535). That is exactly the alternative my round-1 ask allowed, and the file header states it once (:8-17).
Note on what "fails on pre-fix" can mean here: pre-fix has no arm_test_empty_leaf / note_empty_leaf_render / empty_leaf_retry_owed, so the new in-crate tests cannot even compile against 69aa4a7c. I therefore measured the meaningful property — reverting the behaviour while keeping the seam and the test — which is the only compilable form. Results in §2.
2. (b) Do the new assertions actually fail if the fix is reverted — PASS
Reverted tree (rv/rev, own CARGO_TARGET_DIR=target-rev), four independent behaviour reversals, each restored to main's shape while the probes/tests/seam were left intact:
- retained store (
present.rs:5096-5117) → main's unconditionalpresented_leaf_frames.insert(main:present.rs:4784); - deferred-tick persistence (
present.rs:4028-4037) → removed; - reuse gate (
present.rs:4414-4430) → main'sscroll_offset/fade_factor-only version; reject_stale_atlas_frame(present.rs:3685) → alwaysfalse.
cargo test -p bitty-runtime --lib -- empty_leaf_guard_tests coalesced_deferral_tests atlas_epoch_guard_tests:
empty_render_is_never_retained_and_the_retry_paints ... FAILED
panicked: "an empty list must never be stored for reuse"
deferred_latch_change_persists_the_full_redraw_request ... FAILED
panicked: "a deferred latch update must carry its full-redraw request to the next tick"
atlas_epoch_guard_tests: 4 of 5 FAILED (only epoch_consistent_frame_is_presented passes, as expected)
test result: FAILED. 6 passed; 2 failed
Head, same selection, same target-dir discipline: 3 passed; 0 failed (0.07 s).
So the two behaviours round 1 found unpinned now have tests that fail on revert and pass on head — not tautologies. The atlas frame-level guard is likewise pinned (4/5 fail when it is stubbed to false), which substantiates the claim in tests/blank_frame_3032.rs:448-455 that the epoch behaviour is pinned in-crate rather than by the RGBA comparison.
The app-level input_proof_during_a_speculative_reopen_queues_a_from_truth_frame still passes, run the way CI runs it (--features input-vm-test-support --bin bitty; crates/bitty-terminal/src/main.rs:1819 includes mod tests, so --lib finds nothing — that is not a regression, just where the test lives). Its discriminating power was measured in round 1 with the guard reverted; crates/bitty-terminal/{src/terminal_app.rs,src/tests.rs} are untouched by 17a2866f..64c8587e (git diff --stat lists only runtime.rs, present.rs, blank_frame_3032.rs), so that measurement still applies to this head.
3. (c) Empty-frame retry bound — PASS for one leaf, measured gap for two
Present and correct in the single-leaf case: EMPTY_LEAF_RETRY_LIMIT = ATLAS_REBUILD_LIMIT (present.rs:641), note_empty_leaf_render (:3615) arms at most that many times, then emits one rate-limited line (LogThrottle burst 1, runtime.rs:2375) and stops arming; the owed rebuild is folded into the next tick's pending_full (:3825-3829) and surfaced through present_owed() (:2272); the counter resets when the same leaf renders again (:5107-5110).
Two things I measured rather than inferred:
- The bound does not bound two leaves. The budget is a single
(Option<ViewId>, u8)slot (runtime.rs:1435), so a second leaf overwrites the first and each restarts at 1. With a probe test added to my copy (not to the PR) callingnote_empty_leaf_render(A)then(B)on ten consecutive frames:(Some(2), 1)andowed=trueon 10/10 frames. Any frame in which two text-bearing leaves render with emptyfillstherefore re-armspending_full_redrawevery tick forever, and the log never fires because the count never exceeds the limit — i.e. silently the exact sustained-redraw condition the bound was added to remove. The doc comment "The budget is per leaf: a different leaf rendering empty starts its own count" (:3613-3615) overstates it; so does the name ofempty_leaf_retry_is_bounded_and_per_leaf(:9066), which asserts the reset to a new leaf's count 1. AViewId-keyed small map, or "reset only when that leaf renders non-empty", closes it. - No false positives on legitimately empty leaves. A probe over four shapes (fresh idle runtime;
CSI 2Jcleared primary; alt screen entered and cleared; split with a never-written pane) leavesprobe_empty_leaf_retries()at(None, 0)andpending_full_redrawfalse, so the guard does not log or full-redraw normal empty panes. Good — that was my main worry about reusingfills.is_empty()as the trigger.
Neither finding is a regression against main (pre-fix re-armed on every empty leaf, every tick), which is why I am not blocking on them. Tracked as follow-up in §7.
4. (d) MSRV 1.85 — PASS, 64c8587e is behaviour-neutral
The let-chain if let Ok(fallback) = … && !fallback.glyphs.is_empty() is now a nested if (present.rs:4955-4980, #[allow(clippy::collapsible_if)] at :4954). The inner condition moved verbatim; when it is false the old form skipped the body and so does the new one — list is left untouched in both, no early exit, no reordering, no change to the .filter(…).ok_or(()).or_else(…) chain that produces fallback. No logic drift.
Hard evidence rather than reading: the 1.85 toolchain is installed here, and CARGO_TARGET_DIR=…/target-msrv RUSTFLAGS=-Dwarnings cargo +1.85 check -p bitty-runtime --tests finishes clean (1m00s) — that covers the integration test too, which is where is_none_or, the let … else in the seam, and the new probes live. cargo clippy -p bitty-runtime --tests -- -D warnings on 1.98.1 is also clean, so the #[allow] is the only clippy concession and nothing else in the new code warns.
5. (e) No empty-frame present path left unguarded — PASS
All four EAR/CTX-0797 style gates are in place and mutually reinforcing: the frame-level epoch check (present.rs:4997), the reuse-time epoch/fills gate (:4418-4421), the glyphs-empty-with-text gate (:4426-4429), and the store refusal (:5096), plus reject_stale_atlas_frame. The injection seam is #[cfg(test)] on both sides (:3647, :5095), so no production build can clear a leaf's primitives. The probe_* additions are read-only accessors (:8877-8919) — none of them feeds a rendering decision.
One documented narrowing, reported for the record, not as a defect: the retry only arms when fills.is_empty() (:5104-5106). A leaf that emits fills but no glyphs while text is on screen drops its retained entry and re-renders, but never arms a cross-frame rebuild and never logs. The comment at :5097-5102 justifies it (the synchronous shaped + unshaped full-grid pass at :4946-4993 already ran, so another full frame would repeat the same renderer work), and the injected-empty case does exercise the other branch, so I accept it — but it is the one shape where the issue's "fails visibly" half is not met.
6. (f) Test runtime — PASS
Head, cargo test -p bitty-runtime --test blank_frame_3032 -- --test-threads=1: 12 passed, 11.43 s total (17 s wall including cargo). The formerly 62 s / 93 MB test live_retained_heap_shape_still_paints_after_alt_switch is now 600 lines instead of 9,421 (tests/blank_frame_3032.rs:276) and runs in 4.10 s / 82 MB. The shrink is honest: the test never depended on ring size (the alt switch forces a full render), the doc block above it says so (:250-262) and records the manual reproduction for the live figure, and it still asserts the ring is retained (retained_heap_bytes() > 0, scrollback_len() >= 500). No #[ignore]ed coverage.
7. Asks
- Non-blocking, worth doing here: make the bound survive two leaves. The measurement in §3 (10/10 frames armed with
A/Balternating) means the mechanism misses its own stated goal whenever more than one leaf renders empty — the multi-pane case the issue was reported from. Either key the counter byViewId(small array/map, the leaf count is bounded) or reset a leaf's count only when that leaf renders non-empty. If you would rather keep it for a follow-up, please soften the doc (present.rs:3613-3615) and the test name (:9066) so the tree does not claim a bound it does not have. - Nit, remove before merge:
Runtime::probe_atlas_raw(present.rs:8890-8904) is dead scaffolding — doc comment literally/// TEMP probe.,pub(behind#[doc(hidden)]), and referenced nowhere in the tree (the other three probes are used). It returns internal atlas counters/dims for no test. - Follow-up issue (either way): the glyphless-with-fills shape in §5 emits no diagnostic; if a host font stack lacks bitmaps for a screen's codepoints the pane stays blank silently. One
LogThrottleline there would complete the "fails visibly" half.
Summary
Round 1's blocking demand is genuinely met: the two behaviours that were unpinned now have tests measured to fail on reversion and pass on head, the integration tests assert their own preconditions, and every non-discriminating test says so and names its pin. The MSRV commit is behaviour-neutral and verified on the 1.85 toolchain. The retry bound works for the reported single-pane shape and does not misfire on empty panes, but it is defeated by two leaves — a gap in new code, not a regression against main.
VERDICT: APPROVE
Priority: P1 | Area: render | Labels: bug,P1,area:render | Milestone: v0.1.0 | RFC: none | Task: CTX-1746
Closes #3032
Summary
Fixes blank-frame presentation and retained-leaf invalidation defects when a pane's grid holds visible text (
bitty#3032):bitty-terminal,bitty-runtime):surface_reveal_unproven()holds (speculative reopen or an overdue compositor confirmation bound), even whensurface_visibleis alreadytrue.speculative_present_reopeninqueue_reveal_repaintand keep non-expired confirmation bounds intact on normal input so settled frames stay frame-on-demand without dropping active confirmation timers.bitty-runtime):atlas_epochandcolor_atlas_epochonPresentedLeafandCombinedLeaves.reuse_delta,scroll_retained_shift,append_leaf_scene,build_leaf_primitives, and the 1x1 plan probe (Atlas::try_grow()advances the epoch without incrementingevictions).presented_leaf_framesandpresented_scene_frameson stale-atlas frame rejection and when attaching/respawning a pane shell for aViewId.bitty-runtime):origin_last > origin_gen(theu64::MAXsentinel on a newly attached pane session) asdamage_evicted = true.pending_full_redrawandpending_paint_redrawincollect_tick_basisbeforedefer_coalesced_presentcan dropTickBasisafter mutatingkitty_alt_screens_latchedor advancing animations.pending_full_redrawwhen an in-flight present is dropped by resize/shutdown or when a headless present or leaf render fails.bitty-runtime):PresentedLeaf(or scroll-shift result) when the leaf's viewport holds visible text; degrade shaping errors torender_with_bidirather than skipping the leaf.