Skip to content

Give each Bridge its own Search store - #111

Merged
GLinnik21 merged 3 commits into
mainfrom
stores/search
Sep 17, 2026
Merged

GLinnik21 merged 3 commits into
mainfrom
stores/search

Conversation

@GLinnik21

Copy link
Copy Markdown
Collaborator

Summary

Second layer of the per-Bridge store-ownership migration (after Person, #110). Search's mutable state (query, shelves, phase, generation, roster fence, favourites snapshot, debounce), its worker adapter (per-source in-flight claims and mailboxes) and its notice are now owned by each Bridge through Stores, not by process-wide statics.

  • The 12 statics in search.rs are gone; stores::search::apply and the free Search reads are deleted.
  • ViewState's optimistic fan-out edits the owning Bridge's SearchStore through an injected callback instead of the retired global apply.
  • Reset rotates the worker adapter, so a worker started before the reset can only write into the retired adapter.
  • New zero-tolerance search-owner gate in ci/check-deps.sh.

Tests

  • separate_bridges_do_not_share_any_search_owner_state_or_notice: a row landed for Bridge A is invisible to B's pump and lands on A's. Simulated red: a shared default adapter failed it.
  • search_reset_rotates_the_adapter_and_fences_a_late_old_worker: a late landing into the pre-reset adapter at the post-reset generation does not land. Simulated red: with rotation disabled it failed.
  • Local: make check, --no-default-features check, ci/check-deps.sh, ARM make (before the test-only fix round).

Open questions

  • search/scope.rs static mut CACHE holds one entry. Content never crosses owners, but two Bridges pumping alternately would rebuild it every frame (an extra StoreChanged + repaint each). Production runs one Bridge. Allowlist reason line or per-owner cache: decided in the cleanup PR.
  • search/recents.rs STORE/PENDING stay process-wide: recents are disk-persisted per profile, so sharing them across Bridges on one profile is correct.
  • search_facades in ci/check-deps.sh excludes reset because search.rs keeps a module-level fn reset(state, adapter); revisit if that surface changes.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Em5yYDNi5A2peYR6oPMXwD

GLinnik21 and others added 2 commits September 17, 2026 16:41
Ports the Search layer to the store-ownership pattern established by
Browse/Person/ViewState: SearchStore (stores/search.rs) now owns the
SearchState, the rotated Arc<SearchAdapter> worker, and the store's
notice, with one instance per Bridge. The process-wide compatibility
facade (crate::stores::search::apply/snapshot and the crate::search
free-function reads) is gone; callers go through owned SearchStore
methods and screens receive per-owner query/shelf/snapshot reads.

ViewState's optimistic local-edit fan-out (viewstate.rs) is updated to
call the owning Bridge's Search store through an injected callback
instead of the retired global apply(), so a watched/unwatched press
still updates Search's roster within the same sync step.

Adds a search_owner_matches gate to ci/check-deps.sh, mirroring
person_owner_matches, and two regression tests in
viewstate_directory_policy_tests.rs proving two Bridge owners share no
Search state, notices, or adapter identity.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
…e state

P2 from Opus review: the two-owner test only compared query text and
notices, both of which live on SearchState — neither exercises the
adapter mailbox a real fetch actually lands through, so a shared
Arc<SearchAdapter> across owners would have passed unnoticed.

Adds land_for_test (search.rs) to post a landing straight into a given
adapter's mailbox, bypassing the worker, without exposing the private
Projection type outside the module. The two-owner test now lands a row
into Bridge A's adapter and proves Bridge B's pump cannot see it, then
that A's own pump does. The reset/fencing test now lands into the
RETIRED adapter at the post-reset generation, proving the current
store's pump structurally cannot reach it (previously it landed into
an adapter nothing had spawned against, which passed even without
rotation, since reset() also clears the live adapter's mailboxes
regardless).

Simulated RED (that pre-port shape no longer exists on disk to run
directly): temporarily made SearchStore::default hand out one shared
Arc<SearchAdapter> and disabled rotation in run_with_directory's Reset
arm. The two-owner test failed at "Bridge A's own pump must land its
own row" (B's earlier pump drained the shared mailbox first). With
rotation alone disabled, the reset/fencing test failed at "reset must
rotate the Search worker adapter". Both reverted after observing red.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
Copilot AI lite review requested due to automatic review settings September 17, 2026 14:00

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.

🟡 Changes recommended

The architecture documentation is stale and one recents regression test no longer compares snapshots from the same owner.

