Repository navigation
[CTX-1820] fix(runtime): no stale owner on an allocation-epoch ceiling edge (bitty#2476 residuals 7a, 9b) - #3149
Conversation
…g edge
bitty#2476 residual 7(a): `release_generation_scope` stamped the ceiling edge
with `bound_owner.or(last_ended_owner)`. On an edge that ends the allocation
epoch no controller is bound, so `bound_owner` is `None` and the `or` copied
whatever the *previous* edge retained forward. The record then named a plugin
this edge never had, against `PanelRecord::last_controller_owner`'s own
contract ("None on an edge that ended the allocation epoch"), and the
`(owner, PanelId, N)` tombstone was keyed under that phantom owner. A later
legitimate bind from another plugin was then refused on the cross-owner
`CeilingLost` fence in `rebind_panel`, measured against a predecessor that had
already left.
The retention owner is now the owner of the binding this edge ends and nothing
else: `bound_owner`, `None` for an epoch edge. `last_ended_owner` is dropped
from the destructuring tuple rather than `#[allow]`-ed, with a comment naming
the repeat branch (which reads the retained pair from the record itself and is
unchanged).
bitty#2476 residual 9(b): the tombstone-replace line
(`retained_ceilings.retain(|(_, keyed_panel), _| *keyed_panel != panel_id)`,
"A.2: the panel's next edge replaces its own tombstone, whatever owner stamped
the previous one") had no revert-detecting test: deleting it left every suite
green. Two tests now drive one panel through edges whose tombstone keys differ
— `(None, panel)` from the allocation epoch an unbound container's release ends,
then `(Some(acme.notes), panel)` from the controller edge — and assert what
only the replace makes true: one entry for the panel, the retained ceiling is
the latest edge's, the successor's phase 0 reads that one, and repeated
same-panel edges never trip the fail-closed capacity guard with
`max_panels_per_window = 1`.
Tests (public `PanelRegistry` / `PanelRuntime` API only):
- `tests/panel_generation_ownership.rs`
- `an_allocation_epoch_edge_retains_no_owner_from_the_previous_edge`
- `a_bind_after_an_allocation_epoch_edge_is_not_measured_against_the_previous_owner`
- `tests/panel_grant_ceiling.rs`
- `a_panels_next_edge_replaces_its_own_tombstone_across_owners`
- `a_panels_repeated_edges_stay_inside_the_table_bound`
Refs #2476
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
Xuepoo
left a comment
There was a problem hiding this comment.
Independent review — 8 checks at 07e1212
Reviewed independently of the implementer, in my own worktree at 07e1212c with CARGO_TARGET_DIR=$HOME/.hermes/cache/scratch/ctx1820-review-target (nothing built or written in the main checkout or the lane worktree). Every gate below was executed; the A/B reverts were done by me, not taken from the PR description.
1. Semantics of the production change — PASS
let ended_owner = bound_owner; (crates/bitty-runtime/src/registry/panel.rs:3072) is exactly "the owner of the binding this edge ends, None when the edge ends the allocation epoch", and nothing wider:
bound_ownerisrecord.owner().cloned()(panel.rs:3014), the live binding owner.- The release reaches :3072 only after the
StaleHandlefence (panel.rs:3052), i.e. only when the presented generation equalsgrant_key_generation(). That helper iscontroller_generation().unwrap_or(generation)(panel.rs:687-689), sobound_owner.is_some()⟺ this edge ends a controller binding, andbound_ownerisNone⟺ this edge ends the allocation epoch. The stale value is not reachable through any other path. - Readers of
last_controller_owner, all checked: repeat branchpanel.rs:3045(unchanged), accessorpanel.rs:3207-3211,panels_ended_atpanel.rs:3294,capture_rebind_sourcepanel.rs:3449/3486/3496,rebind_panelentry fencepanel.rs:3775. The phase-0 comparison atpanel.rs:3486compares the tombstone owner against the record's retained owner — both are written by the same edge (panel.rs:3077-3088), so after the fix the pair isNone/Noneon an epoch edge. No reader used the old fallback as a substitute predecessor owner;derive_rebind_grants(panel.rs:3556) goes throughcapture_rebind_sourceonly.
One consumer narrows, deliberately and safely: panels_ended_at (panel.rs:3282-3300) filters last_controller_owner.as_ref() == Some(owner), so after an epoch edge a panel can no longer be reported as "ended at (owner, epoch)". Its only production caller is crates/bitty-terminal/src/plugin_runtime.rs:774-779 (held), invoked at :818 with controller_generation(edge.predecessor) — always a controller generation, never an allocation epoch. The change therefore only removes a spurious match; it cannot lose a legitimate panel from a reload enumeration, because both before and after the fix last_controller_generation is overwritten with the epoch (panel.rs:3087).
2. Repeat / already-ended branch untouched — PASS
The branch at panel.rs:3039-3050 is byte-identical to base: the head diff contains no hunk touching already_ended, or_else, or release_controller_binding (grep over git diff 08e077b2...HEAD -- panel.rs returns nothing), and panel.rs:3045 still reads bound_owner.or_else(|| record.last_controller_owner.clone()). It is still correct: a repeat must not rewrite the owner the first release stamped with the None the cleared binding now yields, and with the fix a epoch edge repeat resolves to None naturally because the record already carries None.
3. Tuple change / comments — PASS
No value is dropped that is still needed: last_ended is used at panel.rs:3037, allocation_epoch at panel.rs:3102, bound at panel.rs:3093, released_generation at panel.rs:3035/3052. No #[allow(...)], no #[cfg(test)]-only path, no cfg of any kind in the diff. The prose got stronger, not weaker: the removed sentence ("so it retains the None this write is keyed under") is replaced by the contract plus its failure mode (panel.rs:3062-3071), the destructuring comment explains why the field is not read (panel.rs:3000-3006), and both now agree with the field doc (panel.rs:641-644) and with retain_grant_ceiling's prose (panel.rs:3350-3352), which previously contradicted the code.
4. Test discrimination — PASS (reverted by me in my own worktree)
Revert A — restore last_ended_owner to the tuple and bound_owner.or(last_ended_owner), run cargo test -p bitty-runtime --offline --test panel_generation_ownership: 6 passed; 2 failed, both new rows red, the other six green.
an_allocation_epoch_edge_retains_no_owner_from_the_previous_edge (panicked at :294:5)
assertion `left == right` failed: an edge that ended no binding has no owner to retain:
the previous controller's owner is not carried forward
left: Some(PluginId("acme.notes"))
right: None
a_bind_after_an_allocation_epoch_edge_is_not_measured_against_the_previous_owner (panicked at :354:10)
the predecessor the record names is the allocation epoch, which no plugin owns, so there is
no foreign ceiling to refuse: CeilingLost { panel_id: PanelId(1), bind_generation: Generation(4),
last_controller_generation: Some(Generation(2)), tombstone_generation: Some(Generation(2)) }
Revert B — delete panel.rs:3374-3375 (self.retained_ceilings.retain(...)), guard untouched, run --test panel_grant_ceiling: 17 passed; 2 failed, both new rows red, the existing seventeen green.
a_panels_next_edge_replaces_its_own_tombstone_across_owners (panicked at :629:5)
assertion `left == right` failed: the panel still holds one entry, not one per owner
left: 2
right: 1
a_panels_repeated_edges_stay_inside_the_table_bound (panicked at :689:5)
assertion `left == right` failed: the panel's second edge replaces its own tombstone
instead of growing the table
left: Err(ResourceExhausted { reason: "retired-ceiling table is full (1); refusing to evict a
live panel's ceiling" })
right: Ok(true)
Restored → 8 passed / 19 passed. Both stated claims hold at the head SHA.
5. Test quality — PASS
- Integration tests under
crates/bitty-runtime/tests/, so public API only by construction (they compile without naming a private field). - No tautologies: expected sets are literals or values the test minted (
set(&[FOCUS]),Some(acme.clone()),Some(epoch)), never a second read of the container under test.last_controller_generation == Some(epoch)vslast_controller_owner == Noneare independent reads of two fields, not the same fact twice. - The two tombstone keys really are distinct:
NonevsSome(PluginId("acme.notes"))in aBTreeMap<(Option<PluginId>, PanelId), _>, so a table that only inserted genuinely holds two entries (proved by revert B:left: 2). - The capacity bound is genuinely configured small:
registry_with_max_panels(1)(panel_grant_ceiling.rs:684), and the revert-B failure texttable is full (1)provescapacity = min(1, MAX_RETAINED_GRANT_CEILINGS) = 1was in force rather than assumed. - No
sleep,thread::, orInstantin either file; each test builds its own registry andPanelIdspace; assertions are on orderedBTreeMapstate, so no ordering dependence between tests.
6. Scope — PASS
git diff 08e077b2...HEAD --stat: exactly three files (panel.rs +57/−27 region, panel_generation_ownership.rs +130, panel_grant_ceiling.rs +164/−1), 324 insertions / 27 deletions. No Cargo.toml, no version bump, no docs edits, no unrelated refactor. Commit subject [CTX-1820] fix(runtime): no stale owner on an allocation-epoch ceiling edge .... Body says Refs #2476 and states explicitly that this is "not a close"; no Closes/Fixes token.
7. Gates I actually ran — PASS
From $HOME/.hermes/cache/scratch/ctx1820-review at 07e1212c, CARGO_TARGET_DIR=$HOME/.hermes/cache/scratch/ctx1820-review-target:
| Gate | Result |
|---|---|
cargo fmt --all -- --check |
exit 0 |
cargo clippy -p bitty-runtime --all-targets --offline -- -D warnings |
exit 0 (25.9s) |
cargo test -p bitty-runtime --offline |
exit 0, 232 test result: ok summaries, 0 FAILED |
cargo +1.85 check -p bitty-runtime --tests --offline |
exit 0, no E0658 (no let-chains / if let guards in the new code) |
RUSTDOCFLAGS="-D warnings" cargo doc -p bitty-runtime --no-deps --offline |
exit 0 |
The 232-summary count matches the PR body's claim, and git status is clean at 07e1212c after my reverts.
8. Cross-platform risk — PASS
Nothing platform-dependent in the change: no cfg/cfg_attr/target_os, no sentinel constants, no new enum variants or match arms (so no unreachable_patterns risk), no FFI, no path or newline handling. It is an Option<PluginId> clone/assign plus Option comparisons; the tests use PluginId::new and Generation arithmetic only. The Windows/macOS legs should behave identically.
Defects
None found. No blocking issue in the production change, the comments, the tuple change, or the four new tests.
Residuals (non-blocking, outside this PR's named scope)
- An epoch edge still overwrites the controller predecessor pair.
panel.rs:3087setslast_controller_generation = Some(epoch)unconditionally, so a controller edge followed by an epoch edge drops(owner, N)from the record;panels_ended_atthen no longer yields that panel to its own controller's reload enumeration. Pre-existing on base (same assignment), not introduced here — butpanel_generation_ownership.rs:272-320now institutionalizes that ordering as the expected contract, so it deserves its own #2476 follow-up rather than staying implicit. - B.6 (cross-plugin adoption) is settled implicitly for the
None-predecessor case. After an epoch edge the entry fence atpanel.rs:3819has no owner to compare, so any plugin may bind and receive the epoch row's ceiling (panel.rs:3431-3510). That is what the field doc (panel.rs:641-644) and the fence doc (panel.rs:3769-3771) already assert, and the ceiling comes from a host-authored epoch row rather than another plugin's grant set — but the decision belongs in the OQ record, not only in a test comment. - Nit: the helper doc at
panel_grant_ceiling.rs:569-570says it returns "the controller generation that ended", while the returned controller generation is still bound when the helper returns (the caller ends it). Worth a one-line correction next time the file is touched.
VERDICT: APPROVE
…an allocation-epoch edge (bitty#2476 7f) (#3150) `PanelRegistry::release_generation_scope` (crates/bitty-runtime/src/registry/panel.rs) wrote the controller predecessor pair unconditionally on its non-repeat path, so an edge that ended the allocation epoch (no controller bound) overwrote the pair a controller edge had stamped with `(None, epoch)`. `panels_ended_at` then named no one for that generation, and the generation edge's successor bind — which enumerates that set — never rebound the container (bitty#2476 residual 7(f)). The pair now records only what it is documented to record, "the controller generation that ended a binding": - a controller edge (`bound == Some(generation)`) writes the pair and the tombstone exactly as before; - an allocation-epoch edge that finds a controller predecessor writes neither half and keeps the controller's tombstone, because the epoch is never a controller generation (B.1/B.2) and the tombstone is keyed by the same pair (`N-13`) — keeping the pair without its ceiling would refuse the successor's bind as `CeilingLost`; - an allocation-epoch edge on a panel with no controller predecessor still stamps `(None, epoch)` and its own tombstone, so a never-bound panel's first bind reads the same ownerless ceiling as before. The live row, the epoch sweep, the queue/command/overlay drain, and the `GenerationReleaseRecord` write are unchanged. The repeat branch follows the same rule, and a repeat is now also recognised from the release record (an epoch edge that keeps a predecessor leaves no tombstone of its own). Docs on the two `PanelRecord` fields, `PanelRegistry::last_controller_owner` and `release_generation_scope` were corrected to match. Tests (tests/panel_generation_ownership.rs, public API only): the epoch edge keeps the pair and the tombstone; `panels_ended_at(acme.notes, N)` still yields the container while `panels_bound_to` stays empty; a later successor bind is accepted against `N`'s ceiling; a foreign owner is refused `CeilingLost`. All three fail with the production hunk reverted (A/B proof in the PR). Two `#3149` expectations were re-read rather than kept: they pinned the `(None, epoch)` stamp this residual reports as the defect. Refs #2476
Two independent defects in
crates/bitty-runtime/src/registry/panel.rs, both residuals of bitty#2476. No version bump, no docs changes, no refactors outside this file and its two test files.Residual 7(a) — stale owner on an allocation-epoch ceiling edge
PanelRegistry::release_generation_scope(panel.rs:2987) took the record's retainedlast_controller_ownerand stamped the tombstone withbound_owner.or(last_ended_owner). When no controller is bound the edge ends the allocation epoch, not a binding, sobound_ownerisNoneand theorcopied whatever the previous edge retained forward.Result before this change:
PanelRecord::last_controller_owner(panel.rs:645, doc: "None… on an edge that ended the allocation epoch instead of a bound controller") named a plugin this edge never had, and the(owner, PanelId, N)tombstone was keyed under that phantom owner.rebind_panel's entry fence (panel.rs:3819, comparison atpanel.rs:3820) comparespredecessor_owneragainst the presented owner, so the next legitimate bind from another plugin was refused asCeilingLostagainst a predecessor that had already left — permanently, since nothing rewrites the stale pair.Fix: the retention owner is the owner of the binding this edge ends and nothing else.
panel.rs:3072—let ended_owner = bound_owner;(wasbound_owner.or(last_ended_owner)), with the contract spelled out in the comment above it.panel.rs:3007—last_ended_owneris removed from the destructuring tuple (no#[allow]), with a comment saying why it is not read: it is dead on this path now that the write keys on the live binding, and the repeat/already-ended branch (panel.rs:3045) keeps its ownbound_owner.or_else(|| record.last_controller_owner.clone())behaviour untouched. The repeat branch was not rewritten to the clearedNone.Residual 9(b) — the tombstone-replace line had no revert-detecting test
retain_grant_ceiling(panel.rs:3359) starts with("A.2: the panel's next edge replaces its own tombstone, whatever owner stamped the previous one"). Deleting that line left every existing suite green, so nothing pinned it. Two tests now do, both driving one panel through edges whose tombstone keys differ —
(None, panel)from the allocation epoch edge of an unbound container, then(Some(acme.notes), panel)from the controller edge — using only the publicPanelRegistryAPI:crates/bitty-runtime/tests/panel_grant_ceiling.rs:613a_panels_next_edge_replaces_its_own_tombstone_across_owners—retained_grant_ceiling_count()is 1 for that panel (not one per owner), the retained ceiling is the latest edge's (ended_generation,owner,grants), and the successor's phase 0 reads that one instead of the older row that sorts first.crates/bitty-runtime/tests/panel_grant_ceiling.rs:683a_panels_repeated_edges_stay_inside_the_table_bound— the same panel's second and third edges, withmax_panels_per_window = 1(table capacitymin(1, MAX_RETAINED_GRANT_CEILINGS) = 1): each returnsOk(true)andRetiredCeilingTableFullstays 0, i.e. the fail-closed capacity guard is never reached by a panel replacing its own entry.Discriminating tests for residual 7(a)
crates/bitty-runtime/tests/panel_generation_ownership.rs:272an_allocation_epoch_edge_retains_no_owner_from_the_previous_edge— after the epoch edge,last_controller_ownerisNoneand the tombstone is keyed underNonewith the epoch row's grants.crates/bitty-runtime/tests/panel_generation_ownership.rs:337a_bind_after_an_allocation_epoch_edge_is_not_measured_against_the_previous_owner— a bind by a different owner after the epoch edge succeeds,CeilingLoststays 0, provenance names the epoch edge, and the successor is bounded by the epoch edge's{panel.focus}(nothing of the previous controller's set is adopted).A/B discrimination proof
Each fix reverted in place, the named tests re-run, then restored.
git diffis exactly the change above at the end (git statusclean on07e1212c).(1) Residual 7(a) — revert
let ended_owner = bound_owner;tobound_owner.or(last_ended_owner)and re-addlast_ended_ownerto the tuple —cargo test -p bitty-runtime --offline --test panel_generation_ownership:The other six rows in that file stay green, so the tests fail for the stale owner and not for a broken fixture. Restored → 8 passed.
(2) Residual 9(b) — delete
panel.rs:3375(self.retained_ceilings.retain(...)), guard untouched —cargo test -p bitty-runtime --offline --test panel_grant_ceiling:The other 17 rows in that file stay green — that is the point: with the replace gone they still pass, which is why the line was previously unpinned. Restored → 19 passed.
Gates
All run from the worktree at
07e1212cwithCARGO_TARGET_DIR=/mnt/data/Workspace/Projects/bitty-terminal/.targets/ctx-1820.cargo fmt --all -- --checkcargo clippy -p bitty-runtime --all-targets --offline -- -D warningscargo test -p bitty-runtime --offline(whole crate, 232test result: oksummaries, 4m05s)cargo +1.85 check -p bitty-runtime --tests --offlineRUSTDOCFLAGS="-D warnings" cargo doc -p bitty-runtime --no-deps --offlineFocused runs during development:
--test panel_generation_ownership8/8,--test panel_grant_ceiling19/19.Gate 2 was verified live, not assumed: adding
let clippy_liveness_probe = 1;to one test made it exit 101 witherror: unused variable, and the statement was then removed (exit 0 again,git statusclean).Not in this PR
Residuals 8 and 10 stay blocked on the owner contract decisions, and residual F is a separate seam item; this is
Refs #2476, not a close.retire_rebound_ceiling, the repeat/already-ended branch ofrelease_generation_scope, the window/wheel code, and every docs repo are untouched.Refs #2476
Summary by CodeRabbit