Skip to content

Collection store: emit store jobs and read the server registry as an input - #987

Merged
GLinnik21 merged 7 commits into
mainfrom
sansio/store-jobs-collection
Oct 24, 2026
Merged

GLinnik21 merged 7 commits into
mainfrom
sansio/store-jobs-collection

Conversation

@GLinnik21

Copy link
Copy Markdown
Collaborator

Closes #984

The Collection store no longer starts a worker or reads the server registry from inside its step. It emits a typed StoreJob::Collection, which the app's StoreRunner starts, the same lane the Detail store took in #975. This is wave 1, store 1 of the Sans-IO series (docs/sans-io.md, "The store job lane").

Shared pieces every later store reuses

The first commit (ca9fe8a5f) is store-agnostic.

  • ClientKey and ClientKeys (plx_plex::plex):
    • ClientKey { instance, token } names a client and its credential: instance_gen(), then token_gen().
    • ClientKeys maps each server to its key.
    • The Bridge owns one buffer. adapters::stores::refill_client_keys refills it in place just before a store step, and it is the only loop over the registry.
  • Fetch::release_for(gen) releases a claim only if it was made for that generation.
  • Per-store drains:
    • Stores::take_jobs_of(StoreId) takes one store's outbox; take_jobs and has_jobs walk StoreId::ALL through it.
    • Bridge::start_store_jobs_of(StoreId) starts that store's jobs.
    • Each Bridge entry point drains only its own store, in the same call that steps it. That keeps the tape's admission order.
  • StoreRunner matches on the job. A newer Detail request retires only parked Detail jobs, never another store's.
  • The backstop and assert texts no longer say "detail".

Collection

  • The step: maybe_spawn no longer spawns. With a key for the server, it claims the generation and pushes Job<CollectionReq>. The request carries the server id and the ClientKey the step decided on. Without a key, it holds off RETRY_FRAMES and shows Failed if nothing is on screen.
  • Inputs: run, pump and refresh_if_client_changed take &ClientKeys, so the three client_for reads are gone.
  • The launch: it calls resolve(sid, key) and starts the job only if the registry still answers that exact client. Otherwise it records "admitted":false and refuses the port, and CollectionPort::refused releases the claim.
  • The answer: finish_collection_job runs the IO under catch_unwind, falls back to a transport failure, and answers through CollectionPort::done. CollectionAnswer is an opaque newtype, so Landing stays private.
  • Callers: Bridge::collection_run and Bridge::collection_pump follow refill keys → step → drain.
    • Only two production sites pass empty keys, both of which the design allows: CollectionStore's unreached Machine::step, and ViewState's ApplyView closures. ApplyView reads no key, and a debug_assert! guards it.
    • Every other empty-keys caller is test code.

Ledgers and gates

Before After
ci/allow/workers/data-collection.txt 1 line (maybe_spawn::spawn_small) deleted
ci/allow/globals/data-collection.txt 3 lines (client_for ×3) deleted
PINNED_LEDGER_TOTALS (workers/globals/forks/fxlanes) 25/101/60/11 24/98/60/11

ci/check-deps.sh's wall gate now scans data/src/collection.rs too, with zero hits. docs/sans-io.md describes the key input, the per-store drains and the store's unreached Machine::step.

Tests

  • data/src/collection_job_tests.rs (10 tests):
    • the step emits the job, stamps the ledger, and makes no request without a key;
    • the hold-off is observed: the view's revision stays still for RETRY_FRAMES - 1 pumps, then moves. With retry_cd removed, the test fails.
  • App:
    • a_collection_job_whose_client_the_registry_has_moved_on_from_is_not_started.
    • store_admission_tests.rs pins the recorded admission literals, including a_frame_with_a_person_and_a_collection_admits_the_person_first, which checks the full cross-store order in one frame. It passes byte-equal on main (with the file and its three-line mod declaration added) and on this branch. Swapping the two pumps fails it.
  • Rig: collections_page_to_member_ok (hostsim) now runs the parked store jobs between frames. The Held runner parks collection jobs, so before this the member never landed.

