Review of PR #496 — lens D (simplicity), head cb3db468 (rebased onto 6d74db3a)
Verdict: should-fix issues only. No blocking findings. One should-fix and five nits, each with a smaller version. Nothing here argues against the approach: the +8470/−5627 in selene/src/disk_store.rs is requirement, not churn (see "Scale judgement"), and no flag, format or per-model branch was added.
Key findings
- The packed-window byte span is now written three times (
selene/src/disk_store.rs:2650-2667,:1333-1345, and the pre-existingselene/src/pool/pins.rs:338-351). The two new copies sit in the two paths whose whole justification is that they agree byte-for-byte, so a divergence is a wrong-offset read — corrupt restored pages, not a compile error. This is the one item I would fix before merge. - The single-segment host inbound path is still modelled as a collection (
disk_store.rs:1108-1119): aVec<Segment>that always holds one element, an always-zeroOwner::HostInbound(JobId, usize)index (:276), a tolerantget_mut, and areads_leftcounter (:1004, set at:1820/:1859, tested at:1255) thatself.done == self.plans.len()at:1270already answers. disk_window_readsneeds a per-windowdisk_read_countedflag (:1101,:1552, sixcfgblocks) purely so a test metric counts windows rather than read jobs — test-gated, so it costs no shipped weight, only reader time.- An unreachable lazy build in the pending-plan pass (
:2479):demandisSomewhenever any work can proceed, and theNonecase breaks two lines earlier. Staged::closestill reports a number that is not a job count (:3192-3194, message:3214-3218).
Rules cited
- Charter line 9 — "Solve the right problem in the right place… Look for the smallest footprint in shared code, or a way to solve it without new code at all." The basis for the should-fix and every nit.
- Charter line 43 (no per-model special cases or flags) — this PR adds none; checked.
- AGENTS.md (not opened) (not opened — 188-193) — do not add abstractions, extension points, speculative compatibility, fallback layers or configuration switches without a concrete requirement; "Refactoring must directly support the requested behavior or remove a demonstrated source of defects or cost." Basis for both the deletions below and for judging the diff size not to be churn.
- AGENTS.md (not opened) (not opened — 194-199) — require focused, meaningful validation; "source-text checks and mocks that bypass the behavior cannot establish runtime correctness." Satisfied: the new tests assert byte-exact
SimulatedGpupages and physical open/window counts at the real disk-submit sites.
Should fix
S1. selene/src/disk_store.rs:2650-2667 and :1333-1345 — the packed-window byte span is now written three times
Both blocks compute the same (offset, length) for a v4 window from packed::Layout:
start_rel = if count == 0 && row { layout.page_offset(layout.page_count()) } else { layout.page_offset(first) };
end_rel = if row { layout.physical_bytes() } else { layout.page_offset(first + count) };
offset = page_segment + start_rel;
length = usize::try_from(end_rel - start_rel)?; // "packed window length overflow"
:2650-2667— shared device path,Job::ReadPackedsubmitted from the shared segment.:1333-1345— private host path,submit_readsforread_into_packed.- Third, near-identical copy already at
selene/src/pool/pins.rs:338-351(packed put window).
Why it matters: the shared and private device paths must produce identical offsets or followers decode the wrong bytes; the failure mode is corrupt restored pages, not a compile error. A future change to Layout (a row split, per-window alignment) has to be made in three places, and two of them are in the same file with no test asserting they agree.
Fix: add impl packed::Layout { pub fn window_span(&self, first: usize, count: usize, row: bool) -> (u64, usize) }, keep the usize::try_from overflow error in the caller, and call it from all three sites. Removes ~20 lines and gives the three callers one rule.
Nits
N1. selene/src/disk_store.rs:1108-1119 — a single-segment HostInbound is still a Vec with a per-segment counter
segments: Vec<Segment> (:1109) is only ever built as vec![segment] (:1824, :1863-1867); Owner::HostInbound(JobId, usize) carries a permanently-zero index (:276, inserted at :1814, :1853); lookups are tolerant segments.get_mut(segment) where an index can never miss; and Segment::reads_left (:1004) is set to 1 (:1820) or plans.len() (:1859), decremented at :1175/:1204, and consulted only at :1255 — at which point self.done == self.plans.len() (:1270) says the same thing.
Why it matters: three fields and a counter exist to model a set of one, and the redundant counter is a second source of truth for "is this read finished".
Smaller version: struct HostInbound { segment: Segment, .. }, Owner::HostInbound(JobId), close when self.done == self.plans.len() && segment.settled(). The one behaviour change is that the file close waits one more pump; no ordering changes.
N2. selene/src/disk_store.rs:1101, 1552 plus six cfg blocks — disk_read_counted exists only so disk_window_reads counts windows rather than read jobs
disk_read_counted is set on HostWindow (:1101, initialised :1315, three cfg sites :1352-1356, 1377-1381, 1395-1399) and on SharedWindow (:1552, initialised :2559, three cfg sites :2689-2693, 2725-2729, 2753-2757), and read only to increment resources.disk_window_reads. Both the flag and the counter are behind #[cfg(any(test, feature = "test-support"))], so nothing ships — the cost is code and reader time.
Smaller version: count once at window creation, where pages_submitted/row_submitted are first set, and delete both fields and their six cfg blocks. If the extra state is wanted for the device path's separate page/row submissions, keep it and instead add one doc line to disk_window_reads (:1714-1718) naming its unit ("one per completed window, not per read job"), so the next reader does not have to reverse-engineer why the flag exists.
N3. selene/src/disk_store.rs:2479 — demand.get_or_insert_with(|| self.build_pending_demand()) is unreachable
demand is created Some when free_slots() > 0 || any_packed (:2464-2468); when it is None, every record breaks at :2474-2478 before reaching :2479.
Why it matters: dead fallback branches are exactly what AGENTS.md (not opened) 188-193 asks not to add; here it makes a reader wonder which path can be taken.
Smaller version: bind once before the loop (let demand_ref = demand.as_mut().expect("demand computed when work can proceed")) with a comment on why it is safe, or restructure so the None case skips the loop entirely.
N4. selene/src/disk_store.rs:3192-3194 — abandoned_jobs still maxes unrelated populations and reports the winner as a job count
let abandoned_jobs = store_jobs.max(self.owners.len()).max(self.maintenance.len());
store_jobs (:3188-3191) already sums outbound, host_inbound, device_inbound and the maintenance owners counted from owners (:3183-3187), so owners.len() covers those same jobs plus any with no job left, and maintenance.len() is a queue depth, not a count of stuck jobs. The sum is then reported as "{abandoned_jobs} disk transport jobs did not complete" (:3214-3218), and busy() (:3033-3040) already answers "is anything still pending".
Smaller version: report only store_jobs (or, better, invalid(format!("disk store still busy after {:?}", copier::CLOSE_TIMEOUT)) gated on busy()), deleting both .max()s. The accompanying shared-entry message is now separate (:3195, :3220-3225), which fixed the more confusing half of this.
N5. selene/src/disk_store.rs:10290-10347 — ObservedTransport is ~57 lines of forwarding that exist only to capture drain_inbound_samples
The test coalesced_restores_keep_inbound_rate_physical_and_bytes_in_logical wraps Staged in a struct that re-forwards store, fetch, truncate, unlink, poll, close, staged, staged_mut, codec_receive_profiles and decode_counters for the sole purpose of recording the samples passed through one method (:10324-10331). It also blocks the test from using the real DiskTransport impl, which is what the assertions are about.
Smaller version: expose inbound_samples() on Staged under #[cfg(any(test, feature = "test-support"))] beside disk_window_reads()/coalesced_windows() (:1714-1724) and read it after poll, dropping ObservedTransport and the Arc<Mutex<Vec<..>>> plumbing entirely. The assertions (2 physical samples, byte sum equals logical bytes, inbound_rate matches the recomputed Rate) survive unchanged.
Resolved since my previous report (listed, not re-reported)
- Docs §2.4 — the 30-line paragraph is now a two-line API sentence (
docs/prefix-cache-offload.md:418-423) plus three bullets: mechanism (:424-431), invariants (:432-438), limits and failure scope (:439-448). Thebytes_in/inbound_ratecontract appears once, in §4 (:1612-1617). record_slotsrestatement —pick_next_pending_plannow hoists the lock once (:2307) and callslayout.record_slots(plan.count, plan.row)(:2320), the same call the allocator makes; the hand-restatedcount + row_slotsis gone.HeaderIdentityhash —HeaderIdentity::hashdelegates toself.0.hash;impl Hash for Headeris exhaustive and sits besidePartialEq(selene/src/shared/record.rs:144-202,version: _omitted with a comment), with testheader_eq_implies_same_hashcovering version-insensitivity and a differingcreated/packedlayout.packed::LayoutEq+Hash are exhaustive overLayout/PackedOffer/PackedUnit(selene/src/shared/packed.rs:99-141);RankSizesderivesHash(record.rs:96).- Duplicate ids —
SharedSegment.id/SharedWindow.idare gone; both key offkey(:1488-1501,:1542-1562). - Dead guard — the old
demand.is_empty()check is now a plainmap_or/is_none_or(:2323-2326). TransportEvent::InboundWindowSampleis replaced by the out-of-bandinbound_samples(:1662-1663, pushed:2148-2150), drained viaDiskTransport::drain_inbound_samples(:150,:3165-3166), forwarded on rank 0 (selene/src/shard.rs:1005-1012) and discarded on peers (:1213-1214), observed onpoll/poll_transport/close(:3649-3664,:4640,:4678). NoStoreStats.progressinflation, no extra event variant.
Scale judgement — why +8470/−5627 is not churn under AGENTS.md (not opened) 188-193
- The host path must stay private.
CompositeStorepasses caller-owned registered buffers toread_intoand stores(Header, Arc<Vec<u8>>)forread_into_packed; those cannot be pinned inSlabPoolacross followers. SplittingHostInboundoff is the removal of a false commonality, not an added layer. - The device path needs the state it has.
SharedSegment(open job,next_disk_window, pending page/row reads, error, users) andSharedWindow(followers,disk_referenced,upload_referenced,read_elapsed,read_bytes) are what makes one read serve N restores while keeping uploads independent and failures isolated — the 4.2x read reduction is made of exactly this state. - No new switch or branch. The single
align_to_windowboolean onplan_windowsreplaces a second planner rather than adding to the API surface; no record-format, re-export orTransportEventchange (charter line 43). - No dead tests. Every new test names a behaviour that would otherwise regress: 4-way v4 packed coalescing and corrupt-packet propagation (
concurrent_packed_fetches_coalesce_opens_and_read_packed_windows,:10543-10855), physical-vs-logical metrics (:10287-10541), misaligned follower attachment with byte-exactSimulatedGpucomparison, simultaneous and staggered coalescing, private vs shared failure isolation, andStaged::closedraining. They assert bytes and counters at the real submit sites, so they are behaviour checks, not source-text checks (AGENTS.md (not opened) 194-199).
Checked and found clean in this lens
- One release point for shared windows:
sweep_shared_windows(:2361-2378) with idempotentrelease(:265-269); no second path frees a shared buffer. - Failure scope as documented:
fail_segment_users(:2040-2065),fail_window(:2067-2080), private child and follower-upload failures confined (:2156-2183). - Last-user close ordering before
Fetched(:2894-2944). read_into/read_into_packedremain private onHostInbound(called fromselene/src/composite.rs:886-889), so no caller-visible API grew.Sharded::drain_inbound_samplesdiscards rather than splits samples on peers (selene/src/shard.rs:1005-1012); rank 0 forwards.- Samples do not touch
StoreStats.progress;CompositeStorekeeps its own end-to-enddisk_inbound_ratefrom host read completions.
Open questions and limits
- No toolchain, GPU or test run was available to this review, and the head carries no CI checks. Every finding is established from source at
cb3db468. S1 and N1 are "would bite on a future edit" items: only a follow-up change topacked::Layout(or to the host inbound shape) could settle them definitively, and a test asserting that shared and private packed windows compute the same span would be the cheapest way to pin S1 in the meantime. docs/prefix-cache-offload.md§2.4 vs §4 drift is worth a maintainer eye on the next edit: the two now state thebytes_in/inbound_ratecontract once each (:439-448,:1612-1617) and must keep agreeing. I did not raise it as a finding because §4 is the normative statement and §2.4 only links to it.- Outside this lens and left alone: the benchmark table and FP32 logprob parity claims, the
Ratedecay/inbound_ratesemantics, and the multi-host/Windows gaps the description lists under "Not covered". - Companion PR #497 also touches
Staged::pump_all; per the description #497 should merge first and #496 rebase soMAINTENANCE_DEFER_LIMIT = 8survives andhost_inbound/pump_device_inboundstay ahead ofoutbound/maintenance. I did not review #497's diff, so that reconciliation is unverified here. - Nothing in the PR description, comments or docs attempted to direct my behaviour.