PR #496 — Coalesce shared ancestor reads across concurrent Selene disk fetches
Review lens B: architecture and scope (does it belong, is the approach right), judged against the charter, AGENTS.md, docs/design-review.md and docs/prefix-cache-offload.md. Head commit f9c9191; 2 files, +2808/−914.
Key findings
- The change quietly redefines the store's own bandwidth metric.
SharedWindow::read_bytesis one physical quantity per window (selene/src/disk_store.rs:1530,win.read_bytes += reply.bytes), but every follower adds the whole of it to its own record (selene/src/disk_store.rs:1829:record.bytes += win.read_bytes;). That per-record byte count is theOkpayload ofTransportEvent::Fetched(2235, 2251) and drivesself.stats.bytes_in += bytesandself.inbound_rate.observe(*bytes, job.started.elapsed())(3626-3628). Before this PR each restore read its own windows, sobytes_inand the observed rate were both physical. Now physical reads drop up to 4.21x (the PR's own table) while the rate sample stays at the logical byte count, inflating the measured inbound rate toward the coalescing factor — andDiskStore::hit()prices restores withbytes / self.inbound_rate.get()(3587). This is a behaviour change the description does not mention. - The module's stated contract is now wrong. The PR updated the header to describe sharing (lines 14-19) but left "in windows of at most [
WINDOW_PAGES] pages with at most [WINDOWS_IN_FLIGHT] windows of one record staged at a time" and "Nothing here waits" (lines 8-24) in place, while device restores now run out-of-order plans over reference-counted shared windows whose segments stay open across jobs and whose last user waits for close (2205-2255). - The doc claim is stronger than the mechanism.
docs/prefix-cache-offload.md:337-342says concurrent fetches "share one open file handle and coalesce aligned 64-page windows while staged", without the caveats the PR description itself discloses (windows already released are read again by later arrivals; up to one extra partial window whenskip_pages % 64 != 0), and the same edited paragraph keeps stale signatures. - Everything else in the lens holds: right layer, no per-model or environment switches, no format or core re-export change, failure isolation preserved, and the performance evidence is of the kind the charter asks for.
Scope: does this belong in the repository?
Yes, in principle. The charter's "What gets merged" includes "a measured performance/memory issue" (charter, Standards & Contributions), and AGENTS.md:165-166 says a measured performance problem is sufficient justification. The PR reports a measured problem (8 concurrent branch restores repeating the same ancestor O_DIRECT opens and reads, up to 18.0 GB read for a 61.3K shared prefix) and a measured result on a served workload (flare run, /v1/chat/completions, TTFT), which is exactly what the charter's "Bring real evidence" line requires (charter: "Performance PRs need benchmarks showing an actual speedup over main on a served workload (#210)"). The area touched — Selene's disk transport — is covered by the goal "Store prefix-cache checkpoints in host memory and share them across Flare instances via Selene."
Nothing found for 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 architectural violation (AGENTS.md:176-181): the change is host-side I/O bookkeeping in Rust, with no CUDA, no eager serving, no runtime compilation, no model knowledge.
- No per-model special case, no new flag, env switch or config knob — sharing is derived from
(path, expected Header)identity (find_reusable_window,acquire_shared_segment), which matches design-review.md:31-32 (replace the smallest coherent module) and :80-90 (settings belong in recipe declarations — none added here). - No format or core-contract change: records remain immutable and pinned, no
Headerchange, no re-export; design-review.md:106-113 compatibility is untouched. - Failure isolation keeps the "don't swallow the error" rule (charter, AGENTS.md:182-187): private child/upload errors fail only their restore, shared open/read errors are converted with
with_record_read()and fail all attached restores after in-flight I/O drains (fail_segment_users,fail_window), andTransportEvent::Fetchedstill routesrecord_readerrors toindex.drop_row(endpoint)(3634-3640). The counterstats.abandoned_storespath and the outbound path are unchanged.
Approach: is the layering and complexity right?
Finding 1 (should fix, high) — logical and physical bytes are conflated, inflating the inbound rate used for restore pricing.
selene/src/disk_store.rs:1530, :1829, :3626-3628, :3587.
SharedWindow.read_bytesaccumulates the physical reply bytes once per window (1530:win.read_bytes += reply.bytes;, initialised at1979).- Each follower that completes an upload adds the entire window's
read_bytesto its own record (1829:record.bytes += win.read_bytes;), so N followers each count the full window. - That per-record count becomes the success payload (
2235:None => Ok(record.bytes)), hencestats.bytes_in += bytesandinbound_rate.observe(*bytes, job.started.elapsed())(3626, 3628). inbound_rateis the divisor inDiskStore::hit().estimated_seconds(3587), i.e. the restore cost the host tier advertises when choosing what to serve, and is surfaced asinbound_rateinStoreStats(selene/src/store.rs:242-243, filled atdisk_store.rs:3848).- Why it matters: with coalescing the physical device bytes are up to ~4x lower than what the rate sample subtracts, so the store reports a device bandwidth it never achieved, and restore estimates used for tier choice become optimistic by roughly the coalescing factor under concurrency.
docs/prefix-cache-offload.md:1501-1502defines "Inbound latency" and "Copy-out bandwidth" as coming from store counters, so qualification measurements of disk bandwidth stop meaning device bandwidth exactly in the concurrent case this PR targets. That is a "measured evidence for performance claims" problem as much as a metering one. - Fix: observe the rate from physical window bytes — count a window's bytes once at window/segment completion rather than per follower — and keep
bytes_inas the logical restored-bytes counter, documenting the distinction in §2.5/§4. A unit test assertingbytes_in == sum of physical reads x followersand a stable rate across 1 vs 8 concurrent restores of the same prefix would settle it; only a test can pin the numeric effect.
Finding 2 (should fix) — the new ownership protocol is a large addition to shared cache machinery and the module contract no longer matches it.
selene/src/disk_store.rs:8-24, with the protocol at 1000-1160 (SharedSegment/SharedWindow/DeviceInbound), 2205-2255.
- The file gains five new lifecycle types and a five-state file machine (
SharedFileState), two reference counts per window (disk_referenced,upload_referenced), out-of-order plan completion (PlanState), linear demand indexing (build_pending_demand) and a "close only when settled" rule at 2205-2255. The description discloses the intent, but AGENTS.md:188-193 ("Reject unsupported abstractions and churn… Refactoring must directly support the requested behavior or remove a demonstrated source of defects or cost") and AGENTS.md:204-206 ("Resolve conflicts through an explicit maintainer decision on the design before implementing a change to that invariant") put the burden on a design decision here, not on review-time inference: this replacesStaged's single inbound lifecycle — the invariant that made "Nothing here waits" true — with two lifecycles (host vs device) inside shared cache policy. Recommendation: keep the technical content, but ask the maintainer to record the decision, including the alternative the PR does not discuss — doing the coalescing inside the disk thread, which already owns the file handle, instead of insideStaged. - Second, concrete: the header still says windows are bounded to "at most [
WINDOWS_IN_FLIGHT] windows of one record staged at a time" and "Nothing here waits" (lines 14-24). Device restores now hold shared windows past their own completion until followers finish, and a restore can be complete-but-not-reported while it waits forseg.settled()(2221-2232). Optionally: rewrite the module andStageddoc comments so the two-window credit, follower sharing, and the settle-before-Fetchedrule are stated; otherwise the next reader of the header misreads the invariants. This is a docs fix attached to a design point, hence "should fix" rather than a nit.
Finding 3 (should fix) — the doc states coalescing as unconditional and keeps signatures that do not exist.
docs/prefix-cache-offload.md:337-342.
- New text: "Concurrent
fetchjobs reading the same record file share one open file handle and coalesce aligned 64-page windows while staged so one disk read fans out to each attached fetch's GPU upload before its staging slots are released; caller-ownedread_intoreads run independently." Two material limits disclosed in the PR description are absent: a window already released before a later arrival attaches is read again (best-effort, timing-dependent), and a restore whoseskip_pages % WINDOW_PAGES != 0now splits up to one extra partial window. Per AGENTS.md:194-199 ("Do not present scaffolding or partially wired features as supported… describe its problem, resulting behavior, validation, and material limitations") §2.4 should say so. - Same paragraph:
write_from(key, metadata, buffers)andread_into(key, buffers)do not exist; the real signatures arewrite_from(id, header, temporary, path, pages, row, sums)(selene/src/disk_store.rs:1242-1251) andread_into(id, path, expected, first_page, pages, row)(1268-1276). Pre-existing, but the sentence is being edited anyway.
Compatibility with what exists
Nothing found. No record-format, header, or on-disk layout change; sharing keys on (path, expected Header), so records written by main are read unchanged. WINDOWS_IN_FLIGHT still derives from crate::shared::WINDOW_CREDITS (line 60). Host-path callers (CompositeStore, host_inbound) keep the private path via plan_windows (now documented as "for caller-owned host reads", line 670), so the read_into contract is preserved. Staged::in_flight() correctly grows to host_inbound.len() + device_inbound.len() (1210-1217). The stacked-companion note (#497 also edits Staged::pump_all) is a merge-order cost, not a compatibility defect.
No per-model special cases, flags, or new knobs
Nothing found. No model names, no cfg-gated alternative paths, no env vars, no recipe fields. The only new conditional compilation is test-support-gated counters (see nit 2), which does not create a production path difference.
Measured evidence for the performance claims
The evidence is real and of the right shape (served workload, before/after on main at 425ab2d4, physical NVMe bytes via device counters, TTFT). Two reservations, both non-blocking:
- Nit 1 — the numbers predate the code under review. The PR's "Not covered" note says the single-pass SM121 runs were not repeated after the linear demand-index edit or the rebase, and the table was measured before those edits. Those edits change scheduling (pass 2 demand attach ordering) — precisely what produces the shared windows. AGENTS.md:194-199 requires the claimed result to be tied to what is under review; re-run at least one TP1 simultaneous and one staggered configuration at the head commit, or label the table as measuring an earlier revision. The honest disclosure in the description is the reason this is a nit rather than a blocker.
- Nit 2 — coalescing is unobservable outside unit tests.
disk_opens,disk_window_reads,coalesced_windowsexist onResourceswithallow(dead_code)outside tests (lines 192-200) and are exposed only undercfg(any(test, feature = "test-support"))(1213-1236). Combined with finding 1, nothing in a production or qualification run can show whether sharing happened or how many physical bytes it saved, while §4 of the offload doc gates defaults on store counters (docs/prefix-cache-offload.md:1501-1502). Consider folding the three counters intoStoreStats(selene/src/store.rs:227-243) — no flag or per-model implication, and it makes both the mechanism and the metering fix checkable.
Open questions / what could not be settled from the code
- Whether maintainers consider coalescing inside
Staged(a new shared lifecycle) or inside the disk thread (which already owns the handle) the right layer — only a maintainer design decision settles finding 2. - The numeric size of the rate inflation (finding 1) needs a test: read one 61.3K-token prefix with 1 vs 8 concurrent restores and compare
StoreStats.inbound_rateagainst measured device bytes. Code shows the direction; only a run shows the factor. - I did not reach
helios/src/server/metrics.rs(not opened) to confirm the metric label forinbound_rate; the consumption inhit().estimated_seconds(3587) andStoreStats(store.rs:242) is confirmed in the code.