Gates, run on the committed tree

Run on head ec40c78bb, which includes a merge of main at 3e6665a53 and a names-only simplify commit:

Gate Result
make check exit 0. Every test result: line reports 0 failed. The application crate passed 948 (default features) and 1061 (hostsim). check-deps reports workers 24, globals 98, forks 60, fxlanes 11, "all gates green".
make check-nodef exit 0, no warnings
make check-replay all three fixtures × resolve/targets verdict=SAME, every *_diffs=0. No fixture changed (fixture 12 included).
make (ARM, tvdev) pkg/plxnative linked

One review, verdict FIX FIRST. Its three should-fix findings are in this branch: the live-path proof below, the cross-store admission test, and the observed hold-off.

Live path

Replay never launches a job, so the live runner was checked separately in the macOS simulator against tests/mock_pms.py (--movies 240), booted straight into collection 50001 with no plex.tv or Discover reach.

  • The mock server saw exactly one GET /library/metadata/50001 (the header job) and one 60-item GET /library/collections/50001/children (the children job). There was no refusal loop and no re-ask.
  • The settled capture shows the landed header ("20 films · Collection") and the members grid.
  • The event log has no refused, panic or mismatch line.

This is host simulator evidence only, with no TV claim. The change touches no drawing code and no FFI.

🤖 Generated with Claude Code

