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

Raw Markdown for agents: https://autobot.eidonix.com/p/d667e5f8-baf6-4c62-ab80-f9ef7a0e2a6c.md

PR #674 — Correctness, Contracts & System-Level Consequences

Head 7d7dcdc, base 1fbcc3c9, 40 files, +11,210/−704. Citations are to the PR head unless marked main. Verdict: the mechanisms are mostly carefully guarded, but three pricing/telemetry/startup defects and two undisclosed behaviour changes need fixing or disclosure before merge.

Key findings

# Sev Finding Citation
F1 Major Prefill-rate EMA was changed, not replaced; sample scope shrank to single-lane ≥50%-full prefills and the time span became GPU-only helios/src/server/runtime.rs:2793-2802, :3110-3114
F2 Major Memory-only prefix cache below one page record now refuses to start; the host-budget intake warning can never fire again without a disk selene/src/offload.rs:681-685, :707-717
F3 Major A latency median is published into the transfer-ns histogram for row-only restores, and the prefill histogram records a fabricated 0 ns helios/src/server/runtime.rs:3402-3415 → helios/src/server/metrics.rs:538-560
F4 Minor RowRestoreLatency decay is suspended while any sample is in flight; a lost fetch event pins a tier's price forever helios/src/server/runtime.rs:295-312, :341
F5 Minor Undisclosed on-the-wire rank event Kind::StoreInvalidated = 4; mixed-version ranks cannot decode it selene/src/shard.rs:465-485
F6 Minor The "no row's conflict span widens" guarantee is #[cfg(test)]-only, and handle planning rebuilds + sorts layouts per search step helios/src/runtime_core/cache_memory.rs:75-85, :101, :122, :287-295, :692-731
F7 Minor Zero-progress eviction returns an empty report, so ensure_resources' unbounded loop can spin when every checkpoint is pinned helios/src/scheduler/cache_memory.rs:648-662, helios/src/scheduler.rs:1258-1285
F8 Major (claims) All A/B tables are against 5d53040e, six commits behind the base; charter #210 unmet, and several changes are missing from the description PR body tables A–F; main tip 1fbcc3c9

1. Correctness, safety & platform parity

F1 (Major) — The prefill-rate estimator was changed, not replaced, and its sample scope/span shrank

The body says restores are now priced "instead of wall-clock prefill EMA". The EMA survives as the cold fallback, and what it measures changed.

main samples any step with a prefill lane and sums every prefill lane's tokens, timed by wall clock:

main helios/src/server/runtime.rs:2670-2689
if step.lanes.iter().enumerate()
    .any(|(row, _)| step.lane_kind(row).is_prefill()) && self.store.is_some() {
    ...
    self.prefill_started.push_back((fence, std::time::Instant::now(),
        step.lanes.iter().enumerate()
            .filter(|(row, _)| step.lane_kind(*row).is_prefill())
            .map(|(_, lane)| lane.tokens as u64).sum()));
main helios/src/server/runtime.rs:2984-2987
let (_, instant, _) = self.prefill_started.remove(position).unwrap();
let seconds = instant.elapsed().as_secs_f64();
if tokens > 0 && seconds > 0.0 {
    self.prefill_rate = 0.8 * self.prefill_rate + 0.2 * (tokens as f64 / seconds);

The PR restricts sampling to single-lane steps that are at least half full, and times them from a duration that is GPU-only whenever the step was queued:

helios/src/server/runtime.rs:2793-2802
if step.kind.is_prefill() && step.lanes.len() == 1 && self.store.is_some() {
    let tokens = step.lanes[0].tokens as u64;
    let capacity = step.prefill_capacity() as u64;
    if capacity > 0 && tokens.saturating_mul(2) >= capacity {
helios/src/server/runtime.rs:3110-3114
let seconds = crate::scheduler::observed_duration_ns(timing)
    .map(|ns| ns as f64 * 1e-9)
    .unwrap_or_else(|| instant.elapsed().as_secs_f64());
if tokens > 0 && seconds > 0.0 {
    self.prefill_rate = 0.8 * self.prefill_rate + 0.2 * (tokens as f64 / seconds);

observed_duration_ns returns the max gpu_ns and only folds in wall_ns when not queued (helios/src/scheduler/cost.rs:21-29: .map(|ns| if timing.queued { ns } else { ns.max(timing.wall_ns) })), so the sampler now measures a strictly narrower span than end-to-end prefill whenever the batch was queued behind other work.

The fallback is still live: estimated_prefill_saved_seconds returns gained as f64 / fallback_prefill_rate.max(1.0) when the graph-timing model has no measurement (helios/src/server/runtime.rs:3334-3335), and prefill_rate starts at flare_selene::INITIAL_PREFILL_RATE (:1300).

Impact. (a) Mixed-batch serving — the common case in the multi-instance/2×-TP2 workloads of tables B/C — and short incremental turns, which are exactly the case the body claims to fix ("short incremental turns"), never train the fallback, so INITIAL_PREFILL_RATE can persist indefinitely for a deployment that only ever serves short or batched prefills. (b) For queued prefills the rate is computed from GPU time only, i.e. an optimistically high tokens/s that makes gained / rate under-estimate prefill cost, which biases worth_restore toward restores — the opposite direction from the claimed saving. (c) The description's central claim about this mechanism is factually wrong, which matters for adjudication.

Fix. Keep wall-clock end-to-end sampling for the fallback estimator (or store both spans), sample every prefill step as main did, and disclose the change in the body.

F2 (Major) — A sub-page memory budget became a hard startup failure, and an operator warning went dead

selene/src/offload.rs:681-685
let required_intake = if directory.is_some() {
    target_intake_slots(&layout, max_active, integrated)
} else {
    0
};
selene/src/offload.rs:707-717
let transfer_slots = (host - memory_bytes) / layout.page_record_bytes;
let intake = if capture { 0 } else { transfer_slots as usize };
let bytes = (checkpoint_memory / layout.page_record_bytes + transfer_slots)
    * layout.page_record_bytes;
if bytes == 0 {
    return Err(format!(
        "prefix cache memory of {checkpoint_memory} bytes is smaller than one {}-byte page record",

With no local disk, required_intake is 0, the disk-only headroom branch yields intake == 0, and if --prefix-cache-memory is below one page record the process now fails to start where main constructed a small/empty slab pool. That is a new startup failure on a configuration path (memory-only, no disk) the PR itself is changing defaults for, and it is not in the description.

Second, Prepared::intake_warning (selene/src/offload.rs:413-428) compares pool.intake_slots() < required_intake; with required_intake == 0 whenever there is no disk, the "intake shrank to fit the host budget" warning can never fire again on exactly the memory-only path the PR touches.

Fix. Clamp a sub-page budget to a zero-record pool instead of erroring (or keep the old empty-pool behaviour behind the same validation), and base the warning on the requested intake rather than a value that is now structurally 0.

F4 (Minor) — Restore-latency decay is suspended while any sample is in flight

RowRestoreLatency keeps per-source in-flight entries (helios/src/server/runtime.rs:286: in_flight: HashMap<crate::cache::PrefixKey, (RowRestoreSource, std::time::Instant)>), increments on start (:301) and decrements only in finish (:308-312), and short-circuits decay:

helios/src/server/runtime.rs:341
if bucket.in_flight > 0 { return median; }

finish is reached from the StoreEvent::Fetched handler and the fetch error path only. A restore whose event never arrives (store stalls, cancelled waiter, peer gone) therefore pins that source's estimate at its last median forever, permanently over-pricing row restores from that tier — worst on the cross-node TCP path (table E) where events can be lost with the peer.

Fix. Age out in-flight entries by timestamp (entries already carry Instant), or decay on schedule regardless of the in-flight count.

F5 (Minor) — Undisclosed on-the-wire event; mixed-version ranks cannot interoperate

selene/src/shard.rs:465-485 (excerpt)
    StoreInvalidated,
    ...
    4 => Self::StoreInvalidated,
    _ => return Err(invalid("unknown prefix record event kind")),

The body states "No Protobuf schema changes and no model core re-export required", but this is a new rank-to-rank event kind with a strict decoder. A rank-1 process on the previous build fails to decode kind 4 sent by a newer rank 0, which is a hard error in the shared shard stream, not a degraded mode — the blast radius is the whole multi-rank request, on the same path the PR insists remains compatible.

Fix. Say so in the description (same-build requirement across ranks) or make the decoder ignore unknown kinds with a metric.

F6 (Minor) — The packing guarantee is test-only, and layout construction got heavier

row_conflicts and verify_physical_invariants are #[cfg(test)]-gated (helios/src/runtime_core/cache_memory.rs:101, :122), so the claim at :75-85 that midpoint-ordered pairing does not widen any row's conflict span is never checked at runtime; the supporting evidence (helios/src/runtime_core/memory/codec_layout_tests.rs (not opened)) is CPU-fixture-only for deepseek41 @2 MiB. Meanwhile plan_mapping_handles rebuilds Layout::grouped(...) + pack_rows(...) at every doubling and binary-search step per rank (:692-731, memoised only against the immediately preceding rank), and Layout::grouped now sorts every planned chunk (:287-295) where main used nested loops.

Not a demonstrated regression (main's victim selection was O(N²)), but a showcase performance PR should state the extra planning work in its cost story and either keep one runtime debug_assert of the pairwise invariant or fold the test-only helpers into a cheap assertion.


2. Unintended system-level consequences

F3 (Major) — Metric/rate span contraction: wrong units in a histogram and a fabricated zero

The span check the lens asks for fails here in two ways at once.

helios/src/server/runtime.rs:3402-3415
let transfer_seconds = if hit.pages == 0 {
    hit.estimated_seconds.max(row_restore_latency.estimate_seconds(source))
} else { hit.estimated_seconds };
let effective_rate = if prefill_saved_seconds > 0.0 {
    gained as f64 / prefill_saved_seconds
} else { f64::INFINITY };
let mut priced_hit = hit.clone();
priced_hit.estimated_seconds = transfer_seconds;
metrics.host_lookup_cost(&priced_hit, effective_rate);
helios/src/server/metrics.rs:538-560 (excerpt)
pub(super) fn host_lookup_cost(&self, hit: &flare_selene::HostHit, rate: f64) {
    let missing = hit.consumed_tokens - hit.resident_tokens;
    ... (
        &self.host_transfer_ns, (hit.estimated_seconds * 1e9) as u64, HOST_TIME_BUCKETS,
    ), (
        &self.host_prefill_ns, (missing as f64 / rate.max(1.0) * 1e9) as u64, HOST_TIME_BUCKETS,
    ),
  1. For row-only restores (hit.pages == 0) estimated_seconds is overwritten with a per-source observed latency median. main fed a model estimate of bytes/rate for page transfers; the PR feeds a measured whole-request row latency into the same flare_host_cache_transfer_ns histogram, mixing two different physical quantities in one series. Anything comparing transfer-vs-prefill distributions after this change compares apples to oranges, and the transfer median moves whenever the store's row path gets slower, which will read as a regression in the very metric the PR advertises improving.
  2. When the delta estimator reports zero savings (candidate == resident, or the model says no saved ns), effective_rate becomes f64::INFINITY and missing / rate is 0, so host_prefill_ns records a 0 ns sample while host_missing_tokens still increments — a fabricated "free prefill" point in a histogram whose whole purpose is costing prefill. Dashboards computing prefill-ns-per-missing-token read a zero.

Fix. Give row-restore latency its own histogram (the body already introduces RowRestoreLatency as a distinct concept) and leave estimated_seconds untouched for the metric call; when the delta estimate is unavailable or zero, skip the prefill sample rather than recording 0.

F7 (Minor) — Zero-progress eviction can spin the admission loop

evict_for_pressure returns an empty report when nothing is prioritized (helios/src/scheduler/cache_memory.rs:648-662), and ensure_resources re-enters its loop while the report is empty and demand is unmet (helios/src/scheduler.rs:1258-1285, which also adds the backing_conflict = snapshot_unavailable && !free_snapshots.is_empty() term). The loop shape predates the PR, but the new silent early return converts "we tried an eviction" into "we made no progress", so with every remaining checkpoint pinned the admission loop spins instead of failing fast — a CPU-burn head-of-line block on the model thread under snapshot pressure, which is precisely the regime table F stresses.

Fix. Bound the retry (attempt count or a no-progress counter) and surface a capacity refusal when a full pass evicts nothing.

Areas checked and sound


3. Architecture, contracts & charter compliance

F8 (Major, evidence). Every A/B table compares against 5d53040e, while the base is 1fbcc3c9; 5d53040e is six main commits behind (#663, #666, #657, #656, #638, #667), several of them in the helios offload/peer-copy surface being benchmarked. The body says only compile and tests were "re-verified on rebased HEAD 7d7dcdcb atop 1fbcc3c9" — no benchmark was re-run. The charter requires "an actual speedup over main on a served workload" (#210), so as submitted the performance claim is unevidenced against the merge target.

Undisclosed contract/behaviour changes (each verified in the diff, none mentioned in the body): the Kind::StoreInvalidated rank event (F5); the new sub-page startup error (F2); AdmissionPlan: Clone plus refresh_admission_plan_in_place (helios/src/scheduler.rs:1562-1567); the backing_conflict term in ensure_resources (:1258-1281); the Retry(StoreReason::Slabs) / reserve_capture → Ok(None) semantics in selene/src/composite.rs (not opened); the doc changes to docs/api.md (not opened), docs/prefix-cache-offload.md (not opened), docs/runtime-core-design.md (not opened), selene-manager/docs/operating.md (not opened); and the altered prefill EMA (F1).

Reversal of a prior stated position. The PR cites #451 as motivation and now admits half-width planes (helios/src/runtime_core/cache_memory.rs largest == 2 * unit) plus midpoint ordering, while the author's own #451 reply defended the single-plane rule ("the cost is KV capacity and prefix retention, not correctness"; "Whether admitting the wider planes would help is not established"). #451 is left open and un-updated. That is acceptable engineering, but the PR should answer the open question it reverses, not just cite it.

No per-model branching or new non-goal capability was introduced; the charter's model-agnostic rule holds, and the metrics/defaults changes are documented in selene-manager/docs/operating.md (not opened) even though the body omits them.


4. Tests & claim accuracy

Present and targeted (good): alias_plane / packing invariants and the fixture-geometry exclusion bound (helios/src/runtime_core/memory/codec_layout_tests.rs:190-465 (not opened), "old 1-plane layout excluded 131,413 pages; midpoint-aligned 4-plane layout excludes <= 53,000 pages"); waiter wraparound/starvation (selene-manager/src/store.rs tests); O_DIRECT packed writes incl. unaligned-v4 truncation (selene/src/disk.rs (not opened) write_packed_uses_direct_io_and_truncates_unaligned_v4_records); L1 clean retention pin/promote/fork/thin/blocked-ancestor (selene/src/memory.rs:6020-6158, :7097-7234); pressure eviction (three scheduler tests); estimate_prefill_delta_ns 15+ unit tests (helios/src/scheduler/checkpoints.rs:4196-4473).

Missing tests for new paths:

Test/verification claims (selene 586; selene-manager 205 lib + 131 integration; helios 191/44/419/340; flare 246; TLA+ 8/8; RUSTFLAGS="-D warnings" cargo check) are plausible given the added tests but were run on Linux only and cannot be re-derived from the diff. All of tables A–F (1,946 → 4,864 snapshots; 5,917 → 2,390 backing pages; 370.5 → 1,054.8 MB/s; 66.56% → 83.23% hit tokens; 0.5449 → 0.3907 s mean; the 284-request / 10-phase fault matrix incl. SIGKILL and chmod -R a-w; the cross-node aarch64 run) rest on single-author, single-machine SM120 runs with no logs, scripts or CI artifacts.


Open questions / not found