Repository navigation
[CTX-1703] feat(render): paint kitty relative placements from the parent anchor (bitty#2875) - #2893
Conversation
…ent anchor (bitty#2875) Relative placements (`a=p` with `P=`/`Q=` plus `H=`/`V=`) were stored as terminal truth but never reached the screen: the pixel layer had no parent-anchor model and the bodiless `a=p` mirror skipped them. Presentation now records the parent's wire identity verbatim and derives the child rect at paint time from the parent's painted origin plus the cell offsets (`KittyImageLayer::placement_full_rect_resolved`). Scroll and parent death need no second bookkeeping: the parent rect is recomputed every frame, so the child follows a scroll, hides when the parent leaves the grid, and dies with the parent (delete cascade added to the rich layer so a re-place cannot resurrect a dropped child). Fail-closed: a missing parent, a virtual prototype (never in the placement deque), an unrepresentable offset, or a chain past `KITTY_PLACE_MAX_PARENT_DEPTH` paints nothing and never loops — a cycle is reachable on the wire because a re-put only needs its named parent to exist. z-order stays the child's own `z=`, so a negative-`z` child still composites below text. Addressed re-puts now replace in place (truth's `upsert` parity) instead of delete-then-add, so children of a re-put parent keep resolving and no duplicate blits stack. No per-frame allocation is added: the resolver reads the bounded placement deque and the paint path allocates exactly what it did before. Presentation still never mutates grid truth.
|
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 36 minutes. View limit details
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
…tive placement test The workspace quality gate runs clippy with -D warnings across --all-targets; the new assertion spelled a cell offset as 1 * 16, which trips clippy::identity_op. Value unchanged.
Xuepoo
left a comment
There was a problem hiding this comment.
Read-only review of ctx-2875/feat-relative-image-placement at 3f4989e (base origin/main ef09532). All claims below come from reading the tree and running the commands in this worktree; the PR body was not used as evidence.
1. Resolution math — PASS
KittyImageLayer::placement_full_rect_resolved (crates/bitty-rich/src/kitty_place.rs:2814-2850) walks while let Some((parent_image, parent_placement)) = ancestor.parent (2827), accumulates each link's wire H=/V= at 2834-2835 (dx_cells.checked_add(..parent_offset.0), dy_cells.checked_add(..parent_offset.1)), takes the absolute ancestor's painted rect at 2839 (placement_full_rect(ancestor, metrics, scrollback_now)), and adds the accumulated cell offsets in pixels at 2843-2844. Extent comes from the child, not the parent: 2847-2848 read placement.cols/placement.rows.
Rationale: the child rect is exactly parent_painted_rect.origin + Σ(H,V)·cell_metrics with the child's own span, recomputed per frame (nothing of the child's own anchor/base is consulted).
2. Cycle/overflow safety — PASS
Depth bound: KITTY_PLACE_MAX_PARENT_DEPTH: u8 = 8 (kitty_place.rs:331), enforced at 2828-2831 (if depth >= KITTY_PLACE_MAX_PARENT_DEPTH { return None }), counter advanced with depth.saturating_add(1) (2837). No wrapping/panicking arithmetic on the new path: checked_add/checked_mul at 2834-2835 and 2843-2844, i32::try_from(..).ok()? at 2845-2846, saturating_u32(..) at 2849; the reused ancestor rect is itself saturating (2785-2788). No unwrap/indexing/as-truncation in the resolver or in cascade_relative_orphans (2874-2893, whose loop strictly shrinks the deque).
Rationale: a wire-reachable cycle terminates at the 8th link and an unrepresentable offset returns None rather than saturating into a plausible wrong origin.
3. Fail-closed refusals — PASS
Three distinct None paths, no panic:
- missing parent / off-origin parent:
kitty_place.rs:2833(find_placement_for_origin(..)?, origin-scoped at2855-2864); - virtual prototype: never lives in
placements(it is invirtual_protos), so2855-2864misses it →2833returnsNone; truth also refuses it upstream (crates/bitty-term-state/src/state.rs:2334-2339); - depth/cycle and offset overflow:
2828-2830,2843-2846.
Off-grid resolved rect: the paint path clips atcrates/bitty-runtime/src/runtime/present.rs:6616-6622(viewport intersection →continue), reached after6606-6612.
Evidence in tests:kitty_place.rs:4215-4263(missing parent +H=i32::MAXoverflow),4265-4287(cycle), runtimekitty_images_present.rs:1140-1171(V=30 off-grid: placement count 2, blits 1, no blue pixels),1258-1279(cycle paints 0).
Rationale: every refusal is anOptionshort-circuit on the paint path; nothing panics and nothing paints.
4. Layering — PASS
Paint path present.rs:6575-6683: per-placement z order comes from placements_in_paint_order_for (kitty_place.rs:2564-2572, sort_by_key(|p| p.z)), and the blit layer is chosen at present.rs:6680 as ImagePaintLayer::from_z(placement.z) (crates/bitty-render/src/grid.rs:1871-1877: negative → BelowText, else AboveText). The z used is the child's own: pty.rs:1200 captures control.z_index, forwarded through kitty_images.rs:1899-1911 into display_relative_for_origin(.. z ..) (kitty_place.rs:2380-2394). Relative resolution never rewrites z.
Rationale: a relative child inherits no layer from its parent; z=-1 composites below text and z=0 above, and the runtime test relative_below_text_child_paints_under_glyphs (kitty_images_present.rs:1173-1212) carries a z=0 control run that covers the text completely (blue == area), so the below-text assertion is not satisfiable by an inert path.
5. Truth boundary — PASS
git diff --stat origin/main...HEAD touches only crates/bitty-rich/src/kitty_place.rs, crates/bitty-runtime/src/runtime/{kitty_images,present,pty}.rs, crates/bitty-runtime/tests/kitty_images_present.rs — nothing under crates/bitty-term-state. Presentation stores the parent's wire identity only: pub parent: Option<(u32, u32)> (kitty_place.rs:855) and pub parent_offset: (i32, i32) (858), doc at 849-857 stating the resolved anchor is deliberately not stored. pty.rs:1281-1291 only reads truth (kitty_placements().get(..)) to decide whether to mirror; kitty_place_stored_relative (kitty_images.rs:1831-1860) and push_placement (kitty_place.rs:2402-2476) mutate self.kitty_images only.
Rationale: truth stays the single writer of grid state (invariant 3); the presentation layer derives geometry from stored identity at paint time.
6. Test non-tautology — PASS (proved by reintroducing the old gate)
Temporarily restored the pre-change gate in pty.rs (&& !control.has_parent() on the bodiless_place condition that the PR deleted), then:
cargo test -p bitty-runtime --offline --test kitty_images_present → test result: FAILED. 33 passed; 6 failed (exit 101). The six failures are exactly the new relative-paint pins: relative_child_paints_at_parent_origin_plus_offsets (1018: "parent and child both place"), relative_child_follows_parent_through_a_scroll (1058), relative_child_disappears_when_its_parent_is_deleted (1116), relative_child_fully_off_grid_paints_nothing (1149), relative_below_text_child_paints_under_glyphs (1190), relative_parent_cycle_fails_closed_without_hanging (1271, a stale absolute parent still painted once). Reverted with git checkout -- crates/bitty-runtime/src/runtime/pty.rs; git status --short clean and the suite re-ran 39 passed; 0 failed.
Rationale: the pins fail when the feature is removed, and the one that still passes under the gate (relative_child_without_a_parent_paints_nothing, 1214-1256) is a truth-refusal pin with an absolute-control run, so it is legitimately gate-independent rather than tautological. The pixel assertions are colour bounding boxes on headless_rgba, not just counters.
7. Regression safety — PASS
cargo test -p bitty-rich --offline --lib kitty_place → 52 passed; 0 failed; 273 filtered out (exit 0).
cargo test -p bitty-runtime --offline --test kitty_images_present → 39 passed; 0 failed (exit 0).
Extra signal: full cargo test -p bitty-rich --offline --lib → 325 passed; 0 failed.
Rationale: the re-put-in-place change (no delete_by_wire before re-place) did not break the existing FIFO/quota/wire-identity pins.
8. Gate parity — PASS
cargo fmt --all -- --check → exit 0.
cargo clippy -p bitty-rich -p bitty-runtime --all-targets --offline -- -D warnings → exit 0, no warnings printed (Finished dev profile ... in 25.66s).
The previously failing clippy::identity_op class is gone: 3f4989e0 rewrites base.y + 1 * 16 to base.y + 16 at kitty_place.rs:4189, and the -D warnings all-targets run over both crates is clean.
Rationale: the exact gate command the CI uses on these crates passes on the final head.
9. MSRV 1.85 — PASS
cargo +1.85 check -p bitty-rich --offline → exit 0 (Finished dev profile ... in 8.77s). clippy.toml pins msrv = "1.85" and Cargo.toml:33 rust-version = "1.85". No let-chains were introduced: git diff origin/main...HEAD contains no && let / || let / if let ... && form; the new walk is a plain while let Some(..) = ancestor.parent (kitty_place.rs:2827) and the nested if let/if pair at 2443-2452 avoids the let-chain form.
Rationale: the crate compiles on the declared MSRV and the newer-1.88 syntax is absent.
10. Hygiene — PASS
Both commits carry the ticket: [CTX-1703] feat(render): paint kitty relative placements from the parent anchor (bitty#2875) and [CTX-1703] fix(render): drop the identity op clippy flags in the relative placement test. Comments/docs are English (only typographic —/→/× characters, consistent with the surrounding module docs). No host paths or usernames in the diff (grep for /home/, /mnt/, /Users/, fuyu, C:\ → no hits). No unrelated files: the five changed files are the feature, its wiring, and its tests. No public API removals: git diff shows zero removed pub fn/const/struct lines; placement_full_rect (kitty_place.rs:2766) and the existing placement_rect/display_for_origin_with_wire signatures are intact, and the additions are KITTY_PLACE_MAX_PARENT_DEPTH (331), display_relative_for_origin (2367), placement_full_rect_resolved (2814), kitty_place_stored_relative (kitty_images.rs:1831).
Rationale: the diff is in-scope, additive, and ticket-stamped.
Findings
Blocking: none.
Non-blocking:
kitty_wire_spans_for(crates/bitty-runtime/src/runtime/kitty_images.rs:1531-1567) still derives damage spans fromp.anchor_row/p.anchor_col, which a relative placement stores as the unused(0, 0)(kitty_place.rs:2422). It filters onp.wire_image, so a relative placement contributes a spurious damage span at row 0/col 0 in addition to truth's correct span (state.rs:2341-2342resolves the real anchor). Extra repaint only — no wrong pixels — but the helper's doc ("from the same anchor/scroll math the present layer paints with") is now inaccurate for relative entries. Follow-up, not a blocker.- Quota eviction (
kitty_place.rs:2462-2470) removes a placement without callingcascade_relative_orphans, so an evicted parent's child lingers (paints nothing) and could revive if the same wire identity is re-placed. Terminal truth has the same gap (placement.rs:605-624pops front without cascading), so presentation matches truth rather than diverging — documented as parity, worth a comment. - The depth bound of 8 diverges from truth, which records an arbitrarily deep chain (it resolves only one level per admission). A chain deeper than 8 is recorded by truth but paints nothing. Intentional fail-closed, currently only stated in the resolver doc — fine, but a client-visible limit worth a line in the PR description.
- Combined payload +
a=pis still unsupported (anya=pcontinues atpty.rs:1302-1306without pixel intake), so relative placement only works in the bodiless form. Pre-existing, unchanged by this PR, but the PR title reads broader than that. cascade_relative_orphansis O(n²) over the deque and now runs on everyremove_placement/delete_by_wire. Bounded by the placement caps, so acceptable; noted only for the record.
Not verified
- No real compositor/GPU render: all geometry evidence is headless (
headless_rgbapixel bounding boxes), not an on-screen frame. - Full-workspace clippy/test (
cargo clippy --workspace) was not run; only the two named crates were checked as specified, plus the fullbitty-richlib suite. - The out-of-tree graphics extension crate (
bitty-graphics, referenced as the W-141 raster mirror) is not in this worktree, so I could not confirm it needs no matching change; theKittyPlacementstruct gained two fields and is not#[non_exhaustive]. - kitty-spec conformance for a relative placement that omits
c=/r=(truth refuses spanless places atstate.rs:2317-2324, pre-existing) was not exercised.
VERDICT: APPROVE
… text fallback (bitty#2875) (#2894) * [CTX-1705] feat(render): truthful kitty a=q probes and image-cell text fallback (bitty#2875) Closes the residual scope items of issue #2875 that PRs #2881/#2893 left open. Scope 4 (a=q reply truthfulness): a PNG support probe answered `;OK` without reading the payload's `IHDR`, while the transmit path refuses an `IHDR` past the decode ceilings. A client was therefore told images work and got a blank. `bitty_rich::precheck_png_payload` now runs the decoder's own pre-allocation gate (signature, `IHDR` placement, non-zero sides, per-side/area ceilings, RGBA byte cap) and the probe calls it, so `probe == OK` iff the same bytes transmit. Raw formats already had this guarantee; PNG was the hole. Scope 6 (a11y/scene contract): a direct `a=p`/`a=T` placement owns no grid cell, so `bitty ctl terminal text` and the devtools grid-text snapshot reported an empty hole where the user sees an image. The runtime now derives each painted placement's cell footprint from the paint layer (unit cell metrics, so cell coordinates are exact and headless deterministic) and the shared text projection substitutes the Unicode object-replacement character for covered *blank* cells. Cells that hold real text keep it: an image over text must not erase that text from a reader. Scope 5 (animation): re-verified, no code gap. The bounded tick path (33ms quantum floor, at most 4 timed steps, 256-frame/64-image caps) is wired into present; added a test proving the *presented surface* changes when a frame advances and that wrapping repaints frame 1's bytes, which descriptor-only coverage could not catch. Tests: PNG probe/transmit verdict agreement (fails pre-fix: the probe answered OK), probe-over-refused-payload, image footprint + projection through PTY bytes (fails pre-fix: blank grid), ctl terminal text stand-in, deleted-image fail-closed, and the animation repaint pin. * [CTX-1705] docs(rich): drop a private intra-doc link from precheck_png_payload (bitty#2875) The rustdoc gate runs with -D warnings, and a public doc comment linked to the private `decode_png`. Plain code formatting keeps the reference without the broken link. Verified with RUSTDOCFLAGS="-D warnings" cargo doc --no-deps -p bitty-rich -p bitty-runtime -p bitty-terminal.
Priority: P1 | Area: render | Labels: feat,P1,area:render | Milestone: v0.2.0 | Task: CTX-1703
Refs #2875
Summary
a=prelative placements (P=parent image,Q=parent placement,H=/V=cell offsets) were recorded as terminal truth — anchor, cascade delete,ENOPARENTrefusal — but never painted: the pixel layer had no parent-anchor model, and the bodilessa=pmirror explicitly skipped them.Presentation now stores the parent's wire identity verbatim and derives the child rect at paint time from the parent's painted origin plus the cell offsets. Nothing is re-anchored on scroll, so there is no second scroll bookkeeping and presentation still never mutates grid truth.
bitty-rich:KittyPlacementgainsparent: Option<(u32, u32)>andparent_offset: (i32, i32); newdisplay_relative_for_originadmission seam andplacement_full_rect_resolved, which walks the parent chain (depth-bounded), takes the absolute ancestor's scroll-adjusted rect, adds the accumulatedH/Voffsets in pixels and uses the child's own span.KITTY_PLACE_MAX_PARENT_DEPTH = 8.bitty-rich: relative children cascade with their parent (remove_placement,remove,delete_by_wire) so a later re-place of the same wire identity cannot resurrect a child truth already dropped.bitty-rich: addressed re-puts now replace in place (terminal-truthupsertparity) instead of delete-then-add, so children of a re-put parent keep resolving and no duplicate blit stacks.bitty-runtime: the bodilessa=pmirror accepts relative placements and calls the new seam with the captured parent link; the admission gate now checks that truth recorded the same parent (a refused child never paints).bitty-runtimepresent path: the placement rect comes from the resolver, so scroll/clip/death follow the parent automatically.Fail-closed
A missing parent, a virtual prototype as parent (never in the placement deque), an offset that overflows the
i32pixel range, and a chain past the depth bound all paint nothing and never panic. The depth bound matters because a cycle is wire-reachable: a re-put only requires its named parent to exist, sop1 → p2 → p1can be built.z-order
The child keeps its own
z=, so the existingImagePaintLayersplit still applies: a negative-zchild composites below text, az >= 0child above it.Tests
Headless, through the same surface the shipped kitty paint tests use (placement counts, composite blit counts,
headless_rgbapixels):relative_child_paints_at_parent_origin_plus_offsets— child colour bounding box sits exactlyH=2/V=1cells from the parent's.relative_child_follows_parent_through_a_scroll— two scroll phases; the child keeps its offset and the exact second-phase delta is one cell per scrolled row.relative_child_disappears_when_its_parent_is_deleted— truth and pixel layer both cascade to zero, no orphan pixels.relative_child_fully_off_grid_paints_nothing—V=30is clipped away while the parent still paints.relative_below_text_child_paints_under_glyphs—z=-1child has glyph ink punched through it, with az=0control run that covers the text completely (so the assertion discriminates).relative_child_without_a_parent_paints_nothing— missing parent and virtual-prototype parent, with an absolute control run proving the same command withoutP=does paint.relative_parent_cycle_fails_closed_without_hanging— the wire-reachablep1 ⇄ p2cycle presents and paints nothing.bitty-richunit tests: offset + scroll resolution, missing parent, offset overflow, cycle at the depth bound, exact depth boundary, re-put keeps children / delete cascades.All new runtime tests fail on the pre-change tree (verified by re-adding the
!control.has_parent()gate: 6 of 7 fail), so they are behavioural, not tautological.Deliberately left out
a=astill drives the parent's frame; a child replay path is not added).a=T+P=(payload-carrying transmit-and-display) relative placements: only the bodilessa=pwire form is mirrored; thea=Tpath places at the cursor. Follow-up if a client needs it.c/p/q/x/y/z) still do not clear the rendered layer — pre-existing residual, unchanged here.Gates (local)
cargo fmt --all -- --check— okcargo clippy -p bitty-render -p bitty-runtime -p bitty-term-state --all-targets --offline -- -D warnings— ok, no warningscargo test -p bitty-term-state -p bitty-render -p bitty-runtime --offline— 255 test binaries, allok, 0 failedcargo +1.85 check -p bitty-rich --offline— ok (MSRV 1.85, no let-chains)RUSTDOCFLAGS="-D warnings" cargo doc -p bitty-rich --no-deps— ok (intra-doc links)just ci-localwas not run: this lane is instructed to use the targeted gates above to avoid colliding with parallel lanes sharing the act image and target cache.Summary by CodeRabbit