Skip to content

Browse: the Library's source discovery leaves as a typed store job (B-D) - #1103

Merged
GLinnik21 merged 8 commits into
mainfrom
sansio/store-jobs-browse-bd
Oct 28, 2026
Merged

GLinnik21 merged 8 commits into
mainfrom
sansio/store-jobs-browse-bd

Conversation

@GLinnik21

@GLinnik21 GLinnik21 commented Oct 28, 2026 •

Copy link
Copy Markdown
Collaborator

Closes #1098

The Library's source discovery (the section list, the server's name and the item counts of one source) no longer starts the Browse store's own worker, and its step no longer reads the server registry. The read leaves as a typed store job, StoreJob::BrowseDiscovery, that the app's StoreRunner starts. The step captures the source's ClientKey from the borrowed ClientKeys, as the section hubs, directory and page reads do (#1021, #1028); the runner resolves the key at launch. This is the last Browse read of the Sans-IO series that was started in browse/mod.rs (design row B-D, docs/sans-io.md, "The discovery lane"). B-E (the roster and gate reads) and the pins stay as they are.

What changed

The job (data/src/browse/discovery_job.rs is new; data/src/browse/mod.rs, data/src/stores/{browse,mod}.rs):

  • StoreJob::BrowseDiscovery(Job<BrowseDiscoveryReq>, BrowseDiscoveryPort). The request carries the epoch, the source index, the ClientKey, which job (sections, or counts of the landed sections) and whether to ask the server's name. finish_browse_discovery_job is the IO body, the old worker's, unchanged, still under catch_unwind (a panic lands as Sections(None) / Counts([])).
  • DiscoveryRequest, execute_discovery, spawn_discovery and the REFUSE_DISCOVERY test seam are gone; the runner's existing with_refused_hubs_launches_for_test seam reaches the new launcher.
  • BrowseAdapter::src_fetching is now a Fetch<()> whose slot is unused. The answer still lands in src_result (the mailbox record.rs encodes and the landing gate takes), and the claim still drops at apply_discovery after its epoch check, so the landing gate's dump mode is unchanged. Folding the mailbox into the Fetch slot would move the recorded landing path, which is not this PR's scope.

Admission is Home, the one Browse kind that is. A controlled Home run starts the discovery and records its request, so:

  • It is recorded only from the controlled StoreWork::BrowseDiscovery arm (Bridge::admit_home_jobs(.., StoreId::Browse), which the Hubs arm already uses). Every other sender starts it Direct through start.
  • The recorded bytes are unchanged: the same keys and values DiscoveryRequest::descriptor wrote. They are pinned as literals in home_admission_tests (the sections request, and the counts request after a landing) and in browse_discovery_admission_tests. The JSON key order is alphabetical (serde_json without preserve_order), so there was no order to keep.
  • Replay pops the recorded answer and never launches: a recorded launch leaves the claim up until the recorded landing applies; a recorded refusal is answered once by the runner.

The client: maybe_discover_owned(adapter, keys, jobs) takes keys.key(sid); a source whose slot holds no client asks for nothing. The runner's resolve compares the key at the launch and refuses a job whose client moved on.

Refusal (S2), the B-A shape plus the backoff discovery always had:

  • A refused job lowers its claim in the call that refused it and records the request id on the adapter (Fetch::refuse_for). It never reaches src_result, so no recorded byte moves.
  • The store records the read it has out (src_flight: id, epoch, source). discovery_settle runs at the head of maybe_discover_owned, before the countdown's decrement, only when no claim is up. If take_refused(id) and the flight's epoch is still the table's, it sets that source's retry_cd to the full SRC_RETRY_CD (600). Nothing is invalidated. A flight whose adapter was replaced, or whose epoch moved, backs off nothing.
  • The refusal settles one step later than before. The old launcher set the countdown in the launching call; now it is set at the head of the next step, so the step after a refusal finds the countdown at 599, as it did. This is deliberate: the step is pure and cannot learn of the refusal until the runner has run. BrowseStore::sync_roster settles before it syncs the roster, so a source the sync re-arms in the same step (a re-pointed or retokened client) is asked again at once, exactly as before (review finding 2). No replay fixture holds admitted:false for a discovery, so no recording moves. Pinned by a_refused_discovery_backs_off_for_the_full_countdown_and_the_source_is_asked_again (lifecycle), assert_settled_into_the_backoff in the runner tests, and the data tests for a refusal across a reset and for a settled refusal of an older epoch.

Drains (S3). Every entry that steps discovery now starts what the step emitted in the same call:

Path Drain
Bridge::browse_discover_pump refill the keys, step, start_store_jobs_of(Browse) (new; it had none)
the live StoreWork::BrowseDiscovery arm through browse_discover_pump (it had none)
frame_ingest (onboard) through browse_discover_pump (it called the bare store)
the controlled StoreWork::BrowseDiscovery arm drains inside the arm to admit (admit_home_jobs)
the StoreWork::Browse pump (pump_with_gate, which also steps discovery) already start_store_jobs_of(Browse); started Direct

HomeIo::discovery_owed{,_with} are deleted: the arm no longer builds a closure around a spawn.

The test runner. LiveKind gains BrowseDiscovery. held() and park_page_reads() run it live; held_all() parks it. The reason: three hostsim helpers of app/run.rs run every parked job on the test thread, and a parked discovery would then run its blocking GETs there against fixtures that park their first request or accept and never answer. No rig waits for a discovery landing from a real worker (every one fabricates it). The decision said to flip if a suite failed with this choice and passed with discovery parked; I tried parking it under held() and the whole hostsim (1180 then) and app (1065) suites passed, so no suite forces the choice and live stays, as decided. That is a reason from rig behaviour, not a failing test, and the docs say so.

Gates: ci/check-deps.sh's wall (clock) gate now also covers discovery_job.rs. No ledger line was added or edited.

Ledgers

Before After
ci/allow/workers/data-browse.txt 1 (spawn_discovery spawn_small) deleted (the file's only line)
ci/allow/globals/data-browse.txt 15 14 (maybe_discover_owned client_for gone)
PINNED_LEDGER_TOTALS (workers/globals/forks/fxlanes) 9/66/58/11 on the base; 8/65/58/11 before the main merge 7/64/58/11

The branch merges main at 9cab21e, which includes Metadata M3 (#1102): its ledger lines took the sums to 7/64 once both landed. The totals were recomputed from the # count: headers on the merged tree (workers 7, globals 64, forks 58, fxlanes 11).

Tests

Fails-first. c2ed77d was committed first and ran red on the base:
test result: FAILED. 0 passed; 4 failed; 0 ignored; 0 measured; 1061 filtered out; finished in 0.00s
(each Bridge entry that steps discovery must start the read it emitted in the same call; the controlled arm must record a refused launch as not admitted). Two green pins went in with it and stay unedited: home_admission_tests::a_sections_landing_then_discovery_records_the_counts_request and the lifecycle test above.

New tests:

  • Data (discovery_job_tests.rs, 12): the step leaves one job and raises the claim; no client for the server asks for nothing; the admission is the recorded literal; an answer waits in the mailbox and the apply lowers the claim; a refusal lowers the claim and never reaches the mailbox; a late refusal of a superseded request leaves the current claim alone; a refusal across a reset, or of an older epoch, backs nothing off; a panicking sections or counts read lands as a failure; the kind is a Browse store job admitted Home.
  • Runner (adapters/stores.rs, 8): live start answered once on a worker; client gone: refused once, and the next step, which sees the re-pointed client, asks again with the new key; the system refuses the thread: refused once and backs off; held: parks and holds its claim, then runs once; held with the client gone by then; held() starts it on a worker and held_all() parks it; a replay launches nothing and answers a recorded refusal once; the admission descriptor and start.
  • Admission (browse_discovery_admission_tests.rs, 4): record writes the literal and starts the job inside the arm; replay answers from the line, launches nothing and lowers the claim only at the recorded landing; a different line fails the run (mismatched synchronous admission); the encoder encodes StoreWork::{Hubs,BrowseDiscovery} and refuses StoreWork::Browse, RetryDiscovery, RetrySource and RecheckShares.
  • Drain (browse_discovery_drain_tests.rs, 4): the C0 tests above.

Mutation checks on the committed C2 tree, one at a time, each restored afterwards. Every mutation was killed:

  • resolve always None in launch_browse_discovery: 6 tests fail;
  • the refused() call in start_browse_discovery removed: 5 fail;
  • the test seam for a refused thread removed: 5 fail;
  • the held() park disabled for the kind: 3 fail.

Suites at the review head 5d43380 (origin/main is still 9cab21e, nothing to merge):

  • plx_data: test result: ok. 1270 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 12.76s
  • the app crate: test result: ok. 1085 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 25.70s
  • plx_screens: test result: ok. 1721 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 24.80s
  • hostsim, the whole app crate: test result: ok. 1200 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 32.46s
  • hostsim return_hold: test result: ok. 6 passed; 0 failed; 0 ignored; 0 measured; 1194 filtered out; finished in 0.15s
  • hostsim lifecycle: test result: ok. 88 passed; 0 failed; 0 ignored; 0 measured; 1112 filtered out; finished in 4.13s
  • DepGates.test_ledger_totals_match_the_pinned_table and test_ledger_count_header_must_equal_its_entries_in_every_area_file: OK. ci/check-deps.sh: check-deps: all gates green.

Review

Verdict MERGE, four minor findings; all four fixed (f07877d, 5d43380). git fetch origin main showed no new commits, so there is no merge; the ledger sums are still workers 7, globals 64, forks 58, fxlanes 11.

  1. The Onboard drain test could not tell whether frame_ingest drains (Onboard's Tick sends StoreWork::BrowseDiscovery, whose live arm starts the job anyway). Fixed: a new test runs a frame on Login, whose Tick sends no discovery work, under the refused-thread seam, then runs a second frame and asserts the source is in its backoff (retry_cd > 0), so it also proves a read was asked at all (a bare "claim is down" is true when nothing was asked). The Onboard test stays. Mutation check: frame_ingest reverted to the bare rig.stores.browse_discover_pump(&rig.client_keys) fails it: the Login frame asked for the discovery and it was refused (retry_cd 0); restored, green.
  2. A refusal settled after the roster sync swallowed a re-point's re-arm (a retokened client waited out the 600-step backoff instead of being asked on the next frame). Red first: a_refused_discovery_is_asked_again_at_once_when_the_client_is_repointed failed (left: 0, right: 1) with its control a_refused_discovery_backs_off_when_the_client_is_unchanged green. Fix: BrowseStore::sync_roster calls discovery_settle before sync_roster_owned; the settle in maybe_discover_owned stays and is idempotent. Both new tests pass. The two runner tests that used a retoken to mean "client gone" now correctly see the immediate re-ask and assert it (they asserted the backoff, which was the bug); the refused-thread and lifecycle tests still pin the backoff of an unchanged client. docs/sans-io.md and the discovery_settle doc say so.
  3. Two docs named admit_hubs_jobs (docs/sans-io.md, docs/stores-as-machines.md): now admit_home_jobs.
  4. The held() paragraph contradicted itself: it now says held() leaves Hubs, the season switch and the page read live because rigs wait for those landings, and gives discovery its own, correct reason (the hostsim helpers that run every parked job on the test thread).

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. No Makefile, Cargo or workflow file changed, so no build-bench table is needed. There is no FFI or linkage change.

Review. The pr-reviewer agent was not run: this lane spawns no subagents. An advisor read the combined facts once before this PR and asked for the refusal timing, the held-runner reason and the merge resolution to be checked; they are above and below.

Doc-claim audit, done by hand per .agents/agents/doc-claim-auditor.md (C3). Fixed: docs/sans-io.md (the lane list, a new "The discovery lane" bullet, the Home admission family, the held-runner paragraph, the local-launcher example), docs/stores-as-machines.md (the Browse adapter paragraph and the StoreWork row), docs/poster-scheduler-design.md (the worker table row), ci/check-deps.sh (the same example), base/src/task.rs (the uncounted-worker comment), and the doc comments in adapters/stores.rs and browse/mod.rs. Left alone on purpose: docs/module-layers.md:1305-1307 is a dated measurement of what one build contained. The wall-gate comments for B-A and B-B/C in ci/check-deps.sh say what was true when each file joined.

Live path

Checked in the macOS simulator at 960x540 against a fresh tests/mock_pms.py --verbose, with plex.tv and Discover pointed at the mock and a placeholder token. No keys were sent and no TV or device was touched. Identity lines read before anything else: pms: server 0 version=1.41.0.0000-synthetic, notify: roster servers=1 described=1 owned=1.

  • Two boots (Home, then plxnative-library): the mock saw GET /library/sections once per boot, the counts GET /library/sections/{1,2}/all (size 0, and type=18) once each, and no repeat while the app ran.
  • The Library's pills listed the mock's sections, Movies and TV Shows, and the grid drew.
  • Every sim and mock process was killed by pid afterwards.

Not in this PR

  • B-E: sync_roster_owned, discovery_needs_pump and the other roster and gate reads still read the registry; the pins still spawn their own workers.
  • Folding src_result into the Fetch<()> slot.
  • Nothing was run on a television; discovery is a network read with no pixel, decoder or frame-rate dependence.

🤖 Generated with OpenCode

GLinnik21 and others added 8 commits October 28, 2026 12:55
Every Bridge entry that steps the Library's source discovery must start the read through the
application's runner: four tests refuse the launch with the runner's seam and expect the claim down
in the same call (red on the base: spawn_discovery ignores the seam, and a controlled run records
the launch as admitted). Two pins that are green on both sides: the counts request's recorded bytes,
and a refused discovery's backoff of exactly SRC_RETRY_CD steps.

Co-Authored-By: OpenCode <[email protected]>
maybe_discover_owned no longer reads the server registry or starts a worker: it takes the server's
ClientKey from the borrowed ClientKeys, raises the discovery claim (now a Fetch<()>, its slot unused
because the answer still lands in src_result and the claim drops at apply) and leaves a
StoreJob::BrowseDiscovery. The runner resolves the key at launch and hands the body the client; a
launch that cannot start is refused, the claim comes back in that call, and the store's next step
settles it with the same 600-step backoff, before the countdown's decrement and without an
invalidation.

The job is admitted Home from the controlled arm (admit_home_jobs, inside the arm, so the
recorded line keeps its place) and Direct from Bridge::browse_discover_pump, which the live arm,
frame_ingest and boot now go through. The recorded descriptor keeps its keys and values.

Removes DiscoveryRequest, execute_discovery, spawn_discovery and the REFUSE_DISCOVERY_FOR_TEST
seam, rewrites the tests that used them on the new seams, deletes the data-browse workers ledger
(its only line) and one globals line: PINNED_LEDGER_TOTALS 9/66/58/11 -> 8/65/58/11. The wall gate
covers discovery_job.rs. LiveKind::BrowseDiscovery keeps discovery live under held().

Co-Authored-By: OpenCode <[email protected]>
Eight runner tests over the live, held and refused starts and the replayed
refusal, and four admission tests: the record and replay of the sections
request, a mismatched line failing the run, and the encoder encoding only the
discovery pump.

Co-Authored-By: OpenCode <[email protected]>
The doc-claim audit by hand: sans-io.md (the lane list, a new discovery lane
bullet, Home admission, the held runner), stores-as-machines.md, the runner's
module docs, the browse module docs and the two comments that named
spawn_discovery.

Co-Authored-By: OpenCode <[email protected]>
Metadata M3 (#1102) landed first: the ledger sums are 7/64/58/11 (workers 8 -> 7,
globals 65 -> 64) and PINNED_LEDGER_TOTALS follows.

Co-Authored-By: OpenCode <[email protected]>
…sync, drain test, docs)

A refusal is settled before the step's roster sync, so a re-pointed client re-arms
the source and it is asked again at once, as the launcher's in-call backoff always
allowed. The frame_ingest drain test runs on a screen that asks for no discovery
itself and checks a read was asked. Two docs named admit_hubs_jobs and the held()
paragraph gave a reason its own sweep disproved.

Co-Authored-By: OpenCode <[email protected]>
@GLinnik21
GLinnik21 merged commit a2aa85d into main Oct 28, 2026
19 checks passed
@GLinnik21
GLinnik21 deleted the sansio/store-jobs-browse-bd branch October 28, 2026 11:18
Bardioc1977 added a commit to Bardioc1977/plx-native that referenced this pull request Oct 28, 2026
Merge main (plxnative#1103, plxnative#1106, plxnative#1108, Polish locale and the playback work) into the owner-stamp branch.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Signed-off-by: Heiko Kopp <[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.

Browse discovery: the Library's section discovery leaves as a store job, with the client decided from ClientKeys

1 participant