GLinnik21 and others added 7 commits October 24, 2026 10:10
The store-agnostic pieces the Person and Collection stores need to move onto
the store job lane (the lane Metadata's detail fetch already uses).

plx_plex::plex::{ClientKey, ClientKeys}: the registry's answer for every
server slot as a plain value, so a store's step decides from an argument
instead of reading client_for itself. ClientKey is (instance, token): the
client object plus the credential it held. There is deliberately no reader on
the type; the application fills one in place from the live registry
(adapters::stores::refill_client_keys), and the Bridge owns the one buffer so
a pump that runs every frame allocates nothing for it.

Fetch::release_for(gen): a refusal hands back the claim of the request it
answers and leaves a newer request's claim alone.

Stores::take_jobs_of(StoreId) and Bridge::start_store_jobs_of(StoreId): a
store's Bridge pump drains only its own outbox, in the same call as its step,
so a job some other sender left behind is still found and counted by the
backstop instead of being started silently. take_jobs / has_jobs now walk
StoreId::ALL, so a store joins the aggregate in one place. metadata_run drains
its own store this way (the same jobs today: only Metadata has an outbox).
The backstop and frame-check texts name every drain, not only metadata_run.

The runner's parked-job handling (retire_parked_details, run_held) is a match
over every job kind, so a store that joins the lane must say what a newer
detail request does to its parked jobs.

store_admission_tests: pins the tape admission a pumped collection records as
literals (rating-key open, tag open, unregistered server). Written against
signatures that do not change when Collection moves onto the lane, so the same
file runs on both sides of that change.

Two dead-code expectations (the keys buffer and its refill) are fulfilled by
the next commit, which removes them.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The collection store's step no longer starts a worker and no longer reads
the client registry. Its pump claims the fetch and pushes a typed
StoreJob::Collection (CollectionReq: server, the ClientKey it decided on,
the work) on an outbox; Bridge::collection_pump refills the Bridge's
ClientKeys, steps, and hands the job to the StoreRunner in the same call.

- CollectionReq / CollectionPort / CollectionAnswer / finish_collection_job
  in plx_data::collection. Addr.req is the listing generation (one fetch is
  out at a time). done() lands the answer stamped with that generation;
  refused() releases only that generation's claim (Fetch::release_for).
- CollectionStore::{run, pump} take &ClientKeys; Open and the pump's
  client-changed check compare ClientKey values instead of calling
  client_for. ViewState reaches the store through view_edit_collection,
  which only forwards ApplyView and passes no keys.
- The runner admits the request through the tape in the recorded shape
  (byte-identical to the old inline admission) and resolves the client
  inside the launch, accepting it only if it is still the client the step
  named. A Held runner parks the job; a newer Detail request retires only
  parked Detail jobs and keeps the rest.
- Contract tests for the emitted jobs (assert_fx!), the admission shape,
  refusal and supersede handling, and the runner's four outcomes; the
  Bridge-level admission test from the previous commit passes unchanged.
- The lifecycle rig that walks a collection page runs the held jobs.

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

Collection's step emits its request as a store job and reads the client
registry as an input, so its four ledger lines are gone: the worker start
(`workers`, 25 to 24) and the three `client_for` reads (`globals`, 101 to
98). Both area files held nothing else and are deleted; PINNED_LEDGER_TOTALS
follows, forks and fxlanes unchanged.

The `wall` clock-read gate now scans data/src/collection.rs (no hit).

docs/sans-io.md "The store job lane" names Collection as the second store,
ClientKeys as the input for a registry read, the per-store drain inside each
Bridge pump (refill keys, step, start_store_jobs_of) and the generic
backstop. CollectionStore's unreached Machine::step comment no longer says
empty keys strand a job (they fail the page; real keys without a drain
strand it).

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

a_server_without_a_client_emits_nothing_reads_failed_and_holds_off asserted Failed,
no job and no claim, then pumped with empty keys, which emit no job whether or not
retry_cd was set. It now asserts that the revision does not move across the
RETRY_FRAMES - 1 held-off pumps and does move when the hold-off ends. With the
`self.retry_cd = RETRY_FRAMES` line removed from maybe_spawn's no-client branch the
test fails (revision 3 against 2); with it, it passes.

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

The Bridge-level admission pins opened and pumped a collection alone, so the order
across stores inside one frame (the positional tape comparison) was pinned on no
tree. One test opens a person and a collection, pumps person_pump then
collection_pump inside one FrameScope and compares tape::finish() with the full
literal list: the person's three requests in slot order (the shapes fixture 12
records), then the collection's header read. It uses only signatures that exist on
the base tree. Swapping the two pumps makes it fail.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The job tests import Job and Port that the parent module's glob already supplies, the Bridge
spells StoreId in full where the file imports it, and the client_keys module doc narrated what
the step "used to" do. Names and wording only; no behaviour, expectation or ledger line moves.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@GLinnik21
GLinnik21 merged commit 1e6f591 into main Oct 24, 2026
19 checks passed
@GLinnik21
GLinnik21 deleted the sansio/store-jobs-collection branch October 24, 2026 10:59
GLinnik21 added a commit that referenced this pull request Oct 24, 2026
GLinnik21 added a commit that referenced this pull request Oct 24, 2026
#990)

The Person store no longer starts workers or reads the server registry from inside its step. It
emits one typed StoreJob::Person per fetch slot, which the app's StoreRunner starts, the lane
Detail took in #975 and Collection in #987; wave 1, store 2 of the Sans-IO series, reusing #987's
ClientKeys input and per-store drains unchanged.

The step: maybe_spawn keeps the busy and retry_cd checks, the address, the plex.tv branch with its
session early return, the claim and the synchronous refused landing, then pushes a
Job<PersonReq>. A pump emits at most one job per wanted slot, in ascending slot order, up to the
fan-out width. A server read carries the server and the ClientKey the step chose; with no key the
step backs off RETRY_FRAMES without claiming. A plex.tv read (Profile, Credits) carries the
identity the step decided on: Controlled, or the settled session. Addr.req is a per-state wrapping
sequence; the slot and the person generation travel in PersonPort, and the tape's admission JSON
takes its gen from the request, so the recorded bytes are unchanged.

The runner: start_person admits through the tape. A server read starts only if ClientKey::of(c)
still matches the job's key; otherwise it records "admitted":false and PersonPort::refused
releases only that generation's claim. The Held lane re-resolves the client and refuses on a
mismatch, and a newer Detail request leaves parked Person jobs alone. finish_person_job holds the
old worker body: Controlled answers the failure value without a read, Settled runs
fetch_profile/fetch_credits under catch_unwind, a server job runs the Resolve, Media or Roles read
with its chunking kept, and a server job handed no client is refused. PersonAnswer is opaque.
Bridge::person_pump refills the keys, steps and drains StoreId::Person in one call, still before
Collection and the Detail reconciliation, so the cross-store admission order holds.

Not pure yet: the step still reads tape::active(), session::peek_settled(), the session watch, the
refused-discover landing, server_ids(), server_roster_gen() and, in dev-trigger builds,
devtrig::read("personcredits"); docs/sans-io.md lists them and claims no purity for Person.

Ledgers: data-person's workers (2) and globals (1) files deleted; PINNED_LEDGER_TOTALS
24/98/60/11 -> 22/97/60/11.

Tests: 10 step tests in data/src/person.rs (slot order and width, the no-key back-off, plex.tv
identity, unique addresses across a reset, a pre-reset port lands only into the old adapter, a
refusal releases only its own claim, the admission record in fixture 12's shape, a controlled read
without IO, a clientless server job refused); 7 runner tests in app/adapters/stores.rs; 2 Bridge
admission-order tests that pass on the pre-change tree and on this branch. The controlled-session
test now steps and pins the outbox empty. Fixture replays all SAME; the live runner loaded a
Person page's Media, Profile, Credits and batched Roles reads once each against the mock server in
the macOS simulator.

Closes #989

Co-Authored-By: Claude Opus 5.5 <[email protected]>
GLinnik21 added a commit that referenced this pull request Oct 24, 2026
…he step can observe (#996)

The subtitle-search and view-reconcile stores no longer start workers or read the server registry
from inside their step. Each emits a typed store job that the app's StoreRunner starts, the lane
Detail (#975), Collection (#987) and Person (#990) took; wave 2, lane A of the Sans-IO series.

A refusal the step can observe: Fetch::refuse_for(gen) releases that generation's claim and records
the refusal, only when the claim is its own; Fetch::take_refused(gen) answers once, and a refusal
for a superseded generation frees and records nothing. These stores back off RETRY_FRAMES after a
refused start, and the backoff survives the start leaving the step.

Subtitle search: maybe_spawn claims and pushes Job<SubSearchReq> with the server and the ClientKey
the step chose; pump reads take_refused before maybe_spawn and backs off one pump later, with no
respawn spin; the no-client branch is unchanged; finish_subsearch_job runs under catch_unwind.

View reconcile: kick pushes Job<ReconcileReq> per server batch. A landing is Landing { id, outcome }
with Outcome::{Read, NotStarted}; a refused or key-mismatched flight posts NotStarted, which
requeues its leaves and parents (an item asked for again goes back as an item), drops the dirty
marks it covered, backs off and settles nothing. reset() keeps a job still on the outbox, which
answers into the retired adapter.

The runner resolves the client inside the launch and starts a job only if ClientKey::of(c) still
matches; both kinds are untaped and launch live under replay; Held parks them, run_held re-resolves
or refuses, and a newer Detail request leaves them parked. Bridge::subsearch_pump and reconcile_pump
refill the keys, step and drain their own store in one call.

Ledgers: data-subsearch's and data-viewreconcile's workers and globals files deleted;
PINNED_LEDGER_TOTALS 22/97/60/11 -> 20/95/60/11. The wall gate scans data/subsearch.rs.

Tests: 36 new (Fetch refusal 4, subsearch job 8, view reconcile job 11 plus 1 parents test, runner
12), and the stop-after-identity-change regression test now sweeps the parked read-back. Fixture
replays all SAME; in the macOS simulator against the mock server, a watched-state read-back and a
player subtitle search were each sent to the runner, ran and landed.

Closes #995

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.

Collection store: emit store jobs and read the server registry as an input

1 participant