Skip to content

Close out the store-ownership migration - #121

Merged
GLinnik21 merged 4 commits into
mainfrom
cleanup/ownership
Sep 18, 2026
Merged

GLinnik21 merged 4 commits into
mainfrom
cleanup/ownership

Conversation

@GLinnik21

@GLinnik21 GLinnik21 commented Sep 18, 2026 •

Copy link
Copy Markdown
Collaborator

The cleanup PR that closes the store-ownership migration. Browse, ViewState, Person (#110), Search
(#111), Hubs (#112) and Metadata (#119) each moved one store onto its Bridge; this one removes
what those six left behind and corrects the prose they falsified.

The last global mutable state, and the gate that never looked at it

search/scope.rs's static mut CACHE was the final process-wide mutable state in the migrated
modules: a memo of SourceScopeSnapshot shared by every Bridge in the process, read through
addr_of_mut!. It is now a ScopeCache field on SearchState — RefCell inside, because the
production callers only ever reach it through &self — so each Search owner memoizes its own. The
free scope::snapshot() / snapshot_with_directory() functions and reset_for_test are gone.

The more useful half: it survived four migration layers because nothing was looking.
ci/check-statics.sh scanned static mut only under ui/ and screens/, so search/ was never
examined. The gate now also scans search/, person/, metadata.rs, pms.rs and stores/. It
finds nothing else, which is the point — the blind spot mattered more than the one instance.

Pinned by two_owners_do_not_share_the_scope_memo, built deliberately on differing directory
content: two owners with content-identical directories would pass even against a shared cache, which
is exactly how the Search layer's original two-owner tests failed to discriminate. Red was simulated
by routing one owner through a stand-in shared cache, then reverted.

Replay fixtures: two re-recorded, one blocked by something else

The committed fixtures had failed on main since 9ab256b7 and every layer was told to leave them
alone so the cleanup could re-record once. Fixtures 1 (boot-home-chip-grid) and 6
(settings-family) now replay SAME — 582 and 1214 frames, zero diverged.

Two things worth recording:

  • SCREEN_SHAPES_PIN never needed bumping. It already matched the app's computed state_fp;
    only the fixture artifacts were stale. The assumption that six layers of shape changes had moved
    the pin was simply wrong.
  • Fixture 12 (filmography-detail-return) could not be recorded at all, and not because of this
    migration. Its flow trips the Detail page's hero-preview autostart, and the controlled-effect
    encoder (app/bootstrap/effects.rs) handles only ContentReq::Push, Present and Back,
    erroring on everything else. The preview and panel variants added by detail: trailer UX — full-screen mode, transport, seek, and a left column with a spacing grammar #117 have been unencodable
    ever since, so any flow touching a hero preview is unrecordable — which is most of Detail. That is
    application code and outside this layer, so fixture 12 stays stale and the gap is filed as an
    issue rather than patched here.

tests/fixtures/replay/ALPHABET.json gains three literals (Routine, Background,
RegistryOnly), each traced to its source constant with provenance recorded, per that file's own
add-by-source-backed-name rule: they now serialize into every controlled commit because stores own
their own persistence.

Doc-claim audit: 18 sentences the migration made false

Contradictions only — prose that fails to mention something new is out of scope by construction.
Three were worse than ordinary rot:

  • ci/check-deps.sh told a contributor whose build had just failed to "use
    stores::<store>::apply" — a function that exists nowhere. It now names the owner's run seam.
    This is the one stale sentence a person was guaranteed to read, at the moment they were blocked.
  • A comment in stores/browse.rs claimed four stores' notices were "still process-wide globals
    (stores::mod.rs's NOTICES)" and that draining one cleared the others — inside a test named
    separate_store_aggregates_never_share_state_transport_or_notices. It asserted the opposite of
    what its own test proves; NOTICES matched nothing else in the tree.
  • stores/metadata.rs's §1 read-surface contract still described ~11 free functions returning
    &'static, saying "a screen may call these directly". They are MetadataView methods borrowing
    from the owner, and several signatures had changed.

Where a rule was still correct but its stated justification had been deleted — the &'static
claims, "one static slot", "a crate-wide global" — the rule was kept and the mechanism corrected.
set_current_for_test keeps its testlock, because its assert_held is real.
docs/stores-as-machines.md also contradicted itself about its own mutator table (one line calling
it historical, another calling it live); that is now split explicitly into a frozen phase-4 census
and a caller column that is maintained.

The audit cleared as already-accurate: stores/mod.rs's module docs, ui/CLAUDE.md's phase-4
paragraph, and every host test count (the docs deliberately refuse to state one and hand over the
counting command instead).

What review found, and what it says about the gate

Review caught the gate widening being partly theatre, which is worth recording rather than quietly
fixing: ci/check-statics.sh was passing $SRC/person, and Person is the FILE person.rs, so grep
errored and 2>/dev/null swallowed it — Person was scanned by nothing while the header claimed
coverage. search.rs and metadata/ were missing too. The gate now checks that every gated path
exists and fails loudly if one does not, because a gate that silently scans nothing is worse than no
gate: it is believed.

It also found that the narrow static mut pattern could not see search/recents.rs's
static STORE: Mutex<Option<Store>> and static PENDING: Mutex<Vec<Pending>> — real process-wide
mutable state inside search/, read on the per-owner publication path. So the "no global mutable
state" claim was not true as first stated.
They are now scanned, using Required 1's wider spelling,
and allowlisted with permanent reason lines: they are a persistence seam — a write-behind queue
drained by background workers and a cache keyed by the global session generation — not store state,
and a per-Bridge copy would duplicate the on-disk queue and risk a double write.

ci/allow/statics.txt therefore goes 7 → 9. That is coverage increasing, not debt increasing:
the gate now sees two statics it was never able to see.

The wider pattern is applied to search/ only, deliberately. Run tree-wide it matches every
thread_local! { static … } interior declaration — a different, safe, per-thread idiom used
throughout ui/ and screens/ for render caches and test doubles — producing on the order of 80
unrelated hits. Mass-allowlisting those to make one gate change pass would be exactly the wrong
trade, so that widening is left as its own deliberate piece of work. The reasoning is written into
check-statics.sh itself, where the next person to touch it will read it.

Gates

make check 3688 / 3734 / 85 passed, 0 failed · cargo +nightly check --lib --no-default-features clean · ci/check-deps.sh and ci/check-statics.sh all gates green ·
make (ARM) a real relink with a fresh ARM ELF · replay SAME on fixtures 1 and 6.

One CI run of this branch failed on
app::content::library_publication_tests::a_requested_detail_refresh_retries_after_a_child_supersedes_its_request.
That is not this PR: git diff <main> -- src/app/content.rs is empty, the file is byte-identical
to main, and main passes locally. drain_detail_workers settles an async retry by polling 100
iterations with thread::yield_now() while a genuinely OS-spawned thread races to finish — a
load-dependent bound, not a wait, which passes on a 10-core Mac (in both orderings, and under
deliberate CPU saturation) and fails on a smaller, busier runner. Filed separately; fixing it means
giving that completion a real signal, which reshapes how the family observes async work.

Open questions (not fixed here)

  • Fixture 12 stays stale until app/bootstrap/effects.rs's encoder covers ContentReq::PreviewStart
    and its siblings. Filed separately; it is a recording-infrastructure gap from detail: trailer UX — full-screen mode, transport, seek, and a left column with a spacing grammar #117, not migration
    debt.
  • ui/CLAUDE.md:210 still says "Legacy Search currently uses it through a synchronous compatibility
    bridge". ui/search/ was deleted before this migration's range began, so it was left alone rather
    than fixed on sight.
  • The CHECK_DEPS_ONLY=<rule> filter (~170 s off make check's 616 s, since DepGates re-runs
    check-deps.sh about thirty times) was held back through the migration so no layer's gate timings
    moved mid-flight. It is a build-speed change, not ownership cleanup, so it belongs in its own PR.
  • Deferred to issues, being outside every layer: Person's unconditional notice bump, ui::landgate
    keyed per StoreId rather than per Bridge, the missing hubs_notified suppression, the
    controlled_with_directory(Some(Reset)) rotation asymmetry, and PersonScreen's PersonCmd::Close
    double-emit.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Em5yYDNi5A2peYR6oPMXwD

GLinnik21 and others added 3 commits September 18, 2026 08:24
…see it

The last global mutable state in the migrated ownership layers was
search/scope.rs's `static mut CACHE`: a memo of SourceScopeSnapshot shared by
every Bridge in the process. Move it onto SearchState as a ScopeCache field
(RefCell<Option<Cache>>, since the production callers only ever reach it
through &self/&mut self) so each Search owner memoizes its own scope.

Widen ci/check-statics.sh to also scan search/, person/, metadata.rs, pms.rs
and stores/ for static mut, so this class of regression is visible to the
gate that let this one survive four migration layers. It finds nothing new.

Leave metadata.rs's function-local OnceLock<Option<String>> dev-trigger cache
as is: it is not process-wide mutable state, the widened gate correctly does
not flag it, and it now carries a reason line for why it stays.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Em5yYDNi5A2peYR6oPMXwD
Re-record 1-boot-home-chip-grid and 6-settings-family with
tools/plxnative-rec rerecord against the current SCREEN_SHAPES_PIN
(0x0e66_311c_e4f1_0769, already correct — no bump needed) after six
store-ownership shape changes made the committed fixtures unloadable.

ALPHABET.json gains three source-backed literals now present in every
controlled session commit once a store owns its own persistence:
SaveAuthority::Routine (plex/session.rs), PersistencePurpose::Background
(plex/session/async_persistence.rs) and CommitAdmission::RegistryOnly
(auth/owner.rs).

12-filmography-detail-return could not be re-recorded: the flow's dwell
timer fires ContentReq::PreviewStart (screens/detail/mod.rs
request_preview), which app/bootstrap/effects.rs's recording encoder does
not handle (only Push/Present/Back), so the recorder itself refuses with
"unsupported controlled content effect" before the flow completes. This is
a pre-existing gap in the recording infra, not a stale-fixture problem, and
is out of scope here — left unrecorded and unimported.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Em5yYDNi5A2peYR6oPMXwD
Copilot AI lite review requested due to automatic review settings September 18, 2026 06:31

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The changes are internally consistent (code, gates, docs, and fixtures align) and the ownership model improvements are backed by targeted tests and updated CI enforcement.

Pull request overview

This PR completes the store-ownership migration cleanup by removing the last remaining process-wide mutable cache in the migrated modules, tightening CI gates to prevent regressions, updating store-ownership documentation to match the new ownership model, and re-recording/refreshing replay fixtures affected by the migration.

Changes:

  • Replace search/scope.rs’s static mut CACHE with a per-owner ScopeCache stored on SearchState, and update callers/tests accordingly.
  • Expand CI gates to scan the now-relevant modules (search/, person/, stores/, metadata.rs, pms.rs) and update gate messaging/documentation to reflect owner run seams (vs stores::<store>::apply).
  • Update docs and replay fixtures/vocabulary to reflect the new ownership and persistence vocabulary now present in controlled recordings.
File summaries
File Description
tests/fixtures/replay/ALPHABET.json Adds newly-serialized controlled-recording vocabulary literals tied to persistence purposes/admission.
tests/fixtures/replay/6-settings-family/manifest.json Refreshes fixture manifest schema fields/hashes to match current owned-store recording output.
tests/fixtures/replay/1-boot-home-chip-grid/manifest.json Refreshes fixture manifest schema fields/hashes to match current owned-store recording output.
rust-modules/src/stores/metadata.rs Updates module documentation to reflect MetadataView-based owned borrowing (&'a) and revised read surface.
rust-modules/src/stores/browse.rs Fixes contract-test commentary to reflect per-Stores notice ownership (no process-wide notice draining).
rust-modules/src/search/scope.rs Removes static mut cache; introduces per-owner ScopeCache and adds/updates tests to prove non-sharing.
rust-modules/src/search.rs Wires ScopeCache into SearchState snapshots and directory-driven code paths.
rust-modules/src/screens/detail/mod.rs Updates comments to reflect owned MetadataView borrowing instead of prior 'static semantics.
rust-modules/src/route/plan.rs Updates comments to reflect owned MetadataView borrowing in rationale for purity.
rust-modules/src/route/decision.rs Updates comments to reflect owned borrowing model around metadata::playing() usage.
rust-modules/src/pms.rs Updates comments to reflect per-Bridge ownership of the hub catalog state and testlock purpose.
rust-modules/src/metadata.rs Corrects/reset-related prose and clarifies test-only locking rationale; documents a function-local OnceLock.
rust-modules/src/app/bridge.rs Updates prose describing per-frame notice draining to reflect per-owner notices (not compatibility globals).
docs/stores-as-machines.md Updates phase-4/ownership prose and caller tables to reflect “all stores owned; no apply shim” reality.
docs/agent-reference.md Updates architecture/testing guidance text to reflect Metadata ownership and remaining shared test seams.
ci/check-statics.sh Expands static mut scan scope beyond ui/ and screens/ to cover migrated store modules.
ci/check-deps.sh Updates mutator gate messaging and commentary to match owner run seam usage.
ci/allow/mutators.txt Updates header guidance to reference the owner run/step seam rather than stores::<store>::apply.
Review details
  • Files reviewed: 18/20 changed files
  • Comments generated: 0
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@GLinnik21
GLinnik21 merged commit 2b2a4c9 into main Sep 18, 2026
7 of 8 checks passed
@GLinnik21
GLinnik21 deleted the cleanup/ownership branch September 18, 2026 07:19
GLinnik21 added a commit that referenced this pull request Sep 18, 2026
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants