PR #496 — Coalesce shared ancestor reads across concurrent Selene disk fetches
Review lens B: architecture and scope — does this change belong in the repository, and is the approach right? Judged against the project charter, AGENTS.md, docs/design-review.md (not opened) and docs/prefix-cache-offload.md. Head commit 0c04b1e2; 3 files, +3358/−933 (selene/src/disk_store.rs, selene/src/shard.rs, docs/prefix-cache-offload.md); no CI checks at head.
Key findings
- No blocking findings. The change is in the right layer and is justified by the kind of evidence the charter demands.
- Should fix (layering): a store-local metering sample was added as a variant of
TransportEvent(selene/src/disk_store.rs:97-101), the enum that is also the cross-rank wire event set.Kind::ofmust therefore panic on it (selene/src/shard.rs:476-478), and that invariant is upheld only by hand-writtenif matches!(…)guards at the two places that would otherwise see it (shard.rs:722-725, :1148-1150). The existing shard test helper at selene/src/shard/tests.rs:339 mapsKind::ofover aSharded's event list and would panic if any fetch ran in those tests. - Nit:
inbound_ratenow measures pure disk-thread time (oneO_DIRECTread +xxh3,disk::Reply.elapsedset only aroundworker.execute, selene/src/disk.rs:447-454), soDiskStore::hit().estimated_secondsprices restores optimistically even for a single restore — whileCompositeStoremeasures something different (composite.rs:994-1004). - Held (process): the design decision — a second reference-counted inbound lifecycle inside
Stagedrather than insideDiskThread— is now argued in the PR's Why section, so the remaining ask is only that a maintainer record the decision (AGENTS.md:204-206; docs/design-review.md:64-68 (not opened)), not that the code change shape. - Everything else in the lens holds. All four should-fixes from the previous revision are genuinely fixed at this head.
Scope: does this belong in the repository?
Yes. The charter's "What gets merged" includes a reproducible measured performance/memory issue, and AGENTS.md:165-166 accepts a measured performance problem as sufficient justification. The PR reports a concrete problem (8 concurrent branch restores of distinct checkpoints that share a disk-resident ancestor each repeat the same O_DIRECT opens, reads and xxh3 verification; up to 18.2 GB read for a ~61K-token shared prefix) and a result measured on a served workload — flare run with 8 concurrent /v1/chat/completions follow-ups, ingress-to-first-token TTFT, before/after against main c0c4f798 at head 0c04b1e2: physical NVMe reads 18,177.5 → 4,306.7 MB (−76.3%, 4.22×) and median burst TTFT 7,974.6 → 5,662.8 ms on Qwen3.8-27B-NVFP4 TP1. That is exactly the charter's "Performance PRs need benchmarks showing an actual speedup over main on a served workload". The area is covered by the charter goal to "Store prefix-cache checkpoints in host memory and share them across Flare instances via Selene".
Nothing found against the rejection criteria that usually catch changes of this shape:
- No unapproved scope expansion (AGENTS.md:171-175): no CPU/non-NVIDIA path, no backend swap, no orchestration, no serving-path change.
- No architectural violation (AGENTS.md:176-181): host-side Rust I/O bookkeeping only — no CUDA in
selene, no eager serving, no runtime compilation, no model knowledge. - No per-model special case and no new knob: no model names, no
cfg-gated alternative production path, no env var, no recipe field. Sharing is derived from(path, expected Header)identity viaHeaderIdentity/SegmentKey(disk_store.rs:1001-1064, acquisition at :1425-1462), so it generalises the way the charter's "No per-model special cases or flags" requires. The only new conditional compilation is#[cfg(any(test, feature = "test-support"))]on the diagnostic counters (:200-208, accessors :1279-1295), which does not create a production path difference. - No compatibility break: records stay immutable and pinned,
Headerand the on-disk layout are untouched, there is no core re-export, andHeaderIdentity's field list mirrorsHeader'sPartialEq(compare selene/src/shared/record.rs:136-152 with disk_store.rs:1014-1050), so the sharing key cannot collide two headers that compare unequal.WINDOWS_IN_FLIGHTstill derives fromcrate::shared::WINDOW_CREDITS(:60). The wire protocol'sKindcodes are unchanged because the sample is never forwarded (shard.rs:1148-1150). - Failure isolation keeps the "don't swallow the error" rule: a private child or follower GPU-upload error fails only that restore (
record.fail, :1538-1553, :1652-1660); a shared segment open/read error is converted withwith_record_read()and fails every attached restore after in-flight I/O drains (:1509-1536, :1620-1638); andDiskStore::applystill routesis_record_read()failures toindex.drop_row(:3676-3682). The measurement/metering split the PR introduces is documented:StoreStats.bytes_incounts logical restored bytes (:3669) whileDiskStoreupdatesinbound_ratefrom physical window reads (:3632-3635), stated in docs/prefix-cache-offload.md:362-366.
Approach: is the layering right?
Should fix — a store-local statistic rides the transport event channel and forces unreachable!() in the sharded protocol mapper
selene/src/disk_store.rs:97-101, selene/src/shard.rs:476-478, selene/src/shard.rs:722-725, selene/src/shard.rs:1148-1150, selene/src/shard/tests.rs:339.
What is wrong. TransportEvent::InboundWindowSample { bytes, elapsed } was added to the enum whose own doc comment is "Completion the transport reports to the disk store" (disk_store.rs:83), and every other variant is a job completion carrying a JobId. This one carries no id: it is a per-window bandwidth sample for DiskStore's own Rate:
- produced inside
Staged::pump_device_inboundwhen a shared window finishes its physical reads (samplebuilt fromwin.read_bytes/win.read_elapsed, pushed at disk_store.rs:1617-1620), - consumed by a short-circuit at the top of
DiskStore::apply(disk_store.rs:3632-3635:if let TransportEvent::InboundWindowSample { bytes, elapsed } = event { self.inbound_rate.observe(bytes, elapsed); return; }), with aunreachable!()immediately below at :3638.
Because the same enum is what shard::Sharded serialises between ranks, Kind::of now has to panic on this variant (shard.rs:476-478: unreachable!("window rate samples stay local to rank zero")). That invariant exists only as hand-written guards at the two call sites that would otherwise map it: Sharded::absorb_local pushes the sample straight into self.events instead of routing it through Kind::of (shard.rs:722-725), and Peer::forward drops it (shard.rs:1148-1150). Anything else that maps Kind::of over a Sharded's events panics — including the existing test helper events.sort_by_key(|event| Kind::of(event).1) at selene/src/shard/tests.rs:339, which survives today only because the tests that use it (events_and_peer_file_names_round_trip_and_reject_paths and neighbours, shard/tests.rs:338-345) issue stores/unlinks and no fetch. The disk-store side has the same shape in test code: the helper that drains events has to filter the sample out by hand (disk_store.rs:6341), and the coalescing test that wants it matches it out of the stream explicitly (disk_store.rs:9145).
Why it matters. This is the "solve the right problem in the right place" and "reject unsupported abstractions" rule (charter line 9; AGENTS.md:188-193). A variant with no job id is not a transport completion, and adding it makes the cross-rank protocol mapper responsible for a rank-local statistic: Kind::of goes from total to partially-defined over its own input domain, and its totality now depends on two guards far from it. The fix needs no new machinery — the store already reads Staged state directly for in_flight() and pool() in stats/poll, so the same route works for a pair of window_bytes/window_elapsed accumulators drained by a Staged method; alternatively fold the physical counters into StoreStats (selene/src/store.rs:227-244), which also makes coalescing visible outside unit tests. I would not insist on which of those, only that the wire event set stops carrying a metering sample. A test that asserts Kind::of is total over every TransportEvent (or a property test over the enum) would settle the panic path definitively; today only reading the two guards shows it.
Nit — inbound_rate now measures pure disk-thread time, so estimated_seconds prices restores optimistically
selene/src/disk.rs:447-454, selene/src/disk_store.rs:3615-3627, selene/src/disk_store.rs:1597-1620.
The sample's elapsed is disk::Reply.elapsed, set in disk::run around worker.execute(job) only (disk.rs:448-450) — one direct I/O read plus xxh3, with no wait for a free slot, no copier queue time, and no GPU upload. Before this revision the rate was observed as record bytes over job.started.elapsed() from DiskStore::fetch to Fetched, which spanned queueing and the upload (that field has been removed; the Fetched arm now only does self.stats.bytes_in += bytes, disk_store.rs:3669). Since hit() divides by the rate (estimated_seconds: bytes as f64 / self.inbound_rate.get().max(1.0), disk_store.rs:3625) and that value is consumed by worth_fetching/worth_transfer (selene/src/store.rs:422-438), by restore deferral in the runtime, and by the host_cache_inbound_rate metric, restore estimates are now optimistic by the staging/upload share even for a single restore — the opposite direction from the inflation this revision fixed. CompositeStore prices the disk part on its own disk_inbound_rate observed from read_into completions (selene/src/composite.rs:994-1004), so the two stores now measure different quantities under the same name. Fix: either document inbound_rate explicitly as device read bandwidth and keep a separate end-to-end restore estimate for estimated_seconds, or include the per-record wait in the sample. Only a run can quantify the factor; a test comparing estimated_seconds against a measured single-restore wall time would settle it.
Held (process, not a code ask)
The design call — putting a second, reference-counted inbound lifecycle (SharedSegment with a five-state file machine, SharedWindow with disk_referenced + upload_referenced, out-of-order PlanState completion, demand indexing, "close only when settled") inside Staged, in shared cache machinery, rather than in DiskThread — is now argued in the PR's Why section on technical grounds (DiskThread sees only file offsets and raw host addresses and finishes once direct I/O and xxh3 complete, whereas staging slots must stay pinned until every follower's asynchronous Copier upload completes). That satisfies docs/design-review.md:64-68 (not opened) in substance. What remains is that a maintainer record the decision (AGENTS.md:204-206), since it replaces Staged's single inbound lifecycle and the invariants that went with it. I am not asking for the code shape to change; I am asking that the choice not be settled implicitly by merge.
Previously reported on the earlier revision, now verified fixed at 0c04b1e2
- Logical/physical byte conflation in the rate. Fixed:
DiskStore::applynow short-circuitsInboundWindowSampleintoself.inbound_rate.observe(bytes, elapsed)(disk_store.rs:3632-3635) and the old per-recordobserveinside theFetchedarm is gone;stats.bytes_instays logical (:3669); the split is documented at docs/prefix-cache-offload.md:362-366. - Module contract contradicting the code. Fixed: disk_store.rs:7-27 now describes per-fetch window credits, shared handles with followers, and "the last user of a shared segment holds its
TransportEvent::Fetchedevent until the file close settles on the disk thread"; the old "at mostWINDOWS_IN_FLIGHTwindows of one record staged at a time" / "Nothing here waits" text is gone. - Docs asserting coalescing unconditionally with stale signatures. Fixed: docs/prefix-cache-offload.md:337-366 now gives the real signatures
write_from(id, header, temporary, path, pages, row, sums)andread_into(id, path, expected, first_page, pages, row), states that sharing covers only windows still live in staging ("so a window released before a later restore attaches is read from disk again"), and states the ≤1 extra partial window whenskip_pages % WINDOW_PAGES != 0; the metrics split is stated too. - Evidence staleness. Addressed: the table is now keyed to
main c0c4f798vs0c04b1e2, with un-rerun items listed honestly under "Not covered". - Coalescing counters hidden outside tests. Gated deliberately under
#[cfg(any(test, feature = "test-support"))]rather than left as productionallow(dead_code)dead code — accepted; the remaining suggestion to surface them viaStoreStatsis subsumed by the should-fix above.
Open questions / what could not be settled from the code
- Whether the
InboundWindowSamplelayering should be fixed by aStageddrain method or by counters inStoreStats— both remove the wire-protocol coupling; the choice is a maintainer call for internal API shape. - The numeric size of the
estimated_secondsoptimism (nit) needs a run or an instrumented test; the code shows only the direction. - Maintainer sign-off to record the
Staged-vs-DiskThreaddesign decision (held note) — not something a reviewer can settle. - Out of this lens and unverified here: multi-host RoCE serving, 2-GPU
split_pools, discrete PCIe GPUs, Windows serving and liveCompositeStore/PooledStoreGPU serving are listed as "Not covered" by the PR and are covered by other lenses.