Get a fresh assessment by requesting another Copilot review.

Pull request overview

Moves Search state, worker transport, and notices from process-wide globals into each Bridge’s SearchStore, while routing ViewState optimistic edits through the owning Search store.

Changes:

  • Introduces per-owner SearchState, SearchAdapter, notices, and reset fencing.
  • Updates Bridge/ViewState/store wiring and tests.
  • Adds the search-owner dependency gate.
File summaries
File Description
rust-modules/src/viewstate.rs Routes optimistic edits through Search owners.
rust-modules/src/stores/viewstate.rs Passes Search callbacks through ViewState.
rust-modules/src/stores/search.rs Adds owned Search state, adapter, and notices.
rust-modules/src/stores/mod.rs Integrates Search into Stores.
rust-modules/src/search/view.rs Builds snapshots from owned state.
rust-modules/src/search/recents.rs Updates owned-state test usage.
rust-modules/src/search.rs Replaces global Search state with explicit owners.
rust-modules/src/search_test_support.rs Adds owned Search fixtures.
rust-modules/src/search_query_debounce_tests.rs Migrates debounce and reset tests.
rust-modules/src/search_publication_tests.rs Migrates publication tests.
rust-modules/src/search_account_scope_tests.rs Migrates roster and favourite tests.
rust-modules/src/screens/search/tests.rs Uses per-test Search stores.
rust-modules/src/dev/scenarios.rs Uses mutable Bridge Search commands.
rust-modules/src/app/viewstate_directory_policy_tests.rs Adds multi-Bridge and reset-fencing tests.
rust-modules/src/app/surface_navigation_tests.rs Uses owner-local generations.
rust-modules/src/app/session_dispatch_tests.rs Updates ViewState pump calls.
rust-modules/src/app/search_publication_tests.rs Tests owned publication delivery.
rust-modules/src/app/search_owned_tests.rs Migrates owned Search scenarios.
rust-modules/src/app/bridge.rs Routes Search through Bridge stores.
rust-modules/src/app/bridge_test_support.rs Removes obsolete global cleanup.
ci/check-deps.sh Adds zero-tolerance Search ownership checks.
Review details

Suppressed comments (1)

rust-modules/src/search.rs:623

  • This documentation names SearchStore::run as the production caller, but that method is #[cfg(test)]; production routes through Stores::search_run to SearchStore::run_with_directory. Please name the production wrapper here so the reset/adapter ownership contract is not misdocumented.
    /// Synchronous command path. `stores::search::SearchStore::run` is the one caller in
    /// production and is what rotates `adapter` on `SearchCmd::Reset`.
  • Files reviewed: 21/21 changed files
  • Comments generated: 3
  • Review effort level: Lite

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

Comment thread rust-modules/src/search/recents.rs Outdated
Comment on lines +337 to +341
let outer = crate::search::SearchState::default().snapshot();
assert!(remember_with(first.generation(), "beta", || submissions += 1));
assert_eq!(first.terms(), &["alpha"]);
assert_eq!(snapshot().terms(), &["beta", "alpha"]);
let changed = crate::search::view::snapshot();
let changed = crate::search::SearchState::default().snapshot();
Comment thread rust-modules/src/search.rs Outdated
Comment on lines +84 to +86
//! makes two `Bridge`s share neither a query, a landing nor a notice. `SearchStore::run` rotates
//! `adapter` to a fresh `Arc` on `SearchCmd::Reset`, so a worker spawned before the reset can only
//! ever complete into the retired mailbox it captured.
Comment on lines +1 to +2
//! The physically owned Search model and fetch transport (`docs/stores-as-machines.md`). Each
//! production `Bridge` owns one [`SearchStore`]; no free selector can connect two Bridges.
- recents.rs test: take both snapshots from one retained SearchState
  owner instead of two independent defaults, so the query-generation
  equality actually proves stability rather than being trivial.
- search.rs doc comments: point at the production entry point
  (SearchStore::run_with_directory) instead of the test-only
  SearchStore::run.
- docs/stores-as-machines.md, docs/agent-reference.md: Search is now
  owned per Bridge (alongside Browse, Person, ViewState); only pms
  and metadata still retain compatibility globals/mailboxes.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
@GLinnik21
GLinnik21 merged commit ca52494 into main Sep 17, 2026
5 checks passed
@GLinnik21
GLinnik21 deleted the stores/search branch September 17, 2026 14:50
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