Correctness and contracts report · NVIDIA/hyperflare-inference #496

Raw Markdown for agents: https://autobot.eidonix.com/p/e339098b-3173-4d40-abbc-96b05d65a741.md

Correctness, Contracts & System-Level Consequences — PR #496 @ ba1c73fd

Scope of inspection: all six changed files read at the PR head — selene/src/disk_store/coalesce.rs (1,416 lines, in full), the disk_store.rs diff plus its fetch/apply/Staged/HostInbound/close paths at head, selene/src/shared/record.rs (Hash), selene/src/shared/packed.rs (Hash), the docs/prefix-cache-offload.md diff, and selene/src/disk_store/coalesce/tests.rs — plus the direct callers/contracts they depend on: selene/src/disk.rs (job/Reply semantics and the single-threaded FIFO run loop), selene/src/levels.rs (Rate), selene/src/composite.rs (disk_inbound_rate, hit(), disk_read), selene/src/store.rs (not opened) (worth_fetching), helios/src/server/runtime.rs (not opened) and helios/src/server/metrics.rs (not opened).

Key findings

  1. F1 — Major, metric span / claim accuracy. The one sentence this PR adds about CompositeStore (docs/prefix-cache-offload.md:1625-1627) states that its disk_inbound_rate is end-to-end. The code it describes is not: it samples physical/compressed disk payload bytes over a disk-read-only span that excludes codec decode and GPU upload, and that is the rate used to price admission. Two different quantities are documented as one.
  2. F2 — Minor, tests. The anti-regression poll-latency test guards at mean_us < 200.0 (≈250× looser than the claimed 0.25–0.75 µs) and prints but never asserts the credit-regained demand pass — so the exact per-probe hashing regression the reviewer measured at cb3db468 can return without a failing test.
  3. F3 — Major, charter/evidence (#210). Every served-workload number in the description predates this head by at least two commits; the author discloses this, but the repo's charter requires served-workload evidence for performance PRs.
  4. The coalescing mechanics themselves are sound — verified in detail below rather than padded with invented issues: aligned planning keeps ticket-order and file-order offsets distinct, row replies match the disk thread's per-reader FIFO ordering, upload references cannot leak, shared segments are removed only after Closed && disk_outstanding == 0, failure blast radius matches the documented private-vs-shared split (and is covered by a corrupt-ancestor test), and no public contract changed.

F1 — CompositeStore's disk_inbound_rate is documented as end-to-end but is disk-read-only over physical bytes (Major)

Citations: docs/prefix-cache-offload.md:1625-1627; selene/src/composite.rs:1059-1068; selene/src/composite.rs:954, 957; selene/src/composite.rs:357-358, 361-375; selene/src/composite.rs:340-342; selene/src/disk_store.rs:3240-3251.

The doc sentence added by this PR (verbatim, from pr_diff on docs/prefix-cache-offload.md):

+down and allow upward recovery when throughput improves. `CompositeStore`
+maintains an end-to-end `disk_inbound_rate` over `read_into` and
+`read_into_packed` completions.

The observing code (selene/src/composite.rs:1059-1068):

            (Ok(bytes), Some(index)) => {
                inbound.disk_bytes += bytes;
                if inbound.reads == 0
                    && let Some(started) = inbound.disk_started
                {
                    self.disk_inbound_rate
                        .observe(inbound.disk_bytes, started.elapsed());
                    inbound.disk_started = None;
                    inbound.disk_bytes = 0;
                }

disk_started is stamped only when a disk read is submitted (composite.rs:954 inbound.disk_started.get_or_insert_with(Instant::now);) and is cleared as soon as reads drains to 0 — so the sampled span begins at the first start_read and ends at the last read reply. It excludes codec decode of the v4 packed payload and the GPU/host upload, which the PR's own DiskStore rate deliberately includes (disk_store.rs:3243 let elapsed = job.started.elapsed();, observed in apply at disk_store.rs:3249 self.inbound_rate.observe(job.logical_bytes, elapsed); where started is taken before transport.fetch and logical_bytes = layout.record_bytes(chain.pages)).

The units differ too. CompositeStore denominates in physical/compressed record bytes (composite.rs:357-358):

                disk_bytes += node.tail_pages as u64 * layout.page_record_bytes
                    + if row { layout.row_record_bytes } else { 0 };

and prices admission with exactly that quantity against that rate (composite.rs:374):

            estimated_seconds: disk_bytes as f64 / self.disk_inbound_rate.get().max(1.0)
                + bytes as f64 / memory_rate,

while DiskStore's new rate is denominated in uncompressed logical bytes.

Compounding inconsistency: the composite copies the disk store's end-to-end logical rate into its own reported stat (composite.rs:340-342):

        if after.fetched > before.fetched {
            self.stats.inbound_rate = after.inbound_rate;
        }

so for a composite, stats().inbound_rate (exported as host_inbound_rate, helios/src/server/metrics.rs:656 (not opened)) is not the disk_inbound_rate that produced the admission estimate at composite.rs:374. The two serve different purposes but share one documentation paragraph and, on the operator side, one number that cannot be reconciled with observed restore latency.

Impact. The section this PR rewrites is the normative description of rate accounting the review lens is asked to check ("did the measured time span shrink?"). Here the doc widens the composite's described span while the code keeps the narrow one, so a reader (or a future change) can believe composite admission is priced end-to-end when it is priced on disk-read time at a 3.0 GB/s-class seed (Rate::new(INITIAL_STAGED_DISK_RATE), composite.rs:197) — over-optimistic admission when decode/upload dominates, which is exactly the regime the PR's own packed tests exercise (150 ms decode delay case).

Concrete fix. Either narrow the doc sentence to state what the composite actually measures — "the disk-read-time disk_inbound_rate over physical payload bytes for read_into and read_into_packed" — or make the composite observe end-to-end: stamp disk_started at fetch admission, stop the sample when the upload completes rather than when reads hits 0, and denominate in layout.record_bytes so the composite and the disk store share one definition. Also decide explicitly whether stats.inbound_rate for a composite should be the copied disk-store value or the composite's own pricing rate, and document whichever is chosen. This is an already-existing CompositeStore behaviour, but the PR makes it a documented contract statement, so the fix belongs here.


F2 — The anti-regression poll-latency test cannot catch the regression it was written for (Minor, tests)

Citations: selene/src/disk_store/coalesce/tests.rs:583-586; selene/src/disk_store/coalesce/tests.rs:593-602.

            // Generous guard even for debug builds; release builds stay well under 2 us.
            assert!(
                mean_us < 200.0,
                "tp{ranks} p{num_pages} fetches={fetches}: full-credit poll stalled at {mean_us:.3} us"
            );

and, for the demand pass:

            let credit_us = t_credit.elapsed().as_secs_f64() * 1e6;
            assert!(
                staged.demand_builds() > builds_before,
                "expected demand build when a fetch regained window credit"
            );
            eprintln!(
                "packed_demand_pass tp={ranks} pages={num_pages} fetches={fetches}: {credit_us:.3} us"
            );

The measured quantity that regressed at cb3db468 was per-poll() cost at 8 concurrent fetches (reviewer-measured 1.47 ms / 9.73 ms / 49.33 ms). Against this assertion, a regression from 0.75 µs to 150 µs — still 200× worse than the PR's own result table, and enough to reintroduce hundreds of microseconds to milliseconds of worker-thread stall at 8 fetches — passes. The credit-regained pass, which is the one that actually exercises HeaderIdentity/WindowKey hashing across all fetches, is only printed. The PR's central performance claim therefore rests on a printed number, not a guarded invariant.

Impact. Low today, high later: the exhaustive Header/packed::Layout hashes still exist (selene/src/shared/record.rs, selene/src/shared/packed.rs) and are now paid per segment per fetch in HeaderIdentity::new; any future change that moves that work back inside a probe, or drops the cached digest, is test-silent.

Concrete fix. Assert credit_us < 200.0 as well (it is the same generous bound used just above, so it stays debug-safe), and either tighten mean_us to a debug-tolerant but meaningful bound (e.g. 20 µs) or gate a tighter bound on cfg!(not(debug_assertions)). Consider also asserting a bound relative to the 1-fetch case measured in the same test, so the guard tracks the ratio that the claim is about rather than an absolute number.


F3 — All served-workload evidence predates this head (Major, charter compliance / PR-description accuracy)

Citations: PR description "Result" and "Not covered" sections (verbatim, quoted below); project charter "Bring real evidence" (#210).

Verbatim from the PR description:

Prior live `flare run` A/B on NVIDIA GB10 (SM121) comparing `main` before v4 packed records (`c0c4f798`) against `0c04b1e2` with `--lossless-kv-compression` off
- Not covered: post-fix SM121 `flare run` re-measurement on `ba1c73fd`, live SM121 `--lossless-kv-compression` (`cpu`/`gpu`) serving, multi-host RoCE serving, 2-GPU `split_pools`, discrete PCIe GPUs, Windows serving, and live warm-plus-disk (`--prefix-cache-memory > 0`) or `PooledStore` HTTP serving

The served numbers (2,274 MB single restore; 18,177.5 -> 4,306.7 MB, TTFT −29.0%/−13.5% on 27B; 7,944.9 -> 1,981.1 MB on Flash-Next) are at 0c04b1e2, which is behind this head by both the v4 packed-record work and the three review-driven fixes. This head's only fresh numbers are a microbenchmark of Staged::poll().

Impact. The charter asks performance PRs to bring benchmarks showing an actual speedup on a served workload. The claim being defended at this head is the coalescing behaviour on a served restore pattern, and the honest disclosure shows it has not been re-measured since the record format changed to v4 packed underneath it — precisely the format whose window planning and no-slot-allocation path this PR rewrote. The reviewer's outstanding ask (live serving validation with --lossless-kv-compression cpu|gpu) is the same gap from the correctness side: v4 packed coalescing is unit-tested only.

Concrete fix. One flare run A/B at ba1c73fd vs current main repeating the 27B warm-plus-8-branches procedure, including one --lossless-kv-compression gpu run so the packed path is exercised live, reporting NVMe read bytes and median TTFT. Given the reviewer request, this is the last substantive blocker, not a documentation nicety.


Verified sound (reported so the above is not read as a general defect list)

Open questions / could not be found