Correctness report · NVIDIA/hyperflare-inference #496

Raw Markdown for agents: https://autobot.eidonix.com/p/ebc415f2-2893-4880-821b-f0723c49d65f.md

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

Head reviewed: 0c04b1e2 · Lens: Correctness (callers, configurations, lifetimes, error handling, concurrency, inactive/edge paths, state transitions, compatibility with existing data) · Files: selene/src/disk_store.rs, selene/src/shard.rs, docs/prefix-cache-offload.md (not opened)

Key findings

No blocking or should-fix findings. The three issues I raised on the previous revision are fixed in code at this head (physical vs logical accounting, Staged::close abandoned count, misaligned-follower coverage), and I found no correctness defect in the changed paths I read. Two nits remain.

  1. Nit — selene/src/composite.rs:1376: CompositeStore::poll increments self.stats.progress for every transport event before dispatch, including TransportEvent::InboundWindowSample, while DiskStore::apply early-returns for that variant and deliberately does not bump self.stats.progress (disk_store.rs:3632-3636). The two stores' progress counters now advance at different rates for the same work.
  2. Nit — selene/src/disk_store.rs:2113-2116 with :1599-1611: a shared window whose ReadRow job is skipped because disk_space() is exhausted stays in SharedWindowPhase::Reading with pages_submitted == true, row_submitted == false and disk_referenced == 0, so it is neither sampled into inbound_rate nor uploadable until a later pump submits the row. Correct (the loop re-enters and the row is submitted once queue space frees), but the invariant "Reading ⇒ at least one pending submission or outstanding reply" is load-bearing and undocumented.

Previously raised items, re-checked at head — resolved

(1) Logical bytes leaking into inbound_rate (was should-fix). apply_shared_disk now emits exactly one TransportEvent::InboundWindowSample { bytes, elapsed } per completed physical shared window, at selene/src/disk_store.rs:1596-1620, carrying win.read_bytes and the summed disk::Reply.elapsed over that window's ReadPages/ReadRow jobs (:1597-1598), pushed to self.events at :1617-1620. DiskStore::apply handles that variant first and only feeds the rate sampler:

