Skip to content

Search store emits store jobs for its fetch and recents save; the scope takes the household as an input - #1015

Merged
GLinnik21 merged 26 commits into
mainfrom
sansio/store-jobs-search
Oct 24, 2026
Merged

GLinnik21 merged 26 commits into
mainfrom
sansio/store-jobs-search

Conversation

@GLinnik21

@GLinnik21 GLinnik21 commented Oct 24, 2026 •

Copy link
Copy Markdown
Collaborator

Closes #1014

The Search store no longer starts its own workers or reads process globals from its step:

  • The query fetch leaves as a typed StoreJob::Search per server slot. The app's StoreRunner resolves the slot's client once per launch and hands it to the worker body.
  • A recents edit leaves as a typed StoreJob::SaveRecents.
  • The source scope takes the household from the Bridge as an argument.

Detail, Collection, Person, subtitle search, view reconcile, Catalog and Hubs already work this way (#975, #987, #990, #996, #999, #1011). This is wave 3, lane B of the Sans-IO series (docs/sans-io.md, "The store job lane").

What changed

The fetch (data/src/search.rs, app/adapters/stores.rs):

  • SearchReq { sid, key: ClientKey, q, favs, work }. work is SearchWork::{First, Tail { k, range, lane, tv }}, so one kind covers the first read and the paged lane reads.
  • maybe_spawn keeps its fan-out admission (Fanout, turn.admit), claims the slot's mailbox at the query's generation, and pushes the job. A slot with no client key lands a failure without a job.
  • The runner's launch_search calls resolve(sid, key) once and builds the IO from that client, so the two worker-body client_for reads are gone.
  • The body keeps its panic guard. A panicking fetch lands as a failed read and releases its claim, and two tests pin that the guard moved with the body.
  • Admission is Direct. No replay fixture records search traffic.

Refusal (S2): a refused launch calls Fetch::refuse_for(gen). The pump reads take_refused(gen) and arms the source's existing backoff (retry_cd = RETRY_FRAMES), so a refused source is asked again only after the backoff, with no respawn spin.

The household (S5):

  • ScopeCache::snapshot* and build* take household: &[i64], and the memo is keyed on it.
  • The Bridge passes session::peek().household_ids() into capture_views and with_measure.
  • The step's memo warm-up is deleted rather than given a household. It discarded its result, the scope cache is read only by the publication snapshots, and publication rebuilds when its key moves, so the deletion changes no behavior. With it gone, the step reads no global and the ViewState fan-out needs no household.
  • The cache keeps its household as a Vec and compares it as a borrowed slice, copying only on a rebuild.

Recents (search/recents.rs):

  • remember and clear report whether a save is owed. The RememberRecent and ClearRecents arms push StoreJob::SaveRecents, and the runner runs flush() on a worker and answers with a unit.
  • A refused save sets recents_refused on the store's SearchAdapter, which already holds the job's port, not a new static. The next recents edit then emits the save again, once. Every refusal happens synchronously inside the drain call that took the job, so the adapter cannot rotate in between.
  • A Reset forgets a pending refusal, as the base did.
  • STORE and PENDING stay process statics, and nothing in data/ calls storage_worker::submit.

Drains (S3): Bridge::search_pump refills the client keys, steps, and drains Search in the same call, and the StoreWork::Search arm calls it. Bridge::search_run drains too, which starts a recents save in the call that ran its edit. ViewState's ApplyView fan-out steps Search but pushes no job, so VIEWSTATE_FILLS is unchanged. A test pins that a view edit stepped through the fan-out emits no job.

Test-only forks: TEST_IO, SharedIo, spawn_job, open_io and the paging tests' Hook are gone. The data crate's Owner fixture is now the inline runner.

Gate list: ci/check-deps.sh's wall list gains data/src/search.rs and data/src/search/. Neither had a clock read when they joined.

Ledgers

Before After
ci/allow/workers/data-search.txt 2 lines (spawn_job search, submit recents-save) deleted
ci/allow/globals/data-search.txt 4 lines (the two worker-body client_for reads, scope.rs's two session::peek) deleted
PINNED_LEDGER_TOTALS (workers/globals/forks/fxlanes) 18/82/58/11 (main after #1013) 16/78/58/11

No ledger line was added or edited.

Reads that stay: slots() / server_ids, server_roster_gen, session::current_gen (the profile fence of SetQueryScoped), recents' with_store reads, and scope's read_registry_key and server_facts property reads. A fan-out grant is not refunded on a refused launch, as before and as with Person.

Tests

  • Pinned before the change: search_fetch_pin_tests.rs was added first and never edited after.
    • Its first test runs a query over two slots against two loopback servers. Each server sees exactly one fetch, both slots land, and three more rounds make no re-ask.
    • Its second test checks that a superseded query's late landing reaches no shelf.
    • They pass on main and here.
  • Mutation checks, each reverted:
    • Disabling the pump's take_refused read fails a_refused_request_is_asked_again_only_after_the_backoff.
    • Disabling the refused-save flag fails a_refused_save_is_asked_again_at_the_next_edit_once.
    • Passing &[] for the household in capture_views, or in with_measure, fails capture_views_grades_the_scope_with_the_sessions_current_household. That test saves a session with a household member, then without it, and reads the mark in the same frame.
  • New tests: 8 in search_job_tests.rs and 3 in recents.rs. The runner gains 6 Search and 3 SaveRecents branch tests: started and answered once, not taped, launched live under replay, a client the registry moved on from refused and backed off, and the held park and run.
  • Targeted suites at 6005117, which merges main after Metadata detail chain runs its GETs through the client the runner resolved #1013:
    • plx_data 1209 passed, 0 failed;
    • app 1001 passed, 0 failed;
    • hostsim return_hold 6 and lifecycle 86 passed, 0 failed;
    • the ledger tests and ci/check-deps.sh are green, with workers 16, globals 78, forks 58 and fxlanes 11.
    • The merge's one conflict was the globals pin. In the merged runner every StoreJob arm of both sides appears exactly once.

Gates

This PR's CI is the gate for make check, check-nodef, the replay fixtures and the ARM build. They were not run locally. The fixture files are unchanged from main.

One review, verdict FIX FIRST, with one should-fix finding: no test checked that the Bridge passes the session's household into the scope. That is fixed by the household test above.

Seven notes were also handled:

  • the per-frame household copy now happens only on a rebuild;
  • a comment overstated the pump's refusal ordering and is corrected;
  • a test-only serving call left the production body;
  • the SaveRecents port doc now says a Reset forgets a refusal;
  • the fan-out reasoning is recorded, with its test;
  • a test doc's claim is now asserted;
  • the search_run doc no longer says a command emits no fetch.

A doc-claim audit found three sentences this change made false, and all three are fixed here:

  • docs/sans-io.md said Search differs from the earlier lanes "in four ways". Two of them, the refusal backoff and the runner-resolved client, it shares with subtitle search and every lane.
  • The Bridge::search_run doc said a command emits no fetch.
  • scope.rs said "never the session cache".

Live path

Search was checked in the macOS simulator against tests/mock_pms.py --seed 1, with plex.tv and Discover pointed at the mock and a placeholder token. It was a mock-only run with no real account. It was a non-test build, so the fetch went through StoreRunner::Live.

  • Booting into Search with a seeded query logged asking 1 source(s), hubs movie=1, shelves=1 items=1 and state=ready.
  • Across three boots, the mock saw exactly one GET /hubs/search?query=…&limit=12&includeCollections=1 per boot and no /library/search. The results screen did not re-ask while it sat, and no refusal or backoff line appeared.
  • Picking the result opened its Detail page (/library/metadata/1046, extras, related, view reconcile) with no second search.

A recents save cannot be reached headless: RememberRecent fires only on a keyboard commit, and the simulator cannot type. The runner test a_save_job_is_started_writes_the_history_and_is_not_taped covers the save's Live path. This is host-simulator evidence only, with no TV claim. No drawing code or FFI changed.

Not in this PR

  • Replacing slots() and the roster generation with ClientKeys (optional; not claimed).
  • A Bridge-side household cache keyed by session::visible_generation(). capture_views still takes one session peek and builds a small Vec per call.

🤖 Generated with Claude Code

GLinnik21 and others added 26 commits October 24, 2026 17:05
…before Hubs moves onto the job lane

A controlled Home Bridge (recording side) writes one admission per request
the stores ask for, in the order they are asked, and a replay compares that
list byte for byte. The new Bridge-level test delivers a Hubs refetch and
the discovery work of the same frame and pins both recorded values as
literals, hubs first and discovery second, against the signatures that do
not change when Hubs emits a store job instead of starting its own worker.
It passes on the base and stays unedited through the lane.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ry read

Src keeps a ClientKey instead of a &'static Client and a token generation.
Every Hubs entry (tick, land, run, controlled) and the Stores methods that
step Hubs (viewstate_run, viewstate_pump, stops_landed, notify_map) take
the ClientKeys the Bridge refills just before the call. The landing compare
keys on resource.instance_gen(), so replay's recorded logical instance id
cannot make a live landing look stale. The recorded HubsInitial and the
request descriptor carry the same numbers as before.

BrowseScope carries the keys so the scope-level cores need no new
parameter; a test-only standalone scope reads the registry in test code.
Four client_for lines leave the globals ledger (count 5 to 1); the last one
goes with the worker in the job-lane commit.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Stores::VIEWSTATE_FILLS and Stores::NOTIFY_FILLS name the outboxes a fanning
call can fill, and Bridge::start_store_jobs_in starts them in that order.
hubs_run, viewstate_run, viewstate_pump, notify_pump and the three live
Store(Hubs) / HubsResult / StoreWork::Hubs arms drain Hubs in the same call
as the step. stops_pump and reconcile_pump reach Hubs through ApplyView only,
which launches nothing, so they drain none. The two controlled arms join in
the job-lane commit, where they start through admission.

Hubs has no outbox yet, so behaviour does not change; the WARN string and the
leftover-job assertion name the new drains.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…he kick

PmsAdapter gains an unrecorded refused list. kick_with records
(generation, request id, server) there when its launcher says no and leaves
the source in flight; settle_refused runs first in step_landings_with_scope,
run_with_scope and controlled_work_with_scope and runs the old inline block
verbatim (latch released; a quiet read spaces its next try; a page ask backs
off without spending an attempt; anything else fails the attempt and asks for
the endpoint again). An entry whose generation or request id no longer
matches was superseded and is dropped. No refusal reaches a recorded
mailbox, so no recorded byte moves.

The refusal tests were rewritten first and failed against the previous tree
(data 5 failed, app 4 failed); they pass with the settle.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
… starts no worker

HubsStore steps emit StoreJob::Hubs(Job<HubRequest>, HubsPort) on an outbox
and the app's StoreRunner launches them. HubRequest carries the ClientKey its
step decided on and owns the IO body (fetch) and the landing (complete);
HubsPort holds the adapter Arc, raises the dump-mode claim at the launch (at
the park in Held) and files a refusal on the unrecorded list the next step
settles. StoreJob::admission() names three families as one exhaustive match
(Tape, Home, Direct); the Hubs read is Home, admitted through the controlled
run's own ledger by StoreRunner::start_admitted with the bytes HubRequest::
admission returns (the bytes hubs_descriptor returned). The controlled arms of
the Bridge step Hubs and admit what it emitted inside the arm, so the hubs
line still precedes the discovery line; the live arms, the landing and the
fan-outs start through start. Held parks per kind: held() leaves Hubs live,
held_all() parks it for the tests that choose when it settles.

Both spawn_fetch forks, kick's client_for read and the HomeIo::hubs* helpers
are gone, and the three data-pms ledger files are deleted. The test seams the
inline spawn had (a refused spawn, a late worker) are the runner's, cfg(test)
beside the boundary they stand for.

The runner branches have tests of their own (live, spawn refused, client gone,
held run, held gone, and the Home ledger recording and replaying a launch and a
refusal); each fails when its branch is broken (gone-branch claim kept: 1
failed; Home never admitted: 6 failed; ledger refusal unanswered: 4 failed).
home_admission_tests passes unedited.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
docs/sans-io.md gains the Hubs lane (the third admission family, the claim
raised at the launch, the refusal outside the landing mailbox, replay
identity) and names the Hubs drains; PINNED_LEDGER_TOTALS drops to workers
18, globals 90, forks 58 with the three data-pms files gone. Comments that
the change made false are corrected: the landing gate's owed claim now names
launch_hubs_job, the adapter and port docs say the port holds the Arc, a
refused launch is settled by the next step, the check-deps hubs-owner note
no longer names HomeIo::hubs_with_directory, and the rlib string measurement in
docs/module-layers.md records that the Hubs refusal seam is the runner's.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Conflicts: ci/allow/globals/data-pms.txt (main only reworded its header; the
Hubs lane deletes the file, so it stays deleted) and PINNED_LEDGER_TOTALS in
tests/test_harness.py (main kept 19/95/60/11 and moved globals -3/+3; the real
sums of ci/allow on the merged tree are workers 18, globals 90, forks 58,
fxlanes 11).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… them (F1)

BrowseScope::retained cloned the Vec<(ServerId, ClientKey)> on every Hubs
step, so the idle per-frame Home tick allocated and freed once per frame for
any user with a server. The scope now holds a Cow: Borrowed from the host's
one buffer in retained(), Owned in the test-only standalone().

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… endpoint refreshes (F2)

A launch the runner refused is settled by the next Hubs step, and that step can
be an ApplyView (a press, a stop patch, a read-back fact) or a quiet source
refetch (the notification map). Their callers threw the EndpointRefreshSet
away (`let _`), so a refusal settled there backed the source off and never
asked for the server's endpoint to be re-resolved.

publish_view returns the Hubs step's endpoints; ViewStateState::request/run,
ViewStateStore::run, Stores::viewstate_run and Bridge::viewstate_run return a
StoreOutcome (changed = the old bool); Stores::stops_landed/publish and
Bridge::stops_pump return the set; Stores::reconcile_pump returns a
StoreOutcome; Spent gains `endpoints`, which Bridge::notify_pump hands back.
The dispatcher arm carries them (`Bridge::carry`), boot merges them, the
item-action presses and the frame loop execute them.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…d (F3)

`all(|sid| *sid == a)` was true for an empty list, so a boot that returned
EndpointRefreshSet::default() passed. Boot yields exactly nothing in this rig
(Reset rotates the Hubs and Browse adapters, and the refetch it sends is
settled by the next Hubs step), so the assertion is is_empty() with that
reason beside it and the list printed on failure.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… a deleted fn (F6, F9)

HubsPort::unclaim was a plain fetch_sub, so an unclaim after the landing take
had already saturated the count to 0 wrapped it to u32::MAX. It now lowers
with the same saturating update take_landings uses. ci/check-deps.sh's comment
listed controlled_work_with_directory, which this lane deleted.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The doc-claim audit found three prose claims the lane made false: the drain
rule ("each Bridge entry point drains only its own store", "in that one place")
that the *_FILLS fan-out lists broke, the stores-as-machines pms row and the
pms.rs module doc that still described controlled work as the capture path
(it is now a test driver; every step emits a StoreJob::Hubs), and run.rs's
"a refused launch settles at once" (it is settled by the next Hubs step).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… means

The Hubs read is a StoreJob the runner starts, so the "fetching" log line says only that the step emitted the request, and the capture rule is `pms::kick_with`'s "capture at the step".

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… Bridge seam

Two loopback servers count their /hubs/search hits; a query over both makes exactly one request
per server, lands both answers, and asks neither again. A second test lands an answer for a
superseded generation through the landing seam and shows it reaches no shelf while the current
generation's landing does. Both go through Bridge::deliver(StoreWork::Search) and the held-runner /
worker drains without asserting which one ran, so they hold the behaviour still while the fetch
moves from a spawned worker to a store job.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
ScopeCache::snapshot / snapshot_with_directory and the two builders take the signed-in profile's
household member ids as an argument instead of reading session::peek() themselves, and the memo
keys on it. Bridge::capture_views and Bridge::with_measure read the session once per publication
and hand the ids through Stores::search_snapshot.

The step path's scope warm (a snapshot whose result run_with_directory discarded) is gone: the
publication that follows rebuilds on any moved key anyway, and keeping it would have threaded the
household through every ViewState fan-out that steps Search with an ApplyView.

The two session::peek lines leave ci/allow/globals/data-search.txt and the globals pin drops from
90 to 88.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
A search pump no longer starts a worker. For each source that is due it
claims the source's mailbox and pushes StoreJob::Search on the store's
outbox: a SearchReq naming the server, the client the step decided on
(from the ClientKeys it is handed), the query, the favourite snapshot and
the work (the first answer or one window of a lane), addressed by the
query's generation, with a SearchPort into the adapter it was made from.

The runner (Admission::Direct, not on the tape) resolves the client once
per launch and runs finish_search_job on a worker, or refuses the job
through Fetch::refuse_for, which the next pump reads to back the source
off instead of respawning on the very next frame. The worker bodies no
longer read the registry (the two client_for lines leave the globals
ledger); the panic guard that makes a crashed fetch land as a failed one
moved with the body unchanged. Every Bridge call that steps Search
drains StoreId::Search in the same call (search_run, the new
search_pump, the boot and scenario steps through it).

The cfg(test) fork that ran a request inline against a fake server is
now the test fixture's runner (Owner::run_jobs) and the app's Held
runner, so TEST_IO, SharedIo, spawn_job and the paging Hook are gone.

Ledgers: workers 18 -> 17, globals 88 -> 86 (pins set to the counted
sums), data-search globals file emptied; the clock gate now covers
data/src/search.rs and data/src/search/.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Remembering or clearing a recent term no longer starts a worker from the
data layer. The edit queues the new history in memory as before, and the
Search step that made it emits StoreJob::SaveRecents (a unit request, a
unit answer, a sequence address of its own, Admission::Direct) on the same
outbox the fetches use; Bridge::search_run drains it in the same call and
the runner starts the write on a worker (finish_save_recents_job), which
drains the pending queue into the session file exactly as the old flush
did. The statics STORE and PENDING stay.

A write the runner refuses is remembered on the store's adapter, and the
next recents edit, even one that changes nothing, asks for a drain once
more; the queue-full retry that edit already had still goes through the
same job. remember/clear report the write they owe separately from
whether the history changed (recents::Edit); remember_with/clear_with and
their tests are untouched.

Ledger: workers 17 -> 16 (the pin follows); data-search workers is empty.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
docs/sans-io.md gains the Search lane (fetch as StoreJob::Search, recents as
StoreJob::SaveRecents, both Admission::Direct, refusal handling) and the
drain list; stores-as-machines.md and search.md follow. The two ledger files
whose last site moved onto the lane (ci/allow/workers/data-search.txt and
ci/allow/globals/data-search.txt) are deleted, and stale spawn wording in the
Search comments is refreshed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…p notes land

F1: capture_views_grades_the_scope_with_the_sessions_current_household builds a Bridge over a
session whose home_users names a server's owner, asserts the scope marks that server household at
construction (with_measure) and after capture_views, then saves a session without the member and
asserts the next capture regrades it. Handing search_snapshot `&[]` at either site turns it red.

Notes taken (behaviour-identical):
- F3: the household moves out of the scope memo's Key into Cache, compared against the caller's
  slice in place, so the per-frame read no longer copies it.
- F4: the comment on the pump's take_refused read says what the fan-out plan does and does not
  know.
- F5: the test-only io.serving(sid) call moves from finish_work (the production body) into the
  cfg(test) finish_with_io.
- F6: SaveRecentsPort's doc says a Reset-replaced adapter forgets a refusal.
- F7: a test that a view edit stepped through the fan-out emits no job.
- F9: the failed-lane-read test asserts the claim release its doc names.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The doc-claim audit found three sentences this lane wrote that its own code contradicts:
- docs/sans-io.md said the Search lane differs from the earlier ones in four ways; two of the
  four (the refuse_for/take_refused backoff, the runner-resolved client) are the shapes subtitle
  search and every other lane already have, and are now marked reused.
- Bridge::search_run's doc said a command emits no fetch and the drain was a precaution; a recents
  edit emits its SaveRecents there and the drain is what starts it.
- scope.rs said it never reads the session cache; it reads the session's two generation counters
  as memo keys, and never the session's contents.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Behaviour-identical cleanups from a single-pass simplify review of the lane's diff:
- SearchAdapter derives Default now that its second field is an AtomicBool, and imports the
  atomics instead of spelling the path three times.
- owe_recents_save builds its address with search_addr (generalised to a request number) instead
  of repeating the Addr literal.
- The pump sweep takes each slot's mailbox once and uses it for the landing take and the refusal
  read, rather than locking the table and cloning the Arc three times per live slot per frame.
- Two doc paragraphs in app/adapters/stores.rs are rewrapped.

Not done: renaming maybe_spawn (Person, Collection and subtitle search keep the name), and the
start_*/launch_* pairs, which are the runner's shape for every kind.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@GLinnik21
GLinnik21 merged commit fba7a81 into main Oct 24, 2026
19 checks passed
@GLinnik21
GLinnik21 deleted the sansio/store-jobs-search branch October 24, 2026 19:46
GLinnik21 added a commit that referenced this pull request Oct 24, 2026
Main carries the Metadata (#1013) and Search (#1015) store-job lanes. Both sides' additions are
kept: StoreJob::Search, SaveRecents and BrowseHubs side by side in the enum, admission(), store(),
take_jobs_of/has_jobs_of, the runner's start/admit_home/retire/run_held arms, and the wall list
(search and section_hubs.rs). The Search and section-hubs bullets of docs/sans-io.md both stay
(Browse's is the ninth store on the lane). PINNED_LEDGER_TOTALS is the real sum of the '# count:'
headers at the merged tree: workers 14, globals 75, forks 58, fxlanes 11.

Co-Authored-By: Claude Opus 5.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.

Search store: emit store jobs for its fetch and recents save, and take the household as an input

1 participant