Review — PR #496 "Coalesce shared ancestor reads across concurrent Selene disk fetches"
Lens A: correctness and consequences (callers, configurations, lifetimes, inactive/edge paths, state transitions, existing data).
Scope note. This is a partial review, stated honestly. I read the charter, AGENTS.md and docs/design-review.md, the whole new device path in selene/src/disk_store.rs, the disk/slab/geometry support code, and the consumers DiskStore::apply/hit, plus the host path consumers. I did not read the new test module past line 8420, the #497 interaction, or the Windows IOCP / helios GPU-offload paths. I found no blocking correctness defect in the paths I read; the two items below are a real accounting/policy consequence and an unexplained accuracy data point in the PR's own evidence.
Key findings
- Bytes accounting double-counts coalesced reads, and that leaks into scheduling. Every follower adds the full
win.read_bytestorecord.bytes(disk_store.rs:1829), the window accumulates them once per reply (:1530), andapplyspends them on bothstats.bytes_inandinbound_rate.observe(bytes, started.elapsed())(:3626,:3628). A coalesced burst therefore reports close to the pre-PR logical byte total while measuring the post-PR (4× shorter) wall time, soinbound_rateinflates roughly with the fan-out.hit()prices future restores with that rate (:3587) andworth_fetchinggates on it (selene/src/store.rs:423-438), so a request that will not be coalesced (single arrival, no sibling inStaged) is under-priced and may be fetched when prefill would have been cheaper. The physical-read win the PR measures (18,026 MB → 4,286 MB) is invisible instats.bytes_in, which the new doc paragraph (docs/prefix-cache-offload.md, section 2.4, +5/−1) does not say either. - The PR's own evidence contains an unexplained accuracy regression at 61.3K. "Live SM121 checks" reports Qwen3.8-27B TP1
9/9on main vs7/9with this PR at61.3Ktokens (8/9→7/9on the retrieval prompt). Everything else is asserted to be byte-exact, so either the retrieval harness is noisy at that context length or the shared-window fan-out corrupts something at a page/row boundary that the tests do not reach. This is the single most important thing to settle before merge, because it is the only signal pointing at data corruption in the changed path. - The
closediagnostic silently regressed (nit) — the only place where an operator learns a drain was abandoned now under-reports. - The lifetime design holds up on the paths I traced (see "What I checked and found sound"), including slot pinning, upload/disk reference counting, and ordering against segment removal.
Angle A — correctness and consequences
Should fix
A1. Coalesced logical bytes feed stats.bytes_in and inbound_rate; the rate inflates with fan-out. selene/src/disk_store.rs:1089 (read_bytes: u64), :1530 (win.read_bytes += reply.bytes), :1829 (record.bytes += win.read_bytes per follower), :3626 (stats.bytes_in += bytes), :3628 (inbound_rate.observe(*bytes, job.started.elapsed())), :3587 (estimated_seconds: bytes as f64 / self.inbound_rate.get().max(1.0)); consumers selene/src/store.rs:418 (INITIAL_STAGED_DISK_RATE), :423-438 (worth_fetching/worth_transfer).
What is wrong: the window is read once, but each attached follower is charged the whole window in record.bytes (:1829), so the completion is reported with the full logical byte count and the coalesced elapsed time. Rate::observe therefore measures a throughput that is followers× the physical one for the duration of the burst.
Why it matters: inbound_rate is not a statistic here, it is an input to admission. hit() converts it into estimated_seconds (:3587) and worth_fetching compares that against prefill cost (store.rs:423-438). After a coalesced burst the store believes disk restores are ~4× cheaper than they are for a lone request, so lone requests whose restore would not pay off get admitted; conversely stats.bytes_in reports no reduction at all, so the documented, measured 4.21× read reduction is invisible to the operator counters the doc paragraph (docs/prefix-cache-offload.md section 2.4) just told them to interpret.
Fix: either (a) divide the credit (charge each follower win.read_bytes / followers_at_read_time, or accumulate physical bytes per window and observe the rate on the window rather than per follower), or (b) keep the historical definition but make it explicit — a comment at :1829 and one sentence in the section 2.4 paragraph saying bytes_in remains logical bytes and coalescing is not visible there. If (b), the rate used for scheduling should still be measured on physical bytes or on non-coalesced restores only.
Severity: should fix (policy/stats consequence, not a memory-safety or data bug).
A2. Unexplained 8/9 → 7/9 retrieval result at 61.3K. Source: PR #496 description, "Live SM121 checks" (9-fact numerical retrieval, temperature = 0, cold-VRAM restart, Qwen3.8-27B TP1, 61.3K tokens; main 8/9, this PR 7/9; 30.1K is 9/9 on both, DeepSeek TP4 9/9 at 23.1K/47.1K).
What is wrong: a deterministic retrieval evaluation is reported as worse with the change and no explanation is offered beyond "recipe-clamped", while the PR simultaneously claims byte-exact coalescing.
Why it matters: this is the only end-to-end check that exercises the new shared-window fan-out on a real model, and it is the one that regressed. If it is a real defect it would be in plan_aligned_windows (:700-738) offset/count mapping for a follower whose first page is not 64-aligned, or in the trailing partial chunk / row flag (row && chunk_end == end, :730), where a follower attaching to a window that another restore created could read the wrong page into its upload.
Fix / what would settle it: re-run the 61.3K prompt N times on both revisions and report variance; if it is real, add a test where a follower attaches to an already-created shared window with a non-64-multiple skip_pages and a shared final partial chunk, and assert every device page/row byte-equal against the private path (the existing "misaligned skip_pages" tests cover a single restore's plan, not follower-attachment to another restore's window). Note this is exactly the pair of risks I could not close out: I did not read the test module past line 8420.
Severity: should fix (needs resolution before merge; may collapse to a description fix if re-runs show noise).
Nit
A3. Staged::close abandoned count under-reports. selene/src/disk_store.rs:2485-2489 vs the old let abandoned = self.owners.len();. New code is (outbound + host_inbound + device_inbound + maintenance).max(usize::from(self.busy())), and busy() (:2344-2351) is a bool that also covers shared_segments, shared_windows and owners. A drain held only by those three maps reports "1 disk transport jobs did not complete within …" (:2501-2505) instead of the previous owners.len().
Why it matters: diagnostic only — the error is still returned and the pool is still leaked on failure (:2495-2499), so no lifetime change. But an operator sizing copier::CLOSE_TIMEOUT or distinguishing a hang from a slow drain loses the count exactly in the coalesced case this PR introduces (a close that outlives in-flight shared disk jobs).
Fix: count outstanding disk jobs before the disk.and(transfers)?, e.g. self.owners.len().max(1) as before, or owners.len() + maintenance.len().
What I checked and found sound (no finding)
- Slot lifetime. A shared window is only released when
followers.is_empty() && disk_referenced == 0 && upload_referenced == 0(:1755-1771); every path that can remove a segment first requiresactive.is_empty()(Pass 5e,:2213-2230) or refuses to detach while an upload is busy (:1737-1741), soapply_device_transfer(:1548-1566) cannot drop a reply whose window was freed.allocate(plan.count, plan.row)matchesrecord_slots/the free-slot precheck inpick_next_pending_plan(:1701-1704). - Demand ordering.
build_pending_demand(:1647-1679) keys on(path, first, count, row)with a per-record de-duplication set and a header disambiguator;pick_next_pending_plan(:1684-1724) prefers windows with sibling demand and falls back to a scan when demand is empty, so a single fetch behaves as before (device_inbound.len() <= 1short-circuit at:1651). - Host path unchanged.
HostInbound(:759-997) keepsplan_windows(:672-695, unaligned) and private per-restore opens, soCompositeStore(selene/src/composite.rs:802-836) sees no behaviour change; the doc's "caller-ownedread_intoreads run independently" is accurate. - Failure isolation. Private upload/child failures go through
record.fail(:1563-1565); shared open/read failures go throughfail_segment_users(:1449-1473) andfail_window(:1475-1487), which mark onlyReadingwindows failed and are exercised by the PR's stated tests. Fetchedemission.pump_device_inboundPass 5e (:2213-2230) withsegment_needs_disk_reads(:1773-1801) keeps the segment open (Closing→Closed) until outstanding I/O drains, matching the description's "last user waits for file close".Staged::pump_allorder (:2268-2289) runs outbound, thenhost_inbound, thenpump_device_inbound, consistent with the description's note that#497must rebase on this.
Open questions / not covered
#497rebase: both PRs touchStaged::pump_all; merge order is asserted in the description ("merge this PR first"), not verifiable from this branch alone.- A follower attaching to a
Readingwindow in a segment that closes in the same pump — my trace says it is safe viausers/settled/disk_outstanding(:1037-1049,:1773-1801), but I did not read the tests that pin it. pending_row_readsFIFO matching (:1030-1032,:1512) is correct only if every intendedReadRowjob is actually submitted on the same disk id; I did not read the submission side far enough to rule out a dropped submission permanently stallingdisk_outstanding(which would makeStaged::closehitCLOSE_TIMEOUT). A test that forces a submission shortfall would settle it.heliosGPU-offload, Windows IOCP serving, discrete PCIe GPUs, liveCompositeStore/PooledStoreGPU serving were explicitly not run by the author and not reviewed here.- Benchmark provenance: the table was measured before the linear demand-index and close-count edits at head
f9c9191, and the description says so; the TTFT numbers should not be read as attributable to the merged code. - Existing data/artifacts: no record-file format, header or re-export change (
selene/src/disk_store.rsonly), so previously written checkpoint files load unchanged — consistent with the description; I saw no format touch in the diff.