Correctness scratchpad · NVIDIA/hyperflare-inference #496

Raw Markdown for agents: https://autobot.eidonix.com/p/fdd88c0c-ca43-45cc-afa7-1f6512b35ccf.md

#1 [high] PR 496 overview: coalesced shared ancestor reads in selene disk_store

PR #496 (FujitsuPolycom, open, ready for review, head f9c9191, base main@c0c4f79). 2 files: selene/src/disk_store.rs (+2803/-913), docs/prefix-cache-offload.md (+5/-1, section 2.4).

Change: splits old InboundRecord (Destination::Device|Host) into

Relevant constants: WINDOW_PAGES=64 (selene/src/slab.rs:34 via shared), WINDOWS_IN_FLIGHT=WINDOW_CREDITS=2 (shared/limits.rs:18), RECORDS_IN_FLIGHT=8 (disk_store.rs:64), disk::QUEUE_DEPTH=64.

PR claims: shared Open per file, 64-page aligned coalescing, refcounted windows, demand ordering, failure isolation, Staged::close drains. Evidence: 474 selene tests, Windows IOCP 7 coalescing tests; live SM121 checks; not covered: rerun of single-pass benchmarks after demand-index edit, helios FLARE_RUN_CUDA_TESTS, Windows serving, CompositeStore/PooledStore GPU serving. Related: #497 (companion, same author, touches Staged::pump_all; merge this first), #477/#486 (other disk_store changes). Review lens A: correctness and consequences - callers, configs, lifetimes, edge paths.

#2 [high] Research summary

I ran out of budget before finishing the whole review, so this is a partial result stated honestly.

What I reviewed in context

What I checked and found sound

Slot lifetime for a shared window is guarded by followers.is_empty() && disk_referenced == 0 && upload_referenced == 0 (1755–1771); every path I traced that could remove a record or a segment first requires active.is_empty() (Pass 5e, 2213–2230) or refuses to detach while an upload is busy (1737–1741), so apply_device_transfer cannot drop a reply that still holds upload_referenced. allocate(plan.count, plan.row) matches record_slots and the pick_next_pending_plan free-slot precheck, and plan.offset/count index record.pages and win.buffers.pages consistently for aligned windows. Linux disk::Job ordering makes the pending_page_reads/pending_row_reads reply matching correct (jobs for one id run in submission order). Host read_into stays on the unchanged private path, so CompositeStore behaviour is untouched.

Findings

  1. Nit — selene/src/disk_store.rs:2485–2506 (Staged::close): the timeout diagnostic now sums outbound + host_inbound + device_inbound + maintenance and then .max(usize::from(self.busy())), where busy() is a bool. Work held only by shared_segments/shared_windows/owners is therefore reported as "1 disk transport jobs did not complete" instead of the previous self.owners.len(). Diagnostic-only; fix by counting outstanding disk jobs (owners + maintenance) so the message stays truthful.
  2. Observation (should confirm) — selene/src/disk_store.rs:1828–1830 with 3587 and 3628: each follower credits the shared window's read_bytes in full (record.bytes += win.read_bytes), so a coalesced restore still reports its whole chain to DiskStore::apply, which feeds stats.bytes_in and inbound_rate.observe. That keeps the historical definition, but inbound_rate also prices hit().estimated_seconds for scheduling. After this change the rate reflects a wall time shortened by sharing, so estimates for a request that will not be coalesced under-report its cost. Not a correctness defect; worth stating explicitly in the description or splitting physical from logical accounting.

Not finished (would settle the remaining risk)

I did not read the new test module past line 8420 (tests staggered_arrival…, different_skip_pages…, private_failure_isolation…, shared_ancestor_failure…, staged_close_drains…), nor #497's pump_all rebase interaction, nor the Windows/IOCP and helios GPU-offload paths. The two-risk areas I would want tests for before approving are (a) a follower attaching to a Read-phase window in a segment that closes in the same pump (my trace says safe via users/settled), and (b) Staged::close draining a coalesced burst within copier::CLOSE_TIMEOUT, which staged_close_drains_active_coalesced_fetches_cleanly appears to cover but which I did not read. I found no blocking correctness defect in the paths I did read.

#5 [high] Report 2026-11-25 (head 0c04b1e2): earlier should-fix items resolved; residual nits

Review — PR #496 at head 0c04b1e2 (2026-11-25), correctness lens

Verdict: no blocking or should-fix findings; 2 nits.

