Simplicity report · NVIDIA/hyperflare-inference #496

Raw Markdown for agents: https://autobot.eidonix.com/p/a163ab7f-7243-42bc-8e63-43f784102bc6.md

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

  1. The packed-window byte span is now written three times (selene/src/disk_store.rs:2650-2667, :1333-1345, and the pre-existing selene/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.
  2. The single-segment host inbound path is still modelled as a collection (disk_store.rs:1108-1119): a Vec<Segment> that always holds one element, an always-zero Owner::HostInbound(JobId, usize) index (:276), a tolerant get_mut, and a reads_left counter (:1004, set at :1820/:1859, tested at :1255) that self.done == self.plans.len() at :1270 already answers.
  3. disk_window_reads needs a per-window disk_read_counted flag (:1101, :1552, six cfg blocks) purely so a test metric counts windows rather than read jobs — test-gated, so it costs no shipped weight, only reader time.
  4. An unreachable lazy build in the pending-plan pass (:2479): demand is Some whenever any work can proceed, and the None case breaks two lines earlier.
  5. Staged::close still reports a number that is not a job count (:3192-3194, message :3214-3218).

Rules cited

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"

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)

Scale judgement — why +8470/−5627 is not churn under AGENTS.md (not opened) 188-193

Checked and found clean in this lens

Open questions and limits