Repository navigation
Give each Bridge its own Metadata store - #119
Conversation
Co-Authored-By: Claude Sonnet 5 <[email protected]>
Routes production reads through MetadataView (`bridge.metadata_view()` / `H::metadata(cx)`) the same way Person already does, instead of calling `crate::metadata::<state fn>()` directly: - ViewState's D6.5 fifth-owner-callback threading (viewstate.rs, stores/viewstate.rs, stores/mod.rs) so `SetWatchedLocal` lands through the owner rather than the free `apply`. - app/playback.rs, app/run.rs (Frame::begin now samples the HUD control slot through the owner), app/input.rs, dev/scenarios.rs, app/bridge.rs's page_probe. - A new `MetadataLike` trait (screens/registry.rs, mirroring `PersonLike`) plus its `AppHost` impl, for screens generic over `H` where `H::Views<'a>` is opaque: tracks_panel.rs, item_menu.rs (added `MetadataView::alt_copies`-style forwarding), alt_sources.rs (added `MetadataView::alt_copies`/`alt_available`), screens/player/overlay.rs and ui/info_panel.rs's Info card (now threaded a `MetadataView` parameter into `on_ok`/`draw`). - Removed the now-satisfied `#[allow(dead_code)]` on `MetadataView`'s `now_playing`/`playing`/`active_marker`/`synthesized_tail_marker`, on `AppViews.metadata` and on `Bridge::metadata_view`. Left reading the static directly, because no accessible `Cx`/owner reaches them without a much larger refactor of their own private call graphs: screens/detail/mod.rs and detail/episodes.rs (a ~30-site `self.detail()` fan-out with no H in scope), ui/track_menu.rs's `TrackMenuState` (11 sites through a cx-less `tracks()` helper, cx-less at construction), and ui/info_panel.rs's `is_episode()`/`actions()` (called from cx-less methods). These stay `&'static` reads exactly as before (Stage A/D4's behaviour-preserving leak) and are Stage B/follow-up work, not invented here. Gates green: cargo +nightly check --lib (default and --no-default-features), make check (both feature passes + lint), ci/check-deps.sh. Co-Authored-By: Claude Sonnet 5 <[email protected]>
…ugh the owner view
Routes the last cx-less production readers of the metadata statics through
MetadataView, closing the gap A2 left open:
- screens/detail/mod.rs's detail() and episodes.rs (the ~30-51-site
self.detail() fan-out) already converged on a single choke point per
static call, so no per-call-site threading was needed — each bare
crate::metadata::{current,season_loading,detail_loading,
detail_request_status,alt_available}() call became
crate::metadata::MetadataView::new().<method>() at its existing choke
point (detail(), or the bare call itself where there was no wrapper).
Approach chosen: capture at the existing single choke point, not thread
cx through dozens of cx-less helper signatures — matches Stage A's own
module doc, which already sanctions MetadataView::new() as the
zero-argument, forward-compatible construction (stores/metadata.rs's
MetadataStore::view, item_menu.rs/tracks_panel.rs/alt_sources.rs test call
sites already do this).
- ui/track_menu.rs's tracks() (11 downstream call sites) — same
choke-point rewrite.
- ui/info_panel.rs's is_episode() (2 sites) — same choke-point rewrite,
now reading both now_playing() and current() off one MetadataView value.
- metadata.rs: dropped the now-stale #[allow(dead_code)] on
season_loading/detail_loading/detail_request_status/alt_available, which
A3 makes reachable through MetadataView.
Statics stay in place; behaviour-preserving. One known-scope residual:
ui/player_hud.rs:1326 still reads crate::metadata::now_playing()
directly — not in this stage's listed scope (draw_hud has no cx/H and no
MetadataView parameter today; D2's plan for it is later work).
Gates green: cargo +nightly check --lib (default and
--no-default-features), make check, ci/check-deps.sh.
Co-Authored-By: Claude Sonnet 5 <[email protected]>
MetadataView<'a> now borrows its owner's MetadataStore instead of being constructible from nothing: MetadataView::new(&'a MetadataStore) -> Self is the only constructor, and MetadataStore::view(&self) -> MetadataView<'_> is the accessor. Every production reader gets a view through H::metadata(cx) (the MetadataLike trait, reachable) or by threading an explicit meta: MetadataView<'_> parameter down from the nearest caller that has one (not reachable). Test code constructs a fresh owner (MetadataStore::default().view(), or a static MetadataStore for a fixture Host's MetadataLike impl) exactly as Person's tests already do. screens/detail/mod.rs's memory_at has no cx/H in reach at all (it's called through dyn Screen<H> from ui/dispatch.rs and app/bridge.rs, a signature shared verbatim by every other screen) so it constructs its own owner locally rather than widening that trait, which is out of this layer's scope. Behaviour is unchanged; the statics MetadataView still reads stay until Stage B deletes them. Co-Authored-By: Claude Sonnet 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Em5yYDNi5A2peYR6oPMXwD
Stage B deleted the metadata statics, so MetadataStore::default() in
memory_at (and the now-false "until Stage B deletes them" comment above
it) answered from a permanently empty store: locate/hero_set/detail all
blank, collapsing season/section/col memory to (0, 0, None) on every
BACK.
Per Opus decision D7: memory_at now reads a cached SpotFacts { detail,
tracks, hero, season }, refreshed only where a real MetadataView is in
hand (tick, draw, end of sync_keys). spot() loses its meta parameter
and takes SpotFacts instead; locate() is now a one-line wrapper over
the new locate_with(elem, detail, tracks) which needs no view at all.
Co-Authored-By: Claude Sonnet 5 <[email protected]>
…leted metadata shims MetadataStore::state_mut() (test-only, mirrors HubsStore::state_mut) and split_for_test() (state_mut + adapter_ref borrowed together, for _for_test helpers that take both) are the only new owner-accessor surface; every rewritten call site still goes through run()/state_mut()/adapter_ref()/view(), never a second mechanism. screens/detail/tests.rs drove one screen per test through free helper fns (install/step/apply_metadata/...) written for the old global CURRENT static and the deleted stores::metadata::apply shim. Since the file calls MetadataStore::default().view() (and the old free-function reads) at ~90 individual call sites rather than through a handful of helpers, threading an owned store through every call site the way stores/person.rs's tests do would have rewritten most of the file. Instead the owner now lives in a thread-confined cell (`test_store()`), reset per test the same way the old global was, and a mechanical perl rewrite retargeted every call site at once; a handful of signature changes (pump_restore now taking fx, land_detail_for_test taking state+adapter, spot() taking SpotFacts) were fixed by hand. Co-Authored-By: Claude Sonnet 5 <[email protected]>
…rs test fixtures Same TEST_METADATA_STORE-as-unit-struct pattern as screens/detail/tests.rs, fixed the same way: a thread-confined MetadataStore behind test_store(), reached only through run()/state_mut()/view(). Co-Authored-By: Claude Sonnet 5 <[email protected]>
…ply tests metadata.rs: land_detail_for_test forwarded a plain &MetadataAdapter into pump_detail -> install_landed_detail -> request_alt_sources, which clones the Arc to spawn a resolve worker — a real Stage B signature bug, not a test-only mismatch. Fixed by taking &Arc<MetadataAdapter> throughout (and MetadataStore::split_for_test to match); the module's own trailer_now_playing_keeps_the_parent_and_the_extra_duration test now owns a local MetadataState instead of calling the deleted 1-arg set_current_for_test/free trailer_now_playing. stores/mod.rs: deleted a_command_raises_one_notice_and_a_steady_store_none and generic_dispatch_rejects_all_physically_owned_stores — both graded the free apply()/take_notices()/gen() dispatcher, which no longer exists anywhere in production code now that every store (Metadata included) dispatches through its own owner. Co-Authored-By: Claude Sonnet 5 <[email protected]>
…tadataState/Arc<MetadataAdapter> Same reasoning as screens/detail/tests.rs's TEST_METADATA: these fixtures are called as free, argument-less functions from hundreds of call sites in the three split metadata test modules, a shape written for the old CURRENT/SEASON_GEN statics. Threading an owner through every call site would rewrite most of those files for no behavioural change, so the pair now lives in a thread-confined cell here, reached only through the real accessors (current, land_detail, MetadataState/MetadataAdapter's own fields) — never a second mechanism. Co-Authored-By: Claude Sonnet 5 <[email protected]>
Same thread-confined MetadataStore pattern as screens/detail/tests.rs, plus a local land_detail_for_test(sid, rk, gen, detail) wrapper matching the pre-Stage-B 4-argument shape so the ~9 multi-line call sites below needed no per-site rewrite. Co-Authored-By: Claude Sonnet 5 <[email protected]>
Co-Authored-By: Claude Sonnet 5 <[email protected]>
Finishes the 8 files named in the Stage C1 map: app/detail_panel_tests.rs, app/viewstate_directory_policy_tests.rs, screens/detail/hero.rs, and ui/info_panel.rs now route through the real per-Bridge `rig.stores.metadata` (where a Bridge is already in scope) or a thread-confined test store (where it is not), instead of the deleted `crate::stores::metadata::apply` shim or a throwaway `MetadataStore::default()` that silently read back nothing. Also fixes the free `crate::stores::take_notices()`/`crate::stores::apply()` callers left behind by the same cutover in app/bridge_test_support.rs, app/surface_navigation_tests.rs, app/search_publication_tests.rs, and screens/library/deferred_tests.rs (routed onto the real `Stores` aggregate already in scope), and adds the missing `MetadataLike` test impls in screens/about_panel.rs, screens/player/mod.rs, and ui/chapters_panel.rs. Co-Authored-By: Claude Sonnet 5 <[email protected]>
…data dispatcher viewstate.rs's optimistic-edit tests routed their MetadataCmd closure through a fresh MetadataStore::default() per call (a throwaway store, so the following crate::metadata::current()/take_notices() read-back saw nothing); each test now owns one MetadataStore for its whole body and reads/writes through it directly. focusprobe.rs's fingerprint() gained a MetadataView parameter in the Stage B/C1 cutover; every call site (and the one closure wrapping it) now threads a thread-confined test store's view through, mirroring the pattern already used in screens/detail/tests.rs and friends. Co-Authored-By: Claude Sonnet 5 <[email protected]>
…s/apply Same shape as the earlier detail/tests.rs port: swaps the dead unit-struct static MetadataStore for a thread-confined store, adds the missing spot_facts field to the DetailScreen test fixture, and threads state/adapter through set_current_for_test/land_detail_for_test/begin_detail_for_test/ detail_request_status wherever the old free-function shape called for it. Co-Authored-By: Claude Sonnet 5 <[email protected]>
… script) This submodule of metadata.rs read the pre-Stage-B crate-global detail/alt mailbox statics (DETAIL_LANDING, DETAIL_GEN, DETAIL_DONE, ALT_GEN, ALT_ROSTER_GEN, ALT_SLOT) and called free functions (clear, land_detail, pump_detail, current, detail_loading, alt_install, alt_available, pump_alt_sources, request_detail_with_spawn, finish_detail_fetch, detail_request_status, begin_detail_for_test) at their old, state-less arities. One perl script threads metadata_test_support's test_state()/ test_adapter() through every call site and rewrites the deleted statics to the equivalent MetadataAdapter fields (this file is a descendant module of metadata.rs, so it can see them) — no per-site hand edits. Co-Authored-By: Claude Sonnet 5 <[email protected]>
metadata_season_mailbox_tests.rs and metadata_watch_state_tests.rs: same mechanical test_state()/test_adapter() threading as the detail mailbox file, one perl script each. metadata/record.rs's replay-recorder tests (p2_* cancellation/replay tests, the malformed-batch and float-bits round-trip tests) needed the same threading plus one real gap: the old crate-global `reset(bool)` free function that rearmed the shared TRACKER has no Stage B equivalent, since the tracker is now owned per-adapter with no reset seam (production never resets one after boot). Added a local test-only `reset(bool)` that overwrites the owned Tracker directly through the already-private `tracker(adapter)` accessor (this file is a descendant of crate::metadata, so it can reach it) rather than inventing a second mechanism. This closes out Stage C1's test-compilation debt: `cargo +nightly check --lib --tests` is clean. Co-Authored-By: Claude Sonnet 5 <[email protected]>
The prior mechanical port had routed this module's metadata calls through the thread-confined test_store() double instead of rig.stores.metadata -- the same store the module's real, mounted DetailScreen actually reads via bridge::frame(). That disconnection made 7 of 10 tests fail at runtime (the mounted screen's `current`/`detail_request_status` never reflected what the test wrote). Fix: shadow land_detail_for_test/drain_detail_workers inside this module to take `rig: &mut bridge::Bridge` and route through `rig.metadata_mut()`, and give the two Tap<AppHost> structs (SettleDetailBeforeRestoredEnter, AtomicStart) a `*mut MetadataStore` captured from `rig.metadata_mut()` just before the frame_with_tap call that invokes them, since Tap::effect has no rig parameter by design. 8/10 tests now pass. The remaining 2 failures (a_covered_detail_refresh_waits_until_its_page_owns_metadata_again, visible_refresh_starts_before_queued_tick_or_store_change_can_consume_it) now exercise the REAL DetailScreen's behavior for the first time and disagree with their pinned generation-count/status expectations -- this looks like the reconnection surfacing a real behavioral difference, not a wiring bug, and needs domain review rather than a mechanical fix. Co-Authored-By: Claude Sonnet 5 <[email protected]>
…names The route-unconditional per-frame pump text-pin still checked for the old free-function call shape (crate::stores::metadata::pump_detail()/ pump_season()), but Stage B moved the real call site in app/run.rs to the per-Bridge owned methods (app.bridge.metadata_pump_detail()/ metadata_pump_season()). The pin never updated, so it always panicked. Co-Authored-By: Claude Sonnet 5 <[email protected]>
Three call sites built a fresh, empty MetadataStore::default().view() to seed/refresh AltSourcesScreen's materialized table, instead of the same thread-confined test_store() the test's alt_install/alt_restamp_owners calls actually write to -- the same disconnected-throwaway-store bug as D7, just in a different file. MetadataStore::default() is a genuinely new owner post-Stage-B, not an alias for a shared global, so the panel always saw an empty store. Co-Authored-By: Claude Sonnet 5 <[email protected]>
an_open_request_does_not_outlive_its_page discarded the effects Unmount returned instead of applying them, so `test_store()` still held the Detail this page had just unmounted from -- the page's next press still resolved the same Related row and pushed again, when the whole point of the test is that it should not. A real Bridge applies AppFx::Store effects on its next dispatch turn; this file drives no dispatcher, so it has to do that itself. Added apply_metadata_effects() for it. Co-Authored-By: Claude Sonnet 5 <[email protected]>
DetailScreen::new() never touches the metadata adapter -- the fetch starts on the mounted page's first Enter (ScreenEvent::Enter pushes MetadataCmd::RequestDetail as an effect, admitted in the same step that publishes Requested, per T2). This test asserted detail_loading() right after construction, which only worked before this event moved fetch-start off construction and onto Enter. Drive Mount then Enter and apply the resulting effect before checking. Co-Authored-By: Claude Sonnet 5 <[email protected]>
Both request paths Enter can take (the direct RequestDetail push and start_reconciliation's own) only enqueue the command for a real Bridge's next dispatch turn; this truth-table test drives no dispatcher and was reading detail_generation_for_test() right after step() without ever applying the effect it returned, so the very first combination (cached= false, phase=None, status=None) already failed. Same missing-effect- application gap as the two fixes just before this one. Co-Authored-By: Claude Sonnet 5 <[email protected]>
controlled_cancelled_detail_ack_is_recorded_and_recovers_capacity expects crate::app::bootstrap::stores to observe cancelled-completion recordings, which only happens while this adapter's own Tracker.enabled is true. Before Stage B, Tracker was one crate-global static, and record.rs's own mod tests armed it once via a pub(crate) reset(bool) any test in the binary could reach (and never explicitly disarmed) -- so this test worked only by relying on some other test in the same binary having left the single global Tracker enabled. Post Stage B each MetadataStore owns its own Tracker starting disabled, so that implicit cross-test leakage is gone (as it should be) and this test never enables it at all. Added record::reset_tracker_for_test (pub(super), reachable from every metadata_*_tests.rs sibling, not just record.rs's own mod tests) and had this test call it. This gets the test substantially further (the "results recorded" assertions this note names now pass); a further mismatch inside the REPLAY phase's publish_replies/pump_detail interaction (`replay grades the ACK it actually applied` at line ~562, left:[] right: one dropped- terminal record) remains and needs a domain-level read of record.rs's replay path, not a mechanical fix -- left red and documented for review. Co-Authored-By: Claude Sonnet 5 <[email protected]>
Missed by the earlier mechanical sweep because this module (activate_card_ tests) only compiles under --features hostsim, which the default `cargo test --lib` run never exercises -- ci/check-deps.sh's metadata-owner gate caught the leftover crate::stores::metadata::apply(...)/free-function detail_loading() call sites. Routed both through the real, already- constructed bridge (bridge.metadata_mut()) instead of adding a disconnected test double, since this test already drives one. Co-Authored-By: Claude Sonnet 5 <[email protected]>
Only one of the three is landed here. `controlled_cancelled_detail_ack_is_ recorded_and_recovers_capacity` was a fixture gap, not a product defect: before Stage B, `bootstrap::stores::init` ended with `crate::metadata::record::reset(initial.content.is_some())`, so re-entering the controlled domain for the replay run rewound the one crate-global TRACKER. Stage B deleted that line along with the static, and `init` cannot reach a per-owner adapter, so the replay phase inherited the recording phase's seq=8 and `publish_replies` rejected the first supplied batch (seq=1) as "incoherent detail reply sequence" — `take_results()` answered `[]`. The fixture now does the rewind itself; every assertion is unchanged. The other two are one product regression and are NOT fixed here: Stage A/B moved Metadata's screen-issued commands from a synchronous `apply` onto the deferred `AppFx::Store` queue, and three properties depended on that synchrony. See the handback for the evidence and the decision that is needed. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Em5yYDNi5A2peYR6oPMXwD
… the request Metadata was the one owned store without the synchronous same-turn boundary its siblings have at `app/bridge.rs` (`browse_run`, `person_run`, `viewstate_run`). Stage A/B left that gap, and `app::content::refresh_content` fell back to the deferred `AppFx::Store` queue for the one call that cannot tolerate deferral: the visible reconciliation start, whose `DetailRefreshPhase::Requested` becomes observable two queue hops before the store admits the request. A `Tick` or `StoreChanged` landing in that window reads the PREVIOUS reconciliation's terminal `Some(false)` and `pump_restore` drops the server obligation outright (trap T2, pinned by `visible_refresh_starts_before_queued_tick_or_store_change_can_consume_it`). - `Bridge::metadata_run` — the missing sibling, delegating to the `Stores` method that already existed. - `refresh_content` takes the `Bridge` and runs `RequestDetail` through it in the same synchronous step that emits `DetailRestore`. Covered entries still arm `Deferred` and start nothing, so a covered page cannot supersede the visible one's in-flight request. Screen-issued Metadata commands that are not same-turn boundaries stay on `AppFx::Store`. - `DetailScreen`'s `DetailRestore` arm records `Requested` instead of starting a second, non-idempotent request against an address the caller already admitted. - `teardown_cleared` latch: §3.4's `pop_sequence` delivers `WillLeave(ForGood)` AND `Unmount`, and with the store owned per `Bridge` the first `Clear` is still queued when the second event reads the guard, so one teardown emitted two `Clear`s and two `supersede_detail` generations. - `DetailScreen::reconcile` weighs the page's own undischarged `refresh` obligation beside the store's answer. The `Enter(Restored)` promotion of a covered page's obligation is screen-issued and cannot be made same-turn — `Cx` publishes stores as views — and the engine's `after_step` reconcile runs before the drain reaches that effect, so reading the store alone dropped the restored episode key to the hero fallback for one frame, after which it is unrecoverable. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Em5yYDNi5A2peYR6oPMXwD
…d test start_reconciliation (Enter(Restored)'s promotion of a Deferred obligation to Requested) pushes RequestDetail onto the deferred AppFx::Store queue and flips self.refresh synchronously in the same step, but the store only admits that command on a later drain iteration. A StoreChanged/Tick landing in that window still sees the stale terminal from the PREVIOUS reconciliation at that address, and pump_restore's (Requested, Some(false)) arm silently retires the freshly promoted obligation. Confirmed as a real defect (test goes red against unmodified code), but closing it needs Cx/Rig widened so a screen can write a store synchronously from step, the way app::content::refresh_content does at the Bridge level for the sibling DetailRestore path. That is an architecture change, not a Metadata-layer fix, so the test is left #[ignore]d and documented rather than fixed or weakened. Co-Authored-By: Claude Sonnet 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Em5yYDNi5A2peYR6oPMXwD
Two independently-owned MetadataStores must share no request, landing or notice generation. Mirrors HubsStore's own two-owner test shape. Checked by hand (not left in the tree) that routing one owner's begin_detail_for_test through the OTHER owner's adapter_ref() — the shape a shared/global adapter would have produced before this layer's ownership port — makes the first cross-owner assertion go red, so this is not an assertion that would also pass against the broken shape. Co-Authored-By: Claude Sonnet 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Em5yYDNi5A2peYR6oPMXwD
cancelled_focus_restoration_still_terminates_reconciliation_on_success_or_failure (screens/detail/tests.rs, landed with ViewState's refactor at 4b390cd) already exercises T1 exactly: directional input cancels restore_intent, the refresh obligation must survive that cancellation, and the store's own terminal landing (not the cancellation) is what retires it. Confirmed meaningful by mutation — folding self.refresh into the same directional-input cancellation guard the intent uses turns this test red — then reverted the mutation (no diff) rather than leaving it in the tree. Doc comment now names it as the contract's T1 pin so it is not lost again. Co-Authored-By: Claude Sonnet 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Em5yYDNi5A2peYR6oPMXwD
…gression) bootstrap::stores::init ended with crate::metadata::record::reset(initial .content.is_some()) at d067a79; Stage B (0d46652) deleted that call along with the crate-global TRACKER static it reset, and nothing armed the per-owner replacement in production. Bridge::controlled_home built its MetadataStore with Tracker::new(false) permanently, so every controlled- content detail landing produced no recorded terminal at all while the tape was active, and the device-side validator rejected the resulting {"data":[]} as "noncanonical detail replies" — recording of detail terminals was dead. Adds crate::metadata::record::arm (production, not #[cfg(test)]) and MetadataStore::arm_detail_tracker, called once from Bridge::controlled_home right after Stores::default() with initial.content.is_some(), exactly the decision record::reset used to make. Pinned by app::bootstrap::tests::controlled_home_arms_the_detail_tracker_when_content_initial_is_present, which lands a detail terminal through the Bridge's own owned store and checks bootstrap::stores::take_results() is non-empty; confirmed load-bearing by removing the wiring call and observing the dead-code deny fail the build. Co-Authored-By: Claude Sonnet 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Em5yYDNi5A2peYR6oPMXwD
stores/mod.rs's module doc (:4-6, :14-15) still said Metadata/Search/Hubs "retain the compatibility global + mailbox shape" and that apply(cmd) "rejects Browse, Person and ViewState commands" -- both false now (the generic apply(cmd) dispatcher is gone entirely; grepped for stores::apply and fn apply( across stores/ to confirm). docs/stores-as-machines.md and ui/CLAUDE.md's phase-4 paragraph carried the same claim about Metadata's mailboxes/adapter still being process-wide compatibility state. Corrected the false clauses in place; left the surrounding historical/dated narrative alone (docs the layer makes false are in scope, not a rewrite). Co-Authored-By: Claude Sonnet 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Em5yYDNi5A2peYR6oPMXwD
`pump_restore`'s (Requested, Some(false)) arm retired the reconciliation obligation on a bare terminal bool with no identity, so a stale terminal left by an OLDER request at the same (sid, rk) — reachable whenever Enter(Restored) promotes Deferred->Requested and the queued RequestDetail has not yet been admitted to the store — could drop a freshly promoted obligation. The previous stage's #[ignore]d test proved this is real. Fix: MetadataView::detail_generation() exposes the adapter's detail_gen counter (mirrors the generation check completions already use for T3). DetailScreen now records self.refresh_gen — the generation that existed just BEFORE this promotion's own request is admitted — at both places refresh becomes Requested (start_reconciliation's queued path, and the DetailRestore arm's already-admitted synchronous path). pump_restore only retires the obligation once the store's current generation is strictly newer than that recorded value, so a stale terminal from before admission can no longer be mistaken for this request's own terminal. Un-ignores enter_restored_promotion_survives_a_stale_terminal_before_admission_t2; verified red again with only the pump_restore generation check reverted. Co-Authored-By: Claude Sonnet 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Em5yYDNi5A2peYR6oPMXwD
Resolves the ownership/feature collision: threaded MetadataView through reconcile/record_stops/preview_extra/content_top/preview_tick and fixed the non-conflicting test call sites #117 added against the pre-ownership signatures. No process-wide state, no throwaway MetadataStore::default() reads, and the T2/T3 generation-identity fix in pump_restore/refresh_gen is untouched by the merge. Trailer transport (trailer.rs) reads no Metadata store directly and does not change the detail item, hero set, or season, so it owes no new SpotFacts write. Co-Authored-By: Claude Sonnet 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Em5yYDNi5A2peYR6oPMXwD
There was a problem hiding this comment.
🟡 Changes recommended
Unresolved critical and moderate review findings remain.
Get a fresh assessment by requesting another Copilot review.
Pull request overview
This PR moves Metadata state and workers from process-wide globals to per-Bridge ownership, with lifecycle fixes, updated consumers, tests, and dependency checks.
Changes:
- Adds
MetadataStoreownership and removes global Metadata dispatch. - Threads owner-specific metadata through UI, screens, playback, and tests.
- Adds generation fencing, teardown latching, tracker restoration, and CI enforcement.
Review findings: critical (1 vote) issues remain in detail test call sites and Metadata reset/fencing; moderate (1 vote) issues remain in playback server selection and duplicate detail requests; nit (1 vote) documentation is stale.
File summaries
| File | Reviewed change |
|---|---|
rust-modules/src/viewstate.rs |
Routes optimistic metadata edits through the owning store. |
rust-modules/src/ui/track_menu.rs |
Uses owner-borrowed metadata for track data. |
rust-modules/src/ui/player_hud.rs |
Uses owner metadata for markers and chapters. |
rust-modules/src/ui/info_panel.rs |
Uses owner metadata for actions and labels. |
rust-modules/src/ui/CLAUDE.md |
Documents store ownership. |
rust-modules/src/ui/chapters_panel.rs |
Threads metadata ownership through chapter UI. |
rust-modules/src/stores/viewstate.rs |
Propagates metadata callbacks through ViewState. |
rust-modules/src/stores/mod.rs |
Integrates Metadata into Stores and removes global dispatch. |
rust-modules/src/screens/tracks_panel.rs |
Reads metadata through the host owner. |
rust-modules/src/screens/registry.rs |
Adds owner-aware metadata views and detail requests. |
rust-modules/src/screens/player/overlay.rs |
Threads metadata through player overlays. |
rust-modules/src/screens/player/overlay_tests.rs |
Updates overlay ownership fixtures. |
rust-modules/src/screens/player/mod.rs |
Uses owner metadata for player UI. |
rust-modules/src/screens/library/deferred_tests.rs |
Updates owned-store dispatch tests. |
rust-modules/src/screens/item_menu.rs |
Uses owner metadata for cached trailers. |
rust-modules/src/screens/detail/hero.rs |
Updates metadata-backed hero tests. |
rust-modules/src/screens/detail/geometry_tests.rs |
Updates detail geometry fixtures. |
rust-modules/src/screens/detail/episodes.rs |
Uses owner metadata for season loading. |
rust-modules/src/screens/alt_sources.rs |
Uses owner metadata for alternate sources. |
rust-modules/src/screens/alt_sources_tests.rs |
Updates alternate-source ownership tests. |
rust-modules/src/screens/about_panel.rs |
Reads metadata through the host owner. |
rust-modules/src/route/decision.rs |
Threads Metadata through playback resolution. |
rust-modules/src/route/decision_timeline_tests.rs |
Updates resolution fixtures. |
rust-modules/src/route/decision_test_support.rs |
Updates plan-application fixtures. |
rust-modules/src/route/decision_resolve_route_tests.rs |
Updates playback resolution tests. |
rust-modules/src/route/decision_plan_tests.rs |
Updates plan construction tests. |
rust-modules/src/metadata_watch_state_tests.rs |
Uses explicit metadata ownership. |
rust-modules/src/metadata_test_support.rs |
Provides owner-scoped fixtures. |
rust-modules/src/metadata_season_mailbox_tests.rs |
Updates season mailbox ownership tests. |
rust-modules/src/focusprobe.rs |
Uses owner metadata in fingerprints. |
rust-modules/src/dev/scenarios.rs |
Threads metadata through development scenarios. |
rust-modules/src/app/viewstate_directory_policy_tests.rs |
Updates Bridge-owned metadata tests. |
rust-modules/src/app/surface_navigation_tests.rs |
Updates navigation fixtures. |
rust-modules/src/app/session_dispatch_tests.rs |
Updates ViewState pump callbacks. |
rust-modules/src/app/search_publication_tests.rs |
Uses aggregate-owned notices. |
rust-modules/src/app/search_owned_tests.rs |
Updates owned metadata views. |
rust-modules/src/app/run.rs |
Pumps and fingerprints owner metadata. |
rust-modules/src/app/recorder.rs |
Reads store generations through Bridge. |
rust-modules/src/app/playback.rs |
Threads metadata through playback actions. |
rust-modules/src/app/library_shelf_action_tests.rs |
Updates app view fixtures. |
rust-modules/src/app/item_menu_player_return_tests.rs |
Updates playback resource fixtures. |
rust-modules/src/app/input.rs |
Uses Bridge-owned metadata for input paths. |
rust-modules/src/app/detail_panel_tests.rs |
Updates detail panel fixtures. |
rust-modules/src/app/bridge_test_support.rs |
Removes legacy notice cleanup. |
rust-modules/src/app/bootstrap/tests.rs |
Tests controlled tracker activation. |
rust-modules/src/app/bootstrap/stores.rs |
Removes global tracker reset. |
rust-modules/src/app/adapters/session.rs |
Passes metadata into local-data erasure. |
docs/stores-as-machines.md |
Documents owned stores. |
ci/check-deps.sh |
Adds the Metadata ownership gate. |
Review details
Suppressed comments (4)
rust-modules/src/app/playback.rs:747
request_play_up_nexthas already calledrequest_play, whose non-preview path retiresMetadataStore::playingbefore returning (route/decision.rs:5472-5475). This lookup therefore falls through tocurrent_server()on a successful transition, which can be a different Plex source from the queue's source; capture the outgoingcur_sid(ps)(with the same fallback used byrequest_play_up_next) before retiring the descriptor and reuse it for thisRequestDetail.
let sid = bridge.metadata_view().playing()
.map(|p| p.sid)
.unwrap_or_else(crate::plex::current_server);
rust-modules/src/screens/detail/mod.rs:3289
- Adding the owner parameter here leaves the detail test at
screens/detail/tests.rs:1208callingscreen.hero_set()with no argument. Because that module is compiled by the host unit suite, this signature change makescargo testfail; update the stale test call to pass the sametest_store().view()owner used by the surrounding tests.
rust-modules/src/screens/registry.rs:1586 - This mount effect unconditionally admits a non-idempotent
RequestDetail(each admission increments the generation and supersedes the previous worker). The/tmp/plxnative-detailpath already admits the same request synchronously before callingopen_detail(dev/scenarios.rs:882), so mounting that page starts a second fetch and cancels the first; skip the mount request whendetail_request_status(...)is alreadySome(true)(or remove the pre-open request).
rust-modules/src/stores/mod.rs:20 - The module header now says all six stores are physically owned and that no compatibility globals remain, but the
StoreEvdocumentation below still says the remaining stores retain legacy pump callers until their ownership slices land. That contradiction leaves the architecture documentation stale after this migration; update the pump-ownership wording as part of this change.
- Files reviewed: 58/58 changed files
- Comments generated: 2
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
|
|
||
| fn detail(&self) -> Option<&'static Detail> { | ||
| crate::metadata::current().filter(|d| { | ||
| fn detail<'a>(&self, meta: crate::metadata::MetadataView<'a>) -> Option<&'a Detail> { |
| pub(crate) struct Stores { | ||
| pub(crate) browse: std::rc::Rc<std::cell::RefCell<browse::BrowseStore>>, | ||
| pub(crate) hubs: hubs::HubsStore, | ||
| pub(crate) metadata: metadata::MetadataStore, |
…sites Co-Authored-By: Claude Sonnet 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Em5yYDNi5A2peYR6oPMXwD
… changes Co-Authored-By: Claude Sonnet 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Em5yYDNi5A2peYR6oPMXwD
…er rebasing on #119 Co-Authored-By: Claude Opus 5 <[email protected]>
The store-ownership migration's last owed item was the device pass; layers #110/#111/#112/#119 and the cleanup #121 were host-verified only until now. The player-lane scrub legs (paused scrub, tap commit, dropped-keyup net) all passed on the real pipeline. The ownership legs showed a clean boot-time activation reset, but the reused-Bridge case #119 was actually about could not be reached: the only in-app route to a second activation on a live Bridge is the profile picker, and that route is broken for a managed user. Two new findings came out of hitting that dead end: the profile chip and account overlay name the account holder rather than the signed-in managed user, and "Change profile" as a managed user spins forever on a 401 from the home-roster endpoints with no error, nothing logged, and Back inert — only Sign out escapes. Filed as separate issues, along with the pointer scrub path having no device-drivable coverage at all (no held-pointer token in the FIFO, and the one reachable synthetic click didn't engage the scrub band). Claude-Session: https://claude.ai/code/session_01Em5yYDNi5A2peYR6oPMXwD Co-authored-by: Claude Opus 5 <[email protected]>
pop_sequence delivers WillLeave(ForGood) and Unmount to the same body, and the AppFx::Store Close is deferred, so the is_some() guard still read a populated slot on the second event and emitted a second non-idempotent Close. Latch the teardown per instance, as #119 did for Detail's MetadataCmd::Clear. Closes #126 Co-Authored-By: Claude Opus 5 <[email protected]>
The last of the four store-ownership layers. Metadata's state, worker adapter and notice now live on
StoresperBridge, like Browse, ViewState, Person (#110), Search (#111) and Hubs (#112) beforeit. With this, no data store keeps process-wide mutable state: the statics, the
stores::metadata::applyfree function and the compatibility globals instores/mod.rsare gone,and
ci/check-deps.shgrows a zero-tolerancemetadata-ownergate to keep them gone.MetadataViewcan now only be constructed from a&MetadataStore, which is what made the rest ofthe port mechanical: nothing can read metadata without naming the owner it reads from.
The defect this layer found
Moving screen-issued commands onto the deferred
AppFx::Storequeue exposed a live instance oftrap T2 — an obligation retired against a result that was never its own:
pump_restoreretired a page's reconciliation obligation whenever the store answereddetail_request_status(...) == Some(false). That answer is anOption<bool>; it carries noidentity, so a page could not tell "my request settled" from "an older request for the same key
settled". When
Enter(Restored)promoted a deferred obligation, theRequestDetailcommand wasstill queued, so a stale terminal was exactly what the store answered and the reconciliation was
silently dropped. It is reachable in ordinary frames, not a contrived one:
StoreChangedcallspump_restoreoutside theif *ord == StoreId::Metadata.ord()guard, so a notice bump from anyother store landing in the same drain reaches it.
The fix is identity, not synchrony. The adapter already carried
detail_gen, and completionsalready dropped on it — that is T3, honoured for landings but not for retirement. A page now records
the generation at the moment it enters
Requestedand retires only on a terminal newer than it.Proven both ways: the test passes with the fix, and reverting only the generation check turns it red
again.
A second, smaller bug came from the same deferral: one page teardown emitted two
MetadataCmd::Clears,because
WillLeave(ForGood)andUnmountboth reach the teardown arm and the firstClearnolonger self-disarmed the second. Latched.
Traps, pinned by test
existed from the ViewState layer; verified load-bearing by mutation rather than duplicated.
actually discriminates — it fails against a shared adapter, which is the failure mode the Search
layer's two-owner tests missed.
Also fixed here:
Bridge::controlled_homearms the production detailrecord::Trackeragain. Anearlier commit in this layer deleted its only caller along with the static, which left
controlled-content recording of detail terminals dead on the device with nothing failing on the host.
The gap review found: activation never reset Metadata
app::boot::activate_server_ownedresets Browse, Search, Hubs, Person and ViewState when thecurrent server or profile changes, and did not reset Metadata — while its own doc comment states the
invariant: "EVERY store below is keyed to whichever server was current when it was filled, and none
of them carries a server in its keys, so leaving one behind means server A's ratingKeys being
fetched from server B."
MetadataCmdhad noResetat all, andClearis not a substitute: itdeliberately spares
now/playing(D3) and does not rotate the adapter, so aBridgereused forthe next profile could still reach the previous profile's playback descriptor and track store.
MetadataCmd::Resetnow drops the complete owned state —current,now,playing,skipped,alt— andMetadataStore::runrotates the adapter before dispatch, exactly asPersonStore::runand
SearchStore::run_with_directorydo, so a worker spawned before the reset can only land into theretired
Arc. Metadata was also the only owned store without the siblings'*_reset_rotates_the_adapter_and_fences_a_late_old_workerpin; it has one now, next to Person's andSearch's, asserting both halves — state cleared, and a pre-reset worker's completion invisible to the
post-reset store. Watched red first against a Reset deliberately built to behave like
Clear:reset must rotate the Metadata worker adapter.Merged with #117
#117 (trailer UX) landed mid-flight and touches the same file this layer rewrote most. Besides the
conflicts, it had added nine call sites against pre-ownership signatures that merged cleanly and
only failed at compile time. Audited against this layer's invariants:
trailer.rsnever reachesMetadata, nothing it does changes the detail item, hero set or season (so no
SpotFactswrite isowed), and it issues no Metadata request.
Gates
make check3687 passed / 0 failed ·cargo +nightly check --lib --no-default-featuresclean ·make(ARM) a real link,filereports a fresh ARM ELF ·ci/check-deps.shall gates green,including
metadata-owner. Replay fixtures are deliberately not re-recorded here: they have beenstale on
mainsince9ab256b7and the follow-up cleanup PR re-records them once.Open questions (not fixed here)
screens/detail/mod.rs— after the new guard keepsrefresh, the fall-through still acts on theidentity-less
Some(false)and clearsrestore_intent/return_pending. No reachable productionsequence was found, and the behaviour matches
main, so it is left alone rather than patched onsuspicion.
metadata::reset's doc comment sayssupersede_detailruns "for the in-flight work on THIS(about-to-be-retired) adapter". It does not:
MetadataStore::runrotates before dispatch, sosupersede lands on the fresh adapter. Behaviour is right — rotation is what fences, and Person does
the same thing in the same order — but the sentence is wrong and the cleanup PR's doc audit gets it.
refresh_genlacks the "derived, not hashed" comment thatspot_factscarries, so a reader maywonder why it is absent from
SHAPE.OnceLocksurvives inmetadata.rs. It is not process-wide mutable state, andci/check-statics.shonly scansstatic mutunderui/andscreens/, so allowlisting it wouldcreate a stale entry and break
make check. The cleanup PR decides it.ui::landgatekeyed perStoreIdrather than perBridge, the missinghubs_notifiedsuppression, the
controlled_with_directory(Some(Reset))rotation asymmetry, andPersonScreen'sPersonCmd::Closedouble-emit — the same shape as theClearbug fixed here.🤖 Generated with Claude Code
https://claude.ai/code/session_01Em5yYDNi5A2peYR6oPMXwD