Previously raised items, re-checked at head — resolved

  1. Logical bytes into inbound_rate (old :1829/.3626/.3628) — fixed. apply_shared_disk now emits TransportEvent::InboundWindowSample { bytes, elapsed } once per completed physical shared window (selene/src/disk_store.rs:1596-1620), carrying win.read_bytes and the summed disk::Reply.elapsed of that window's ReadPages/ReadRow jobs (:1597-1598), and DiskStore::apply feeds only self.inbound_rate.observe(bytes, elapsed) from it (:3632-3635). stats.bytes_in stays logical through record.bytes += win.read_bytes per follower (Pass 1, :1899-1905) and :3669. Docs state the split (docs/prefix-cache-offload.md §2.4 and §4). Note Rate::observe ignores zero bytes/elapsed (levels.rs:57-60), and the pure row window is included in the same window's bytes/elapsed.
  2. Staged::close abandoned count — fixed: store_jobs.max(internal) where internal = max(owners.len(), maintenance.len(), shared_segments.len(), shared_windows.len()) (selene/src/disk_store.rs:2513-2528) can no longer report less than owners.len().
  3. Misaligned-follower coverage — added misaligned_follower_attaching_to_shared_partial_tail_and_row_matches_private_restore, comparing byte-equal SimulatedGpu pages/row against a private-store baseline for skip_pages = 13 attaching to a leader's windows (test module, disk_store.rs ~8760ff).

Event plumbing for the new variant (checked in full)

Nits

Not re-verified this turn (time)

#497 rebase interaction on pump_all, Windows IOCP path, multi-host RoCE, 2-GPU split pools — the author lists these as not covered too.

#6 [high] Research summary

Reviewed PR #496 at head 0c04b1e2 through the correctness lens. Verdict: no blocking or should-fix findings — the three issues I raised on the previous revision are addressed in code, and the two things left are nits. Full detail is in scratchpad entry #5.

Resolved from the previous round. (1) The inbound_rate/bytes_in conflation is fixed: apply_shared_disk emits one TransportEvent::InboundWindowSample { bytes, elapsed } per completed physical shared window (selene/src/disk_store.rs:1596-1620) carrying that window's summed disk::Reply.elapsed, and DiskStore::apply feeds only inbound_rate from it (:3632-3635) while stats.bytes_in stays logical via record.bytes += win.read_bytes (:1899-1905, :3669); docs §2.4 and §4 now state the split. (2) Staged::close's abandoned count is now store_jobs.max(internal) with internal the max of owners/maintenance/shared_segments/shared_windows lengths (:2513-2528), so it can no longer under-report versus owners.len(). (3) A misaligned-follower test now compares byte-equal pages and row against a private-store baseline.

Event plumbing checked in full. Sharded::absorb_local forwards samples to rank 0 without Kind::of (shard.rs:718-728); the unreachable! arm (shard.rs:476-478) is genuinely unreachable because Peer::forward filters first (shard.rs:1144-1153), so peers drop samples and rank 0, which owns the DiskStore, measures its own. CompositeStore::poll routes them to streamed_event → DiskStore::apply (composite.rs:1373-1385), and the composite's counters are computed from fetched/bytes_in deltas, so they are unaffected.

Nits. N1: composite.rs:1376 bumps self.stats.progress for every transport event before dispatch, including InboundWindowSample, while DiskStore::apply deliberately does not (disk_store.rs:3632-3636) — the two progress counters now advance at different rates for the same work. N2: a window whose ReadPages succeeded but whose ReadRow was deferred for lack of disk queue space (:2113-2116) stays Reading with disk_referenced == 0, so it is neither sampled nor uploadable until a later pump; correct but deserving of a comment on that invariant. I did not re-verify the #497 pump_all rebase, the Windows IOCP path, or multi-host/split-pool configurations in this turn.

#7 [high] Scope, docs claim check, and verdict line for the 0c04b1e2 review

Scope & supporting notes for PR #496 review at head 0c04b1e2

What was read in context this turn (all changed files + their consumers)

Docs claim check (against code, not just prose)

docs/prefix-cache-offload.md §2.4 additions match the code: shared handle per matching (path, expected header), WINDOW_PAGES-aligned staging, per-follower upload, slots released only after disk read + every upload, caller-owned read_into independent and segment-relative, sharing only while a window is Reading/Read, at most one extra partial window per segment when skip_pages % WINDOW_PAGES != 0, shared open/read errors fail all attached restores while private child/upload errors fail one, logical bytes_in vs physical inbound_rate. §4's added paragraph matches DiskStore::apply (:3632-3635) and stats (:3889).

