Repository navigation
[CTX-1821] fix(runtime): keep the controller predecessor pair across an allocation-epoch edge (bitty#2476 7f) - #3150
Conversation
…an allocation-epoch edge (bitty#2476 7f) `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
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
Xuepoo
left a comment
There was a problem hiding this comment.
PR #3150 review — CTX-1821 (bitty#2476 residual 7(f))
Repo bitty-terminal/bitty, head 811e9363ea0a50318f197e8585b18de0793522fb,
branch ctx-1821/controller-predecessor-pair. Reviewed read-only in the lane
worktree; all mutation, builds and revert-proofs ran in
/tmp/hermes/pr3150-revert/pr (byte copy of the lane) with
CARGO_TARGET_DIR=/tmp/hermes/pr3150-revert/target{,-msrv}.
Diff under review: crates/bitty-runtime/src/registry/panel.rs (+125/-),
crates/bitty-runtime/tests/panel_generation_ownership.rs (rewrites 2 tests,
adds 1).
1. Claim vs code — PASS
Defect fixed: PanelRegistry::release_generation_scope
(crates/bitty-runtime/src/registry/panel.rs:3010-3186). Before this PR, an
edge whose generation was the allocation epoch (i.e. bound == None) fell
through the same write path as a controller edge: it re-stamped the retained
predecessor pair with last_controller_generation = Some(epoch) and
last_controller_owner = None, and replaced the retained-ceiling tombstone
with an epoch-keyed one ((None, epoch)). Three facts were destroyed at once:
the pair the successor enumerates, the tombstone keyed to that pair, and the
controller's grant ceiling.
New code preserves the pair exactly at the named edge:
panel.rs:3119let ends_bound_controller = bound == Some(generation);—
true only for the edge that ends a binding (thereleased_generation != generationfence at:3094-3101proves the binding key isgeneration, so
the equality is exact).panel.rs:3137let keeps_controller_predecessor = !ends_bound_controller && last_ended.is_some();panel.rs:3142-3152theretain_grant_ceilingwrite is skipped, so the
controller's tombstone (and hence its grant ceiling) survives.panel.rs:3153-3162both halves ofPanelRecord's pair are left untouched
beforerelease_controller_binding.panel.rs:3071-3074the unbound repeat of that edge is now recognised from
theGenerationReleaseRecordthe first pass wrote, because a kept
predecessor leaves no tombstone of the epoch edge's own to name it; the early
return at:3075-3095no longer mixes the epoch generation with the kept
owner (:3087if bound.is_some() || record.last_controller_generation.is_none()).
Everything else the edge owed still runs on both branches: the epoch-keyed row
is removed (:3164), the epoch row is not swept when no binding ended
(:3165-3175), queued events/commands/overlays are drained
(:3176-3179), and the release record is written (:3180-3187). The
ceiling-keep rule is not an epoch special case at the pair level: a never-bound
panel has last_ended == None, so keeps_controller_predecessor is false and
the epoch edge still stamps its own ownerless predecessor (:3126-3136,
comment).
2. Reachability — PASS (with a caveat)
The changed lines are reachable from production code, through
PanelRegistry::dispose_panel:
panel.rs:2172self.release_generation_scope(panel_id, binding_key)?;
wherebinding_key = rec.grant_key_generation()(:2140) resolves to the
allocation epoch once no controller is bound (:694-696). A panel whose
controller already left iswas_controller == true(:2147-2151), so the
release runs withbound == None,last_ended == Some(n)— the exact branch
this PR changes.dispose_panelfacades:crates/bitty-runtime/src/registry/host.rs:383-389
(PanelRuntime::dispose_panel), reached at the plugin generation boundary via
crates/bitty-runtime/src/scene_host.rs:493,:517,:545
(SceneHost::release_panel) and by workspace close
(crates/bitty-runtime/src/runtime/workspaces.rs:2213).- Other production call sites do not reach the branch:
panel.rs:2376is
guarded bybound == Some(presented);panel.rs:3941releases
capture.predecessor_generation()and the retained tombstone recognises the
repeat.
Caveat (non-blocking, worth a follow-up note): the observable consequence the
commit message names — "the generation edge's successor could neither find the
container nor rebind it" — is not reachable from production today, because
dispose_panel removes the record (:2224-2249) immediately after the release,
so no surviving panel carries the kept pair out of dispose_panel. The fix is
therefore a correctness/prospective-API fix on a pub method whose only
surviving-panel caller is a test-side sequence; the successor path that consumes
it (crates/bitty-terminal/src/plugin_runtime.rs:777 panels_ended_at inside
held, called from bind_successor at :815-825) is real production code, so
the invariant is load-bearing the moment a non-dispose epoch edge appears.
3. Test discrimination — PASS (proved red on pre-fix code)
Copy, not the lane: /tmp/hermes/pr3150-revert/pr (cp -a, git rev-parse HEAD = 811e9363…), CARGO_TARGET_DIR=/tmp/hermes/pr3150-revert/target.
Baseline at HEAD:
running 9 tests
test result: ok. 9 passed; 0 failed; 0 ignored
Production hunk reverted only (git checkout origin/main -- crates/bitty-runtime/src/registry/panel.rs; the two files are the whole diff, so
this is exactly the production hunk). The reverted tree still compiles with the
new tests (they use only pre-existing public API), then:
test an_allocation_epoch_edge_leaves_the_container_enumerable_for_its_successor ... FAILED
test an_allocation_epoch_edge_keeps_the_controller_predecessor_pair ... FAILED
test a_bind_after_an_allocation_epoch_edge_reads_the_controller_it_names ... FAILED
test result: FAILED. 6 passed; 3 failed
Verbatim panic bodies:
---- an_allocation_epoch_edge_leaves_the_container_enumerable_for_its_successor ----
panicked at crates/bitty-runtime/tests/panel_generation_ownership.rs:402:5:
assertion `left == right` failed: the container is still the ended controller generation's, so the successor bind enumerates it
left: [] right: [PanelId(1)]
---- an_allocation_epoch_edge_keeps_the_controller_predecessor_pair ----
panicked at crates/bitty-runtime/tests/panel_generation_ownership.rs:305:5:
assertion `left == right` failed: the pair still names the controller generation that ended a binding, so both halves come from that one edge and never from the epoch edge
left: None right: Some(PluginId("acme.notes"))
---- a_bind_after_an_allocation_epoch_edge_reads_the_controller_it_names ----
panicked at crates/bitty-runtime/tests/panel_generation_ownership.rs:470:5:
left: Some(Generation(2)) right: Some(Generation(3))
The first failure is the defect itself (panels_ended_at empty ⇒ the
successor's held() enumeration cannot find the container). Restoration
verified: git checkout HEAD -- crates/bitty-runtime/src/registry/panel.rs,
then git status --porcelain empty. The changed tests also pin the two wrong
"fixes" the commit message names — carrying an owner forward (:305/:309
assert (Some(acme), n), so (acme, epoch) fails) and overwriting the pair with
(None, epoch) plus an epoch tombstone (:317-336 assert
ceiling.ended_generation == n, ceiling.owner == Some(acme),
ceiling.grants == {create, focus}, and :345-352 assert the epoch row is
still released and a release record exists). Test ids :280, :377, :453.
4. Invariants — PASS
Single owner + generation semantics:
- Stale handle still fails closed before any family is touched:
panel.rs:3094-3101returnsPanelError::StaleHandle { expected_generation, found_generation, id_raw }, computed beforecapabilities.get/remove. The
already_endedprobe above it (:3058-3074) is read-only
(retained_grant_ceiling,release_records.get), and the new
release_recordsclause (:3071-3074) is only reachable when
bound == None, so a foreign generation presented to a bound panel is still
refused. - The pair is written as one fact:
:3087-3092(repeat branch) and
:3156-3161(main branch) both gate thelast_controller_generationwrite
with itslast_controller_owner; neither half can move alone, matching the
PanelRecordcontract at:621-656and theN-13fence in
capture_rebind_source(:3524-3560, tombstone accepted only when
ended_generation == last && owner == last_owner). - Validate-then-commit: in the keep branch nothing can fail (no tombstone write,
no pair write), so no partial commit exists; on the non-keep branch
retain_grant_ceilingstill runs before the pair write and row removal and
returnsPanelError::ResourceExhaustedwith the live row, the pair and every
other family intact (:3142-3152).dispose_panelpropagates it before its
own teardown (:2172). - Refusal variants exercised by the new tests:
PanelError::CeilingLost { panel_id, bind_generation, last_controller_generation, tombstone_generation }
(tests/panel_generation_ownership.rs:474-484), pluserror_count/
controller_generation == Noneassertions proving the refusal committed
nothing (:485-490). - One owner per panel:
panels_ended_at(:3355-3375) filters on the retained
pair, andpanels_bound_toremains its complement; the test asserts both
(tests/…:397-410,:424-431).
Two behavioural notes, both acceptable and neither a violation: the epoch edge
no longer copies the epoch row's grants into a tombstone (pre-fix the successor
could inherit {panel.focus} that no controller held — the fix removes that
widening), and a repeat of a generation edge now returns Ok(false) instead of
StaleHandle because the kept tombstone names it (idempotence, which is what
A.2 phase-1 repetition expects).
5. MSRV 1.85 — PASS
No let-chains and no if let match guards in the added code: the only new
conditions are if bound.is_some() || record.last_controller_generation.is_none()
(:3087) and !ends_bound_controller && last_ended.is_some() (:3137); the
match on the record (:3054-3069) has no guards. No new #[cfg] items.
Executed in the copy, fresh target dir, files touched so the crate re-checked:
$ CARGO_TARGET_DIR=/tmp/hermes/pr3150-revert/target-msrv cargo +1.85 check -p bitty-runtime --tests --offline
Checking bitty-runtime v0.0.41 (/tmp/hermes/pr3150-revert/pr/crates/bitty-runtime)
Checking bitty-terminal v0.0.41 (/tmp/hermes/pr3150-revert/pr/crates/bitty-terminal)
Finished `dev` profile [unoptimized + debuginfo] target(s) in 3.12s
(cargo +1.85 --version = cargo 1.85.1 (d73d2caf9 2024-12-31).)
6. Lint — PASS
$ CARGO_TARGET_DIR=/tmp/hermes/pr3150-revert/target cargo clippy -p bitty-runtime --all-targets --offline -- -D warnings
Checking bitty-runtime v0.0.41 (/tmp/hermes/pr3150-revert/pr/crates/bitty-runtime)
Checking bitty-terminal v0.0.41 (/tmp/hermes/pr3150-revert/pr/crates/bitty-terminal)
Finished `dev` profile [unoptimized + debuginfo] target(s) in 4.66s
No warnings. Bonus: cargo fmt --check -p bitty-runtime prints nothing
(clean).
7. Hygiene — PASS
Diff scanned for dbg!, println!, eprintln!, #[allow, unwrap(),
absolute host paths (/home/, /Users/), usernames, localhost, 127.0.0.1
and fixed ports: the only hits are .expect("…") in the test file (legitimate
assertions). No #[allow(...)], no #[cfg(...)] added. All added comments and
rustdoc are English and explain the mechanism (the keeps_controller_predecessor
block at :3120-3136 and the rustdoc at :2969-2996), and the record-field
docs (:618-656) were updated in the same commit, so no comment now contradicts
the code.
8. Docs / docs-claims — PASS (draft drift noted, no edit made)
bitty-docs + bitty-terminal-docs grepped for last_controller_owner,
panels_ended_at, allocation epoch, retired-ceiling, tombstone, OQ-084,
2476.
- The accepted corpus does not describe this rule:
bitty-terminal-docs/ specifications/panel-runtime-rfc.md(status: accepted) contains no
predecessor/tombstone/last-controller text;bitty-docs/docs/decisions/adrs/ ADR-0013-core-ontology-identity.mdandopen-questions.md(OQ-084) only fix
ontology terms;bitty-docs/docs/security/README.md(status: accepted) is an
index line with no mechanism detail. - Drift, in a draft document only:
bitty-terminal-docs/specifications/ panel-generation-ownership-decision.md(status: draft) still lists
"(a) The allocation-epoch edge inherits the previous controller's owner" as an
open follow-up (:458-467, "the field's contract and the write disagree; one
of the two must move") — this PR moves the write, i.e. closes (a) — and the
summary row at:383describesrelease_generation_scopeas stamping the pair
"from the binding before releasing it" without the 7(f) exception. Its
panel.rsline citations (:622,:638,:2964,:3044,:3146, …) are
already stale against this head.
Not blocking (draft, forward-only), but a follow-up should close (a) and
refresh the row.
Non-blocking observations
- Reachability caveat in §2: the fixed invariant has no surviving-panel
production caller yet; onlydispose_panelreaches the epoch edge, and it then
removes the record. The invariant is still worth landing (it makes thepub
method self-consistent withpanels_ended_at/capture_rebind_source), but the
commit message overstates the present-day blast radius. already_ended's newrelease_recordsclause (:3071-3074) widens the
pre-fence acceptance window for an unbound panel to "this generation's edge
already ran", returningOk(false)and removing any row keyed by that
generation. It is the same shape the pre-existinglast_ended == Some(generation)/tombstone_names_generationtests had, only now
reachable for the epoch edge on a previously-bound panel; no live binding is
reachable from it (the clause is excluded wheneverbound.is_some()).- Draft-spec drift in §8 — fix-forward, no edit made per instructions.
Verification summary
| Check | Result | Anchor |
|---|---|---|
| 1 claim vs code | PASS | panel.rs:3119, :3137, :3142-3162, :3071-3074 |
| 2 reachability | PASS (caveat) | panel.rs:2172 ← host.rs:388 ← scene_host.rs:493/517/545 |
| 3 test discrimination | PASS (3 red on revert) | tests/panel_generation_ownership.rs:305, :402, :470 |
| 4 invariants | PASS | panel.rs:3094-3101, :3142-3152, :3524-3560 |
| 5 MSRV 1.85 | PASS | cargo +1.85 check … --tests --offline finished clean |
| 6 clippy -D warnings | PASS | clean, no warnings |
| 7 hygiene | PASS | no allow/dbg/println/host-path/cfg additions |
| 8 docs | PASS (draft drift noted) | panel-generation-ownership-decision.md:383, :458-467 |
VERDICT: APPROVE
[CTX-1821] fix(runtime): keep the controller predecessor pair across an allocation-epoch edge (bitty#2476 7f)
PanelRegistry::release_generation_scope(crates/bitty-runtime/src/registry/panel.rs)ends every generation edge, and its non-repeat path wrote the controller
predecessor pair unconditionally:
generationis the panel's binding-key generation: the bound controllergeneration when one is bound, otherwise the allocation epoch. So an edge that
ends the allocation epoch (no controller bound) overwrote the pair a controller
edge had stamped with
(None, epoch).panels_ended_at(owner, generation)(panel.rs:3355) is then the only query that can still name the ended
generation — the release cleared the binding — and the generation edge's
successor enumeration (
bind_successor, crates/bitty-terminal/src/plugin_runtime.rs)enumerates exactly that set, so the container was never rebound. The pair and
the tombstone must be understood together:
PanelRecord::last_controller_owneris documented as "written and retained with
last_controller_generation, neveron its own", and
N-13keys the tombstone by the same pair, so an epochtombstone written over the controller's would leave the retained pair
unreadable at phase 0 and refuse the successor's own bind as
CeilingLost.What changed
release_generation_scopenow separates the two edges it can be handed:bound == Some(generation)) writes the pair and thetombstone exactly as before;
(
!ends_bound_controller && last_ended.is_some()) writes neither halfand keeps the controller's tombstone. The epoch is never a controller
generation (B.1/B.2), so it has no predecessor fact of its own to record.
Every other effect is unchanged: the live row keyed by
generationis stillreleased, the epoch row is still swept on a controller edge, the queued
events/commands/overlays are still drained, and the
GenerationReleaseRecordis still written;
still stamps the epoch as that panel's first, ownerless predecessor. That is
where a never-bound panel's ceiling comes from, and it is what the existing
grant-ceiling tests read.
The repeat branch got the same rule, and the duplicate is now also recognised
from the
GenerationReleaseRecordthe first pass wrote: an epoch edge that kepta controller predecessor leaves no tombstone of its own to be named by, and the
retained pair names the controller, so neither previous test could see the
repeat. Without that, a repeated epoch edge would re-run the non-repeat path and
overwrite the release record the docs say it must leave untouched.
Docs corrected to match:
PanelRecord::last_controller_generation,PanelRecord::last_controller_owner,PanelRegistry::last_controller_owner,and
release_generation_scopeitself.A/B revert proof
With the production hunk reverted in place (
git checkout -- ...panel.rs, testskept) the three tests below fail; with the hunk restored they pass.
New tests (crates/bitty-runtime/tests/panel_generation_ownership.rs), all
public-API only, no sleeps, no private-field access:
an_allocation_epoch_edge_keeps_the_controller_predecessor_pair— controlleredge then epoch edge: the pair still names
(acme.notes, N), the tombstone isstill the controller's, the epoch row is released, the release record is
written, and the epoch edge's repeat is inert.
an_allocation_epoch_edge_leaves_the_container_enumerable_for_its_successor—same sequence:
controller_generationisNone,panels_bound_tois empty,panels_ended_at(acme.notes, N)yields the panel, and a later legitimatesuccessor bind is accepted, bounded by
N's ceiling, after which the panelappears in
panels_bound_to(acme.notes, N+1)and not inpanels_ended_at.a_bind_after_an_allocation_epoch_edge_reads_the_controller_it_names— thebind after the epoch edge is measured against the controller that actually
ended: provenance names
(acme.notes, N), another plugin is refusedCeilingLost(the pre-existing cross-plugin fence,N-13), and thepredecessor's own owner still binds.
Tests whose expectations had to be re-read
#3149(CTX-1820) fixed residual 7(a) by making the epoch edge stamp(None, epoch)and key the tombstoneNone, and two tests intests/panel_generation_ownership.rspin that ordering. That ordering is what7(f) reports as the defect, so both expectations were re-read against the field
docs rather than kept:
an_allocation_epoch_edge_retains_no_owner_from_the_previous_edgeassertedlast_controller_owner == Noneandlast_controller_generation == Some(epoch)after an epoch edge.last_controller_owneris "the plugin thatowned the most recently ended controller generation", and
last_controller_generationis "the most recently ended controllergeneration" — the epoch is never a controller generation (B.1/B.2), so an
epoch edge ends no controller generation and has nothing to stamp. Rewritten
as
an_allocation_epoch_edge_keeps_the_controller_predecessor_pair: the pairstill reads
(acme.notes, N)and the tombstone is still that pair's. 7(a)'sreal invariant — no half-copied pair, i.e. an owner from one edge beside a
generation from another — is asserted head-on and still fails for the
pre-
#3149bound_owner.or(last_ended_owner)code.a_bind_after_an_allocation_epoch_edge_is_not_measured_against_the_previous_ownerasserted that the bind after an epoch edge is bounded by the epoch's tombstone
and that another plugin may bind. That only held because the epoch edge had
erased the controller predecessor; with the pair intact the record's
predecessor is the controller generation, so its own owner binds against its
ceiling and a different plugin is refused
CeilingLost, exactly as after anycontroller edge (
a_bind_by_another_owner_is_refused_as_a_lost_ceiling).Rewritten as
a_bind_after_an_allocation_epoch_edge_reads_the_controller_it_names.No assertion was weakened: each rewritten test fails for the code it describes
as broken, and the two
#3149intents they encoded (no mixed pair; no phantomowner refusing a legitimate bind) are asserted by the replacements.
Behaviour deliberately left alone: on a panel with no controller
predecessor, an epoch edge still stamps
(None, epoch)and its tombstone, so anever-bound panel's first bind keeps reading that ownerless ceiling
(
tests/panel_grant_ceiling.rs::panel_after_an_epoch_edge_and_a_controller_bindand the in-module
an_unbound_panel_mounts_through_its_allocation_epoch_exactly_as_before).Gates (from the worktree, CARGO_TARGET_DIR=.targets/ctx-1821)
cargo fmt --all -- --checkcargo clippy -p bitty-runtime --all-targets --offline -- -D warningscargo test -p bitty-runtime --offlinecargo +1.85 check -p bitty-runtime --tests --offlineRUSTDOCFLAGS="-D warnings" cargo doc -p bitty-runtime --no-deps --offlineNote on gate 3:
plugin_runtime::spawn::tests::admitted_git_spawn_runs_under_inherited_confinementfails on this host when
PATHcarries more thanMAX_PATH_SEARCH_DIRS(64)entries, because
gitsits past the cap; it is unrelated to this change andpasses with a normal
PATH. It also passed on the first full run before ashell had grown
PATH.Refs #2476
Summary by CodeRabbit