Simplicity report · NVIDIA/hyperflare-inference #496

Raw Markdown for agents: https://autobot.eidonix.com/p/7557d433-ffa4-4e01-9c82-89527a7c08df.md

Review of PR #496 through lens D (simplicity) — head 0c04b1e2

Verdict: should-fix issues only. No blocking findings. Four should-fix deletions and four nits, each with a smaller version. Nothing found argues against the approach; the +3313/−931 in selene/src/disk_store.rs is not churn, for the reasons given under "Scale judgement".

Key findings

  1. The new §2.4 paragraph is the one item worth fixing before merge (docs/prefix-cache-offload.md:337-366): a single 30-line paragraph now carries about a dozen independent behaviours, and its closing bytes_in/inbound_rate sentences repeat §4 (:1528-1531) almost word for word.
  2. pick_next_pending_plan restates the allocator's slot arithmetic by hand (selene/src/disk_store.rs:1767-1777) instead of calling Layout::record_slots (selene/src/geometry.rs:180-182), which Resources::allocate already uses (disk_store.rs:245). A second copy of an admission rule is exactly the kind of duplicate that silently mispredicts later.
  3. HeaderIdentity's 37-line hand-written Hash (disk_store.rs:1001-1050) restates Header's PartialEq field list (selene/src/shared/record.rs:136-152) and has to be kept in step by hand.
  4. Staged::close reports a number that is not a job count (disk_store.rs:2513-2528, message at 2541-2544), and busy() (:2367-2374) already answers the same question.
  5. Four remaining nits, all small deletions: a single-segment host inbound modelled as a Vec, two id fields duplicating their HashMap keys, a dead guard, and two test-only flags.

Rules applied

Should fix

S1. docs/prefix-cache-offload.md:337-366 — one paragraph for a dozen behaviours, with §4 repeated

The paragraph beginning "write_from(...) and read_into(...) on Staged move records…" runs for thirty lines and carries, in one breath: the composite-store host API, shared file handles, WINDOW_PAGES alignment, per-follower GPU uploads, slot lifetime, read_into independence, the immutability/pinning assumption, the last-user close ordering, demand-preferring window selection, the liveness limit of sharing, the extra-partial-window bound, per-failure-kind error scope, and the bytes_in vs inbound_rate split. Its last three sentences (:362-366) restate §4 (:1528-1531) almost verbatim.

Why it matters: the section is the reference for the behaviour this PR introduces, and a reader cannot check one clause against the code without re-parsing all of them; the duplicated metrics statement now has two homes to keep in step.

Smaller version: keep one short mechanism paragraph in §2.4 — shared handle, aligned window fan-out, independent read_into, error scope — and move the limits (pinning assumption, close ordering, liveness, extra partial window) into bullets in the style the same section already uses at :333-336. Keep the bytes_in/inbound_rate statement only in §4.

S2. selene/src/disk_store.rs:1767-1777 — admission arithmetic duplicated from Layout

let layout_row_slots = self.resources.pool.as_ref()
    .map(|_| lock(&self.resources.transfers).layout().row_slots())?;
...
let needed = plan.count + if plan.row { layout_row_slots } else { 0 };

Layout::record_slots(pages, row) (selene/src/geometry.rs:180-182) is exactly pages + usize::from(row) * self.row_slots(), and Resources::allocate (disk_store.rs:245) already computes the allocation through it. Why it matters: two copies of the same rule; if Layout ever charges differently (a per-record fixed slot, a bucketed row share), pick_next_pending_plan would admit a plan the allocator then refuses, stalling the restore rather than failing clearly.

Smaller version: bind let transfers = lock(&self.resources.transfers); after the pool check, then let needed = transfers.layout().record_slots(plan.count, plan.row); — same lock, one fewer local, and the rule has one definition.

S3. selene/src/disk_store.rs:1001-1050 — 37 lines of Hash restating Header's PartialEq

Header cannot derive Hash because version is excluded from equality (selene/src/shared/record.rs:118-119, 136-152), so HeaderIdentity spells out every remaining field by hand — including a manual ranks.len() plus per-element loop (:1040-1044) and a .. rest that quietly swallows any newly added field. It must be kept in step with record.rs:136-152 forever, and getting it wrong fails silently: a Hash/Eq mismatch splits two equal headers into different map buckets, so coalescing stops without an error.

Smaller and safe: impl Hash for HeaderIdentity { fn hash<H>(&self, state: &mut H) { self.0.key.hash(state); } }. Hash need only be consistent with Eq; PrefixKey is unique per record and the segment path is derived from the key, so distinct-but-equal-per-Eq headers (differing only in a non-key field) still compare equal inside the bucket. Collisions cost a bucket lookup and nothing else.

S4. selene/src/disk_store.rs:2513-2528, 2541-2544 — abandoned is not a job count

let store_jobs = self.outbound.len() + self.host_inbound.len()
    + self.device_inbound.len() + maintenance_jobs;
let internal = self.owners.len().max(self.maintenance.len())
    .max(self.shared_segments.len()).max(self.shared_windows.len());
let abandoned = store_jobs.max(internal);
...
return Err(invalid(format!("{abandoned} disk transport jobs did not complete within {:?}", copier::CLOSE_TIMEOUT)));

The max compares unrelated populations — store records against a maximum over owners, maintenance entries, open shared segments and live shared windows — then reports the winner as a count of disk transport jobs. On a coalesced shutdown the typical case is many shared_windows entries and zero records, so the message names a number no job count ever produced. It also duplicates busy() (:2367-2374), which already says whether anything is pinned.

Smaller version: report self.outbound.len() + self.host_inbound.len() + self.device_inbound.len() + maintenance_jobs alone and word it as unfinished store jobs, or return invalid("disk store still busy after {:?}") when busy(). Either way three locals and two .max() chains go away.

Nits

N1. selene/src/disk_store.rs:267, 651-659, 750, 789-791, 822, 867, 1351-1360 — single-segment host inbound as a Vec

read_into inserts exactly one segment at index 0 and always passes 0 as the owner index (:1351-1360), yet HostInbound holds segments: Vec<Segment> (:750), Owner::HostInbound(JobId, usize) carries an always-zero index (:267), apply_disk tolerates a missing segment (:789-791), and pump iterates the vec (:865). Separately, Segment::reads_left is set to plans.len() (:1357), decremented only at :822, and tested only at :867 — while self.done == self.plans.len() (:882) says the same thing, because a host window becomes Read only in apply_disk, before pump's removal loop (:838-846) runs.

Smaller version: struct HostInbound { segment: Segment, .. }, Owner::HostInbound(JobId), and delete reads_left, closing on self.done == self.plans.len() && segment.settled. WindowPlan.segment then becomes dead on the host path. (Behaviour: the file close would wait one extra pump for windows that finish in the same pump call — harmless, no ordering changes.)

N2. selene/src/disk_store.rs:1083, 1131 — id fields duplicating their HashMap keys

SharedSegment.id and SharedWindow.id are copies of the keys of shared_segments/shared_windows. Their only uses are min_by_key(|seg| seg.id) (:1433-1434), the identity guards before removing an index entry (:1525, :1543, :1837), and the map(|seg| (seg.id, seg.key.clone())) at :1434.

Smaller version: iterate (&id, seg) / (&id, win) so the id comes from the map, and compare self.window_index.get(&win.key) == Some(&win_id) against the iterated id (the guard is needed and keeps working: a window replaced for the same key must not clear the new entry). Two fields and the invariant that they always equal their key disappear.

N3. selene/src/disk_store.rs:1781-1787 — dead guard

let peer_demand = if demand.is_empty() { 0 } else {
    demand.get(&record.window_key(plan_index)).map_or(0, |t| t.saturating_sub(1))
};

map_or(0, ..) on an empty map already yields 0; the branch adds nothing. Smaller version: let peer_demand = demand.get(&record.window_key(plan_index)).map_or(0, |t| t.saturating_sub(1));. (The device_inbound.len() <= 1 short-circuit at :1734-1738 is the real fast path and is a worthwhile one — keep it.)

N4. selene/src/disk_store.rs:743, 1140 (with :915, 939-940, 957-958, 2009, 2102-2103, 2130-2131) — two flags that exist for a test counter

HostWindow.disk_read_counted and SharedWindow.disk_read_counted exist only so disk_window_reads counts windows rather than ReadPages/ReadRow jobs. They are already behind #[cfg(any(test, feature = "test-support"))], so nothing ships; the cost is code.

Smaller version: either count windows once at window creation (where pages_submitted/row_submitted are first set) and delete both fields and their six cfg blocks, or keep the flags and add one doc line on disk_window_reads 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.

Resolved since the earlier rounds (listed, not re-reported)

All of these were in my previous reports and are implemented at 0c04b1e2:

Scale judgement — why +3313/−931 is not churn under AGENTS.md 188-193

Checked and found clean in this lens

Open questions / limits