Report verdict line

Verdict: no blocking or should-fix correctness findings at 0c04b1e2; 2 nits (composite progress-counter bump for InboundWindowSample, composite.rs:1376; unsampled window when ReadRow is deferred for disk queue space, disk_store.rs:2113-2116 with :1599-1611). Not verified this turn: #497 rebase of pump_all, Windows IOCP, multi-host RoCE, 2-GPU split pools (also listed as not covered by the author).

#9 [high] Re-check of the 5 external should-fix items against my correctness verdict (head 0c04b1e2)

Re-check of the posted review's 5 "should fix" items through the correctness lens

1. TransportEvent::InboundWindowSample on the completion enum (disk_store.rs:97-101; shard.rs:476-478, :722-725, :1148-1150)

Layering, not correctness. The unreachable!() arm is genuinely unreachable at head: Sharded::absorb_local forwards samples straight to self.events without calling Kind::of (shard.rs:718-729), and Peer::forward filters the variant before Kind::of (shard.rs:1144-1153). The two guards are hand-written, so a future event path could violate the invariant — that is the maintainability risk the other reviewer names, and I agree it is worth fixing, but no code path at head can panic. Not a correctness defect.

2. HeaderIdentity's hand-written Hash (disk_store.rs:1014-1050) vs Header::PartialEq (shared/record.rs:136-152)

Verified field by field at head: identity, fingerprint, flags, key, parent, bucket, page_tokens, tail_pages, ranks (len + planes + row_bytes), page_segment, row_segment, row_checksum, created are all hashed; version is skipped but is documented non-semantic (record.rs:118-119) and excluded from PartialEq too. So a == b => hash(a) == hash(b) holds at head and two different records cannot alias in SegmentKey/WindowKey. The .. in the destructure is a silent-drift hazard for a future Header field, not a defect now. Should-fix for maintainability, not correctness.

3. Hand-restated record_slots in pick_next_pending_plan (disk_store.rs:1767-1777)

Checked the arithmetic: needed = plan.count + if plan.row { layout_row_slots } else { 0 } where layout_row_slots = layout().row_slots() (:1767-1771); Layout::record_slots(pages, row) (geometry.rs:180-182) is pages + usize::from(row) * self.row_slots(). Identical expressions, so the admission prediction cannot under- or over-estimate the allocation in Resources::allocate (disk_store.rs:243-254), which uses record_slots. Nit (duplication), not an arithmetic bug — the other reviewer's wording implies a divergence that is not in the code.

4. Docs §2.4 split (docs/prefix-cache-offload.md:337-366; duplication at :1528-1531)

Prose organisation. The content matches the code (I checked the §2.4 claims against plan_windows :682-727, slot release :1824-1843, failure isolation :1509-1553, and the bytes_in/inbound_rate split :3631-3670, :3889). Style only.

5. Design sign-off on a second inbound lifecycle in Staged

Process, not code. Out of my lens.

Where this leaves my verdict

No blocking or should-fix correctness findings at 0c04b1e2. The two nits I recorded stand (composite.rs:1376 progress bump — note that via CompositeStore::poll :1418-1428 it also re-runs spill_parked + disk.maintain() once per physical window, which defeats the throttling the maintenance_progress gate exists for; safe but wasteful. disk_store.rs:2113-2116 deferred ReadRow leaving a window unsampled/unuploadable until a later pump — correct, invariant worth a comment).

#10 [high] Research summary

Reviewed PR #496 at head 0c04b1e2 again through the correctness lens, this time specifically re-checking the five "should fix" items in the posted review against the code. None of them is a correctness defect; my verdict stays clean, with the same two nits.

Re-checks (all verified in code this turn):

The two surviving nits: composite.rs:1376 bumps stats.progress for InboundWindowSample, which DiskStore::apply does not (:3632-3636) — via CompositeStore::poll (:1418-1428) that also re-runs spill_parked + disk.maintain() once per physical window, safe but defeating the throttle; and disk_store.rs:2113-2116, where a window whose ReadRow is deferred for disk queue space stays Reading with disk_referenced == 0, so it is neither sampled nor uploadable until a later pump (correct, invariant deserves a comment). Not verified: the #497 pump_all rebase, Windows IOCP, multi-host RoCE, 2-GPU split pools.

#11 [high] Report of 2026-11-25, run (re-check of posted review): verdict clean, 5 should-fix items re-assessed

Review — PR #496 "Coalesce shared ancestor reads across concurrent Selene disk fetches"

Head reviewed: 0c04b1e2 · Lens: Correctness · Files: selene/src/disk_store.rs, selene/src/shard.rs (+ selene/src/composite.rs, geometry.rs, slab.rs, disk.rs, shared/record.rs, levels.rs read as context), docs/prefix-cache-offload.md. Run purpose: re-check the five "should fix" items in the posted Autobot review against the code, not to re-review from scratch.

Verdict: clean — no blocking or should-fix correctness findings; 2 nits.

The posted review's five should-fix items, re-assessed under correctness

  1. TransportEvent::InboundWindowSample on the cross-rank completion enum (disk_store.rs:97-101; unreachable! shard.rs:476-478; guards shard.rs:722-725, :1148-1150). Not a correctness defect at head: Sharded::absorb_local pushes samples straight to self.events without Kind::of (shard.rs:718-729) and Peer::forward filters the variant before Kind::of (shard.rs:1144-1153), so the unreachable! arm cannot be reached. Real maintainability risk (two hand-written guards uphold an invariant the type system should); agree it is worth fixing, but it is layering, not correctness.
  2. HeaderIdentity's hand-written Hash (disk_store.rs:1014-1050) vs Header::PartialEq (shared/record.rs:136-152). Re-verified field by field: identity, fingerprint, flags, key, parent, bucket, page_tokens, tail_pages, ranks (len + planes + row_bytes), page_segment, row_segment, row_checksum, created are all hashed; version is omitted from both PartialEq and the hash and is documented non-semantic (record.rs:118-119). So a == b ⇒ hash(a) == hash(b) holds and no two distinct records can alias into SegmentKey/WindowKey. The .. in the destructure is a silent-drift hazard for a future Header field, not a present defect.
  3. pick_next_pending_plan restating record_slots (disk_store.rs:1767-1777). The expressions are identical: plan.count + if plan.row { layout().row_slots() } else { 0 } vs Layout::record_slots(pages, row) = pages + usize::from(row) * row_slots() (geometry.rs:180-182), which is what Resources::allocate actually uses (disk_store.rs:243-254). No under/over-admission, so no correctness consequence — duplication nit only. The posted wording ("recomputes by hand", implying divergence) is stronger than the code supports.
  4. Docs §2.4 split (docs/prefix-cache-offload.md:337-366, duplication at :1528-1531). Organisation only; the content matches code (plan_windows :682-727, slot release :1824-1843, failure isolation :1509-1553, bytes_in/inbound_rate split :3631-3670, :3889).
  5. Design sign-off on a second inbound lifecycle inside Staged. Process; outside this lens.

Nits (unchanged from the earlier head review)

Previously fixed at this head (for context)

Not verified (same gaps as the author lists)

#497 rebase of Staged::pump_all ordering; Windows IOCP; multi-host RoCE; 2-GPU split_pools; discrete PCIe GPUs; live CompositeStore/PooledStore GPU serving. No toolchain, GPU or test run was available: every statement above is from source at 0c04b1e2.

#3 [medium] Finding 1 (nit): Staged::close timeout diagnostic undercounts

NIT — selene/src/disk_store.rs:2485-2506 (Staged::close, impl DiskTransport for Staged, PR #496 head).

Old code: let abandoned = self.owners.len(); then disk.and(transfers)?; then if abandoned > 0 { return Err(invalid(format!("{abandoned} disk transport jobs did not complete within {:?}", copier::CLOSE_TIMEOUT))) }.

New code:

let abandoned = (self.outbound.len()
    + self.host_inbound.len()
    + self.device_inbound.len()
    + self.maintenance.len())
.max(usize::from(self.busy()));

busy() is now !outbound.is_empty() || !host_inbound.is_empty() || !device_inbound.is_empty() || !shared_segments.is_empty() || !shared_windows.is_empty() || !owners.is_empty() (disk_store.rs:2344-2351). Because the first term is a count and .max(usize::from(bool)) caps at 1, any drain that leaves only shared_segments, shared_windows or owners outstanding reports "1 disk transport jobs did not complete" instead of the previous owners.len().

Why it matters: only the diagnostic; the error is still returned, so the behaviour (retain/leak the pool, fail the close) is unchanged. But the message no longer reflects how many disk jobs are outstanding, which is what an operator uses to size copier::CLOSE_TIMEOUT or to tell a real hang from a slow drain.

Fix: count outstanding disk jobs, e.g. self.owners.len() (as before) or owners.len() + maintenance.len(), before the disk.and(transfers)? and use that as abandoned.