// disk_store.rs:3631-3635
pub fn apply(&mut self, event: TransportEvent, events: &mut Vec<StoreEvent>) {
    if let TransportEvent::InboundWindowSample { bytes, elapsed } = event {
        self.inbound_rate.observe(bytes, elapsed);
        return;
    }
    self.stats.progress += 1;

stats.bytes_in remains logical: each attached follower credits the window's full byte count in Pass 1 (record.bytes += win.read_bytes, :1899-1905) and DiskStore::apply spends it at :3669. hit()'s estimated_seconds (:3625) is therefore priced from physical disk bandwidth, which is the right input for admission, while bytes_in keeps its historical logical meaning. docs/prefix-cache-offload.md (not opened) §2.4 and §4 now state the split. (Rate::observe ignores zero-byte / zero-elapsed samples — selene/src/levels.rs:57-60 — and the sample is only produced when win.read_bytes > 0, :1605.)

(2) Staged::close abandoned count (was nit). selene/src/disk_store.rs:2513-2528 now computes store_jobs = outbound + host_inbound + device_inbound + maintenance_jobs and internal = max(owners.len(), maintenance.len(), shared_segments.len(), shared_windows.len()), then abandoned = store_jobs.max(internal). Since internal >= owners.len() and store_jobs >= outbound + host_inbound + device_inbound + maintenance, the count can no longer under-report versus the old self.owners.len(). Behaviour on failure (error returned, pool retained) is unchanged.

(3) Misaligned-follower coverage. misaligned_follower_attaching_to_shared_partial_tail_and_row_matches_private_restore compares byte-equal SimulatedGpu pages and row against a private-store baseline for skip_pages = 13 attaching to a leader's already-created windows — the exact untested pair I flagged previously.

Correctness checks that came out sound

Slot and file lifetimes

Failure isolation

Concurrency and demand indexing

Host path unchanged

HostInbound (Staged::read_into, plan_windows(..., false)) keeps private per-restore opens and unaligned packing (:682-727), and CompositeStore::start_read (selene/src/composite.rs:802-837) uses only that path. Live CompositeStore/PooledStore host serving therefore sees no behavioural change; only GPU restores go through shared windows. This matches the doc claim that caller-owned reads run independently and segment-relative.

Event plumbing for the new variant

Compatibility with existing data

No record-file format, header layout, or re-export change appears in the diff. HeaderIdentity's hand-written Hash was checked field-by-field against Header's PartialEq (selene/src/shared/record.rs:89-154): every equality-relevant field is hashed (identity, fingerprint, flags, key, parent, bucket, page_tokens, tail_pages, ranks, page_segment, row_segment, row_checksum, created), with version (non-semantic per its own doc comment) and ranks.len() as a length prefix — so the new SegmentKey/WindowKey hashing cannot alias two different records. Files written before this PR load unchanged.

Nits

N1 (nit) — selene/src/composite.rs:1376: composite progress counter now advances for rate samples.

for event in transport_events.drain(..) {
    self.stats.progress += 1;
    match event { ... other => self.streamed_event(other, events) }
}

DiskStore::apply returns before self.stats.progress += 1 for InboundWindowSample (disk_store.rs:3632-3636). Through a CompositeStore, every coalesced window adds an extra tick to CompositeStore::stats.progress that the inner store does not count, so the two progress counters — used as a liveness/backpressure signal — diverge for exactly the workload this PR introduces. Fix: skip the increment when matches!(event, TransportEvent::InboundWindowSample { .. }), mirroring the early return.

N2 (nit) — selene/src/disk_store.rs:2113-2116: window can sit unsampled and unuploadable when the disk queue is full.

if row_needed {
    if !self.resources.disk_space() {
        continue;
    }

When ReadPages for a window was already submitted (so pages_submitted == true, disk_referenced > 0 then returns to 0) but the ReadRow is deferred here, the window remains Reading with row_submitted == false and disk_referenced == 0. The completion handler's sample condition (:1599-1611) requires row_submitted && disk_referenced == 0, so no InboundWindowSample is emitted and no follower upload is armed until a later pump re-enters and submits the row. Behaviour is correct (the window is not released — followers is non-empty — and Pass re-entry finds row_needed still true), but a rate sample can be delayed indefinitely under disk-queue saturation, and the invariant "phase == Reading ⇒ at least one of pages_submitted/row_submitted still pending, or a reply outstanding" is what keeps the loop live. A comment at :2113 stating that invariant would make future edits to the continue safe.

Open questions / not verified

  1. #497 rebase on Staged::pump_all. Both PRs base on main and both touch pump_all; the description asserts either merge order works and that the second one will "run host_inbound and pump_device_inbound ahead of writes and maintenance". This is not verifiable from this branch — someone must confirm the resolved pump_all on the merged second PR still orders shared-window uploads before outbound writes and maintenance.
  2. Windows IOCP and multi-host RoCE. The author reports 13 coalescing tests passing on Windows IOCP but notes full Windows selene remains gated on /dev/urandom (docs/TODO.txt); Windows serving and multi-host RoCE serving are listed as not covered. The code I read has no platform-specific branch in the new path, but the FIFO-reply-matching assumption above should be spot-checked against the IOCP job executor.
  3. 2-GPU split_pools, discrete PCIe GPUs, live CompositeStore/PooledStore GPU serving — listed as not covered by the author and not exercised here.
  4. Benchmark provenance. The description now benchmarks main (c0c4f798) against 0c04b1e2, the exact head under review, and the TTFT/read-reduction table is therefore attributable to the merged code — an improvement on the previous revision, where numbers predated the demand-index edit.
  5. What would settle the residual risk. Only a stress test that saturates disk::QUEUE_DEPTH while a follower attaches to a window whose row read is still deferred (N2), and a CompositeStore-wrapped coalesced burst asserting the progress counter verdict (N1), would close the two nits by test rather than by inspection.