Repository navigation
[CTX-1864] fix(runtime): observable capture release and unbound-container record accessor (bitty#2476) - #3210
Conversation
…und-container record accessor (bitty#2476)
bitty#2476 names two acceptance criteria the panel generation work could not
observe. Both are closed here with a seam and a test that discriminates.
AC-3 (capture release observability). The unbind edge released four families
it owns — the panel grant row, the queued bus events, the panel commands, and
the attributed overlays — and wrote all four into
`GenerationReleaseRecord`. The fifth family, the generation's overlay
input-capture session, is revoked by the plugin runtime
(`OverlayCapture::revoke_plugin` in `dispose_inner` / `rollback`), which
cannot name a `PanelRegistry`, so "the capture session is gone" was only
inferable from the plugin runtime's own state.
* `PanelEdgeRelease` now carries `capture_revoked`: the answer the edge's
own revoke gave. `dispose_inner` passes it, and `rollback` now revokes
before the container edge (the order `dispose_inner` already used) so the
report is available when the containers are released.
* `PanelRuntime::note_capture_release` / `PanelRegistry::note_capture_release`
store that report per container, fenced on the panel's binding generation
(`StaleHandle` otherwise), at most one per container, dropped with it.
* `release_generation_scope` folds a report naming the released generation
into `GenerationReleaseRecord::capture_sessions` (and `total()`), so the
fifth family is readable exactly where the other four already were.
AC-4 ("accepts no verb, keeps one record"). The AC held structurally but was
not observable as one value, so nothing pinned "one record" over time versus
"one record per tick".
* `PanelRegistry::unbound_container_records` (and the same accessor on
`PanelRuntime`) returns a derived `UnboundContainerRecords` snapshot: the
bound generation, the single placeholder reason, the retained records'
typed reasons, and the saturated binding. Read-only, never stored.
Tests
* `panel_unbind_release::the_edge_records_the_capture_family_the_generation_edge_revoked`
(+ the unreported half),
`a_capture_report_for_another_generation_is_refused_and_never_carried`.
* `panel_generation_ownership::the_generation_edge_records_the_capture_session_it_revoked`
(real `dispose_inner` revoking a live capture) and
`a_generation_edge_without_a_capture_records_none` (negative half).
* `bitty-terminal` unit rows
`the_panel_edge_port_reports_the_capture_family_before_the_release` and
`the_panel_edge_port_reports_no_capture_when_the_edge_revoked_none` pin
the composition-root adapter.
* `panel_rebind::an_unbound_container_keeps_one_record_across_many_ticks`
unbinds a container, drives `RECOVERY_ATTEMPT_CAP * 3` ticks (lease sweep,
placeholder block rebuild, state/attachment reads) with no verb call,
asserts the snapshot is unchanged every tick and the attempt counter is
still 1, then asserts a verb still fails closed with `CapabilityDenied`
and emits no record.
A/B discrimination (scratch copy, own CARGO_TARGET_DIR; the lane worktree was
never mutated):
* AC-4: with the accessor reporting one extra record (the deletion-equivalent
for a pure reader — removing the symbol is E0599, not an assertion
failure), the ticks row fails at "one ending transition, one record"
(left 2, right 1); restored, green.
* AC-3 fold: with the fold returning 0, the registry row fails at
"the capture family is counted with the families the registry released"
(left 0, right 1); restored, green.
* AC-3 edge: with `dispose_inner` dropping the revoke's answer, the
edge row fails at "the capture family the edge revoked is named with the
other families" (left 0, right 1); restored, green.
* AC-3 adapter: with the port's report removed, the port row fails at
"the port must report the capture family before the release writes the
record" (left 0, right 1); restored, green.
Gates: cargo fmt --check; cargo clippy -p bitty-runtime -p bitty-terminal
--all-targets --offline -- -D warnings; cargo +1.85 check -p bitty-runtime
-p bitty-terminal --tests --offline; the three panel test binaries; the
bitty-terminal unit rows; RUSTDOCFLAGS="-D warnings" cargo doc -p
bitty-runtime --no-deps; full `cargo test -p bitty-runtime`. `just ci-local`
was not run (act needs github.com over HTTPS, unreachable from this host).
Related #2476
|
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 58 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. |
Xuepoo
left a comment
There was a problem hiding this comment.
Independent guard-dispatched review (different session) of head 4bf9ab959cd2119b6fd45ec534efbd67543ba2d1.
VERDICT: CHANGES-REQUESTED — the implementation is correct on every functional axis attacked, but two of the four new rows are provably non-discriminating in the exact places their docstrings claim otherwise.
Per-check
1. Diff scope/content — PASS
8 files, all in scope (plugin_runtime/mod.rs, panel_generation.rs, registry/host.rs, registry/panel.rs, 3 test files, bitty-terminal/src/plugin_runtime.rs). Claims (a)–(d) all present. Two behaviour changes the diff makes but the description does not call out: (i) rollback now revokes capture before the panel edge (mod.rs:5331 vs the old post-edge position) — necessary for (a), and nothing between the two calls depended on the order; (ii) GenerationReleaseRecord::total() now includes capture_sessions (panel.rs:1430), which shifts unbind_release_count. No production consumer of it exists outside tests, so risk is observability-only.
2a. an_unbound_container_keeps_one_record_across_many_ticks — FAIL
panel_rebind.rs:926, loop at :976. Each iteration is sweep_expired_leases(tick) (:978) plus four reads through registry() (&PanelRegistry, hence &self). The test holds no lease, so the sweep iterates an empty map and returns vec![]. So: 24 distinct clock values into a no-op, wrapped by 4 identical pure reads — not distinct engine ticks. assert_eq!(ticked, baseline) is guaranteed true by the call signatures; the docstring's stated failure mode ("a tick path that re-presents the placeholder") is unreachable because the presenter is never called in the loop.
2b. Capture fold test can fail — PASS
Deleting the fold makes 3 rows fail, not 1.
2c. a_capture_report_for_another_generation_is_refused_and_never_carried — FAIL (first half only)
panel_unbind_release.rs:368. The refusal half is strong: exact PanelError::StaleHandle{..} equality at :394 plus error_count("StaleHandle")==1. The "never carried" half at :416 cannot fail: the successor's own note_capture_release replaces the single BTreeMap slot before the release runs, and SESSIONS is a constant 1, so the observed value is 1 whether or not the stale report was stored.
3. Fencing — PASS (with caveats)
note_capture_release (panel.rs:3169) fences on grant_key_generation() at :3181 and refuses before storing; the fold is :3456-3460. Reporting before present_placeholder (bitty-terminal/src/plugin_runtime.rs:1026-1036) cannot be lost or double-counted per container: one slot per panel, insert replaces, remove on release, and the generation filter is a second guard. The capture_sessions generation-wide/per-container ambiguity the author flagged is documented, not silent (panel.rs:1414-1421, 3145-3155), so a reader summing across N containers gets N — declared, but note that total() now carries it. Minor: a report can linger unconsumed if release_generation_scope takes the already_ended early return (panel.rs:3335-3360) or if present_placeholder refuses; bounded to one per panel, dropped on disposal, and unmisattributable because of the generation filter.
4. Independent discrimination performed (scratch copies pr3210/src and pr3210/mut, each with its own CARGO_TARGET_DIR; lane worktree untouched, HEAD unchanged)
| mutation | result |
|---|---|
fold → 0 (panel.rs:3456) |
FAIL ×3: the_edge_records_the_capture_family... (unbind:342), a_capture_report_for_another_generation... (:416), the_generation_edge_records_the_capture_session_it_revoked (pgo:2430) |
capture_revoked hardcoded true at mod.rs:3941 (review probe, not in the author's A/B) |
a_generation_edge_without_a_capture_records_none FAILS left: 1, right: 0 |
fence if false && bound != generation (panel.rs:3181) |
..._refused_and_never_carried FAILS at unbind:394 (StaleHandle path is real) |
stale report inserted before returning StaleHandle |
all 8 pass → proves 2c's "never carried" half is vacuous |
injected unused variable in the new test, clippy -D warnings |
exit 101 → gate is live, so the clean run is meaningful |
5. Cross-platform — PASS, real checks run
cargo check -p bitty-runtime --tests --target x86_64-pc-windows-gnu --offline → exit 0, zero rustc warnings; -p bitty-terminal --tests same target → exit 0; -p bitty-runtime -p bitty-terminal --tests --target aarch64-apple-darwin --offline → exit 0; Linux cargo clippy -p bitty-runtime -p bitty-terminal --tests -- -D warnings → exit 0. capture_revoked is an ungated bool, tests use only std::time. Only warning is the pre-existing winres icon note.
Tests at head all green: 39 runtime rows + both new bitty-terminal rows (--bin bitty, 1642 filtered).
Requested changes
panel_rebind.rs:976— either drive the real per-frame presenter path (what the docstring names) or drop the "distinct ticks / re-presents" claim; today the loop proves only that four&selfreads do not mutate.panel_unbind_release.rs:416— assert the refusal left nothing: release the successor without a fresh report and requirecapture_sessions == 0, or report the stale generation against an unbound panel and read the successor's record before its own report.
No functional defect found in (a)–(c); the block is on the test evidence, not the code.
VERDICT: CHANGES-REQUESTED
…s discriminating The independent review proved both rows vacuous by mutation. Both now fail against the mutation they claim to catch. `an_unbound_container_keeps_one_record_across_many_ticks`: the tick loop now drives the shipped present loop's per-leaf entry (`scene_paint_for`, a `&mut self` call, the same call `runtime/scene_present.rs` makes for the leaf) and asserts it paints nothing, instead of only `&self` reads. The docstring no longer claims a per-frame presenter: `present_placeholder` is edge-owned (`AppPanelGenerationPort::release_generation`), so the row asserts the fence that keeps it edge-only — a second presentation of the ended generation is refused `ControllerReleased` and writes no record. `a_capture_report_for_another_generation_is_refused_and_never_carried`: the "never carried" half read `capture_sessions == 1` after the successor reported its own session, which a report stored before the `StaleHandle` return cannot change (the release fold is generation-keyed and drops it anonymously). The test now reads the pending report — new `PanelRegistry:: capture_edge_report_generation`, the only place the ordering is observable — and requires it empty after the refusal, then releases the successor with no report of its own and requires `capture_sessions == 0`. Mutation evidence (scratch copy, own CARGO_TARGET_DIR): storing the report before the fence makes the row fail at the pending-read assertion (`Some(Generation(3))` vs `None`); restoring it is green, as is the same-shaped mutation that writes a recovery record on a refused re-presentation (fails at "a refused presentation writes no record").
|
Test-evidence fixes for both review findings, pushed as c53ea5d.
Mutation (scratch copy, own Gates: fmt 0, clippy (bitty-runtime, bitty-terminal, all-targets, -D warnings) 0, panel_rebind/panel_rebind+unbind/panel_placeholder_bounds 12+8+6 pass, |
Xuepoo
left a comment
There was a problem hiding this comment.
Round-2 guard-dispatched independent review at head c53ea5d33a8dc2a9e51ea5e3e76019309556d6a0 (different session from the fix; lane worktree read-only, every mutation proof in a scratch copy under /home/fuyu/.hermes/cache/scratch/r2 with its own CARGO_TARGET_DIR).
VERDICT: APPROVE — both round-1 blocks are genuinely closed. The two rows now fail against the exact mutations they claim to catch, the full PR diff deletes no assertion, and the new symbol is a pure read that builds on every leg.
1. Fix delta 4bf9ab95...c53ea5d3 (3 files, +121/−24) — PASS
registry/panel.rs only adds capture_edge_report_generation (panel.rs:3211): pub fn …(&self, panel_id: PanelId) -> Option<Generation> over self.capture_edge_reports.get(&panel_id).map(|report| report.generation), #[must_use], fully documented.
- Read-only / cannot change behaviour.
&self, aBTreeMapget(capture_edge_reportsis a plainBTreeMap<PanelId, CaptureEdgeReport>,panel.rs:1686;GenerationisCopy). No store, nobump_error, no interior mutability, no cache warming. The only effect of calling it is producing a value. - Necessary, not convenience. It is the only surface that can observe the ordering round 1 asked about: the fold in
release_generation_scopeis keyed by generation, so a stale report is dropped anonymously andGenerationReleaseRecordcan never show "stored before refused". Integration tests link against the public lib, so a#[cfg(test)]reader would not be visible totests/panel_unbind_release.rs. It matches the crate's existing read-only observability set (unbind_release_record:3744,unbind_release_count:3753). It is also not load-bearing on its own — the second half of my round-1 ask (successor edge with no report of its own →capture_sessions == 0,panel_unbind_release.rs:433) is implemented too.RUSTDOCFLAGS="-D warnings" cargo doc -p bitty-runtime --no-deps --offline→ exit 0, so the new intra-doc links resolve.
2. Round-1 mutation reproduced — PASS
In r2/mut at head, CARGO_TARGET_DIR=r2/targetA, I re-inserted the store before the binding fence (panel.rs:3184, ahead of if bound != generation):
panicked at crates/bitty-runtime/tests/panel_unbind_release.rs:417:5:
assertion `left == right` failed: a refused report is refused before anything is stored
left: Some(Generation(3))
right: None
test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 7 filtered out
Same site and same values the author reported (:417, left: Some(Generation(3))). Reverted (git status clean, 0 files modified) → panel_unbind_release 8 passed, panel_rebind 12 passed.
3. Tick row can now fail — PASS
- The loop now drives the shipped per-leaf entry,
scene_paint_for(ViewContent::Panel(id), None, CW_PRESENT_MAX_SCENE_BLOCKS)(panel_rebind.rs:998), which is the callruntime/scene_present.rs:309makes for a panel leaf. For this container it returnsScenePresent::default()at theself.scenes.get(&id)miss (registry/host.rs:1362) — the test attaches no scene — so it executes the entry, not the paint path. - It can fail, proven twice. Mutation B (record written unconditionally before the fence) → FAILED
panel_rebind.rs:978,one ending transition, one record, left 2 / right 1. Mutation B2 (record written only on the refusal path, so the baseline stays clean) → FAILED at the new assertionpanel_rebind.rs:1058,a refused presentation writes no record,left: … reasons: [Unloaded, Unloaded],right: … reasons: [Unloaded]. The added secondpresent_placeholder+ record-set-equality block is therefore discriminating, not decorative; the fence itself also returnsControllerReleasedfor the ended generation (panel_rebind.rs:1048). - Docstring matches the proof, with one leftover clause. The narrowed text correctly states that
present_placeholderis edge-owned and the shipped present loop "only composes an attached scene, so an unbound container has no per-frame presenter reachable from this seam" (panel_rebind.rs:928-932). Non-blocking imprecision: the parenthetical "the call a shipped frame makes for that leaf" (:914-915) is not true for this leaf, becausescene_present.rs:302filterspanel_scene(*panel).is_some()before calling and a released generation's scene is revoked at the edge — the same docstring corrects this two sentences later. - AC-4 is not dropped. The header still reads
AC-4, "accepts no verb, one record", and the row still pinsrecord_count() == 1(:978), per-tick snapshot equality (:1037),recovery_attempts == 1(:1067), andCapabilityDeniedfor a verb (:1077). The only claim removed is the false one — that the presenter is a tick path.
4. Nothing weakened — PASS
Full PR diff c30539c4 → head: 8 files, +932/−23. All 21 deleted code/comment lines contain no assert, expect or unwrap (grep of ^- lines). The single changed expectation is capture_sessions: 1 → 0 in the same row (panel_unbind_release.rs:433), which is not a downgrade: round 1 proved the old 1 was vacuous (the successor's own report set it), and "a report naming the bound generation counts exactly one" is still covered at :341 and :382.
Tests at head (clean tree, warm target, --offline):
| suite | result |
|---|---|
panel_rebind |
12 passed, 0 failed |
panel_unbind_release |
8 passed, 0 failed |
panel_placeholder_bounds |
6 passed, 0 failed |
26 rows, green; the mutated copies were restored to git status clean before this run.
5. Cross-target — PASS
cargo check -p bitty-runtime --tests --target aarch64-apple-darwin --offline→ exit 0cargo check -p bitty-runtime --tests --target x86_64-pc-windows-gnu --offline→ exit 0
The new accessor is ungated and breaks neither leg; no new warnings (only the pre-existing block v0.1.6 future-incompat note).
Residuals (non-blocking, no re-review needed)
panel_rebind.rs:914-915: drop "(the call a shipped frame makes for that leaf)" or scope it to a leaf with an attached scene — as written it contradicts the correct paragraph below.- The tick loop's leaf call cannot reach the paint branch by design (no scene), so "Fails for … a present-loop leaf call that … writes a record" holds only for writes before the scene lookup.
VERDICT: APPROVE
What this closes
bitty#2476's 2026-11-17 analysis names two acceptance criteria that were true but not observable, so nothing pinned them:
plugin_runtime(OverlayCapture::revoke_pluginindispose_inner), invisible toGenerationReleaseRecord.the_edge_releases_every_generation_familycovered four of five families.GenerationReleaseRecord::capture_sessions, fed by the edge that revoked it, so the fifth family reads exactly where the other four do.require_panel_capability→CapabilityDeniedonce the binding is gone) but there was no single value to compare across ticks. Only record-count assertions werepanel_rebind.rs:423/437(reasondenied) andpanel_placeholder_bounds.rs:103(nine attempts, not ticks).PanelRegistry::unbound_container_records/PanelRuntime::unbound_container_recordsreturn one derivedUnboundContainerRecordssnapshot, and a test drives 24 ticks comparing it.AC-3 — capture release is observable from the registry
The session is not the registry's: OQ-084 D.4 puts the revoke in the plugin runtime, which cannot name a
PanelRegistry. The seam is therefore a report, not a move:PanelEdgeReleasegainscapture_revoked— the answerOverlayCapture::revoke_plugingave at that edge.dispose_innerpasses it;rollbacknow revokes before the container edge (the orderdispose_inneralready used) so the answer exists when the containers are released. Nothing between the two lines depended on the old order.PanelRegistry::note_capture_release(panel, generation)(also onPanelRuntime) stores the report for that container, fenced on the panel's binding generation — a report for any other generation isStaleHandle, so a late report is a diagnosable ordering defect rather than a silently lost fact. At most one report per container; dropped with it (dispose_panel).release_generation_scopefolds a report naming the released generation intoGenerationReleaseRecord::capture_sessions(and intototal()), and drops a report naming another generation instead of attributing it to the wrong edge.AppPanelGenerationPortreports before it callspresent_placeholder, because that call is what writes the record.Semantics are stated in the rustdoc rather than implied: the session is generation-scoped, so an edge that released several containers reports the same count on each — the number says what the edge revoked, never "how much this container owned".
AC-4 — one value for the unbound record set
UnboundContainerRecordsis derived per call and never stored (no authority, a plugin cannot hold it): bound generation, the single placeholder reason, the retained records' typed reasons (closed vocabulary, not prose), and the saturated binding. A bound container reads as a snapshot withbound_generationset, not as "no container".Tests added
panel_rebind::an_unbound_container_keeps_one_record_across_many_ticks— unbind, driveRECOVERY_ATTEMPT_CAP * 3= 24 ticks (host lease sweep, placeholder-block rebuild, state and attachment reads) with no verb call, assert the snapshot is unchanged every tick, assert the attempt counter stays1, then assert a verb still fails closed withCapabilityDeniedand emits no record.panel_unbind_release::the_edge_records_the_capture_family_the_generation_edge_revoked— one record, one generation,total()includes the capture family; plus the unreported edge records0.panel_unbind_release::a_capture_report_for_another_generation_is_refused_and_never_carried—StaleHandle, and the stale report is not folded into the successor's record.panel_generation_ownership::the_generation_edge_records_the_capture_session_it_revoked— the productiondispose_innerrevoking a live capture taken the way a focusable overlay takes one.panel_generation_ownership::a_generation_edge_without_a_capture_records_none— the negative half (a record that always said1fails this one).bitty-terminalunit rowsthe_panel_edge_port_reports_the_capture_family_before_the_release/..._reports_no_capture_when_the_edge_revoked_none— the composition-root adapter itself.A/B discrimination (scratch copy, own
CARGO_TARGET_DIR; the lane worktree was never mutated)Each mutation was applied in a scratch clone, the named row was re-run, and the production code was restored and re-run green.
one ending transition, one record(left 2, right 1)release_generation_scope0the capture family is counted with the families the registry released(left 0, right 1)dispose_innerthe capture family the edge revoked is named with the other families(left 0, right 1)AppPanelGenerationPortthe port must report the capture family before the release writes the record(left 0, right 1)Note on AC-4: the accessor is a pure reader, so deleting the symbol is
error[E0599] no method named 'unbound_container_records'(verified) rather than an assertion failure. The record-set mutation above is the assertion-level equivalent, and it is what the AC actually claims ("one record", not "a method exists").All four mutations restored → all rows green.
Gates run
cargo fmt --all -- --checkcargo clippy -p bitty-runtime -p bitty-terminal --all-targets --offline -- -D warningscargo +1.85 check -p bitty-runtime -p bitty-terminal --tests --offline(MSRV: no let-chains, no if-let guards)cargo test -p bitty-runtime --test panel_rebind --test panel_unbind_release --test panel_generation_ownership→ 19 / 12 / 8 passedcargo test -p bitty-terminal --bin bitty the_panel_edge_port→ 2 passedcargo test -p bitty-runtime(whole crate, incl. doctests) → greenRUSTDOCFLAGS="-D warnings" cargo doc -p bitty-runtime --no-depsjust ci-localnot run:actneedsgithub.comover HTTPS, unreachable from this host.Residual
plugin_runtime/overlay.rs) does not have.PluginServices::clear_ui_blocksare still not counted separately; only the input-capture session is.clear_ui_blocksreturns nothing, so counting handles would need a new return type there — a separate seam, not required by AC-3's "capture session" wording.Related #2476