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

Raw Markdown for agents: https://autobot.eidonix.com/p/aa676290-c9f0-462d-928c-89fab68a003e.md

Review: PR #659 — perf(helios): alias null continuation row zero onto a single zeroed VMM granule

Lens: Correctness, Contracts & System-Level Consequences. Head 16e2247, base main (a747a5a), 3 files, +196/−33.

Key findings


1. Correctness, Safety & Platform Parity

Finding 1 — Major: row-zero write invariant is unenforced in Helios, and this PR makes a violation catastrophic rather than local

The change is only safe while nothing writes row zero. That contract lives entirely outside this crate (Ignition components/state.py, state_transfer.py (not opened)). Helios' transfer layer bounds-checks but accepts slot 0 for both directions:

helios/src/offload/transfer.rs:156-163

    if let Some((slot, slots)) = &job.row {
        let index = u64::from(slot.0);
        if index >= geometry.row_capacity {
            return Err(invalid(format!(
                "state slot {index} is outside the cache's {} rows",
                geometry.row_capacity
            )));
        }

This is not hypothetical. An in-repo GPU test uses row 0 as a real checkpoint slot and writes it:

helios/src/offload/gpu_tests.rs:1476-1481

        let (source_slot, child_slot, restored_slot, again_slot) = (
            StateSlotId(1),
            StateSlotId(0),
            StateSlotId(2),
            StateSlotId(3),
        );

helios/src/offload/gpu_tests.rs:1519-1525

        for slot in [source_slot, child_slot] {
            write_unit(
                rank.row.unit_address(u64::from(slot.0)),
                rank.row.unit_bytes as usize,
                seed(row_plane, slot.0),
            );
        }

Impact. Before this PR, a stray write into row zero at granule k corrupted only granule k. Now all sentinel_granules leading offsets are the same physical page (cache_memory.rs:1418-1427), so one write to row.address + [0, alignment) is simultaneously visible at up to 39 offsets on an 82 MiB row. The result is wrong logits with no error, and it is unobservable from any log — a silent-corruption failure mode introduced exactly where the codebase previously had a contained one. The author discloses the assumption as a limitation but adds no guard, so the only defence is a convention maintained by a different repository.

Fix. Reject StateSlotId(0) immediately after the bounds check at helios/src/offload/transfer.rs:156-163, and change the gpu_tests.rs:1476-1481 fixture to a nonzero child slot. One line plus a test fixture, no per-model branch, and it puts the invariant in the layer that can break it.

Finding 2 — verified sound areas (correctness)

I traced these and found no defect; recorded so the adjudicator does not re-open them:


2. Unintended System-Level Consequences

Finding 3 — Major: the byte saving costs sentinel_granules * row_readers mapping handles and can turn a loadable layout into a handle-exhausted startup failure

The PR is presented purely as a physical-memory win. In the same function it increases the handle charge that #391 (merged 2026-11-21) introduced and budgeted:

helios/src/runtime_core/cache_memory.rs:82-102

        let fixed_charge = if self.sentinel_granules > 1 {
            let sentinel_bytes = self.sentinel_granules * self.alignment;
            let sentinel = 1u64
                .checked_add(
                    self.sentinel_granules
                        .checked_mul(row_readers)
                        .ok_or_else(|| invalid("mapping handle count overflow"))?,
                )
                .ok_or_else(|| invalid("mapping handle count overflow"))?;
            if self.fixed_bytes > sentinel_bytes {
                sentinel
                    .checked_add(1)
                    .and_then(|n| n.checked_add(row_readers))
                    .ok_or_else(|| invalid("mapping handle count overflow"))?
            } else {
                sentinel
            }
        } else {
            1u64.checked_add(row_readers)
                .ok_or_else(|| invalid("mapping handle count overflow"))?
        };

Before: 1 + row_readers for the fixed continuation chunk. After: 1 + sentinel_granules * row_readers plus a tail handle and row_readers tail mappings when the row does not end on a granule boundary.

Verified delta on the in-repo DCP16 fixture (row_bytes = 35_122_432, a = 2 MiB, row_readers = 1): 16 granules, fixed_bytes 34 granules, so charge goes from 2 to 19 per rank, i.e. +17, +272 aggregate. That is exactly what the PR had to re-baseline:

helios/src/runtime_core/cache_memory.rs:818-819

        for (pages, snapshots, fixed, expected) in
            [(2304, 116, 20320, 494848), (3103, 157, 3528, 647816)]

helios/src/runtime_core/cache_memory.rs:831-834

                assert_eq!(
                    fixed + 16 * candidate.handle_charge(1, &readers).unwrap(),
                    518504
                );

(was 518232), and the documented headroom narrowed from 6,056 / 1.2% to 5,784 / 1.1% (docs/runtime-core-design.md:832-833).

Impact. row_readers scales the added term multiplicatively. A 16-reader row plane on an 82,143,488 B row (39 granules) costs 39 * 16 = 624 fixed-chunk mappings versus 16 before — a 39× increase in that term. Because plan_mapping_handles hard-fails when the aggregate does not fit:

helios/src/runtime_core/cache_memory.rs:611-616

    if total >= limit {
        let shortfall = total - limit + 1;
        return Err(invalid(format!(
            "estimated VMM mapping handles ({total}) exceed local handle limit ({limit}) by {shortfall} after compaction"
        )));
    }

…the new charge can refuse a load on the wide-DP configurations #391 existed to make loadable, on hardware where main loads fine — while the PR simultaneously frees physical bytes. That inverts the expected direction of travel on the very dimension a prior reviewer (yatesdr in #391) treated as blocking. The failure is a startup abort, not a degradation, so it has no graceful path.

Note the compaction search already prefers a lower charge (cache_memory.rs:593-599) and stops the moment the total drops below the limit (:570-572), so an aliasing-disabled fallback fits the existing structure.

Fix. (a) State the cost in the description — the current "What changed" bullet describes only bytes saved. (b) Add a guard so aliasing is disabled (or the sentinel term excluded) when sentinel_granules * row_readers would push the aggregate past the remaining budget, e.g. have Layout::unmerged/pack_prefixes clear sentinel_granules when handle_charge cannot be afforded; the sentinel_granules <= 1 fall-through at cache_memory.rs:1438-1447/:1483-1488 is already the pre-PR behaviour and needs no extra code path.

Finding 4 — Major: reclaimed bytes are redistributed into cache, changing planned capacities per engine version

row_backing_bytes is not only a reporting figure; it is the input to every capacity decision:

helios/src/runtime_core/memory.rs:486 / :494

        let fixed = row_backing_bytes(core, execution)?;
        ...
        cached = cached.min((budget - fixed) / rows[0].unit_bytes);

memory.rs:510 (inside fits), memory.rs:523 (minimum-footprint check), memory.rs:1003 (pool budget row_backing_bytes(core, 1 + active as u64 * width)?).

Impact, from the PR's own test (memory.rs:2030-2049, sentinel_row_savings_increase_kv_page_capacity): under a fixed 900 MiB budget, bytes(core,0,2) = 158 MiB becomes row_backing_bytes(core,2) = 82 MiB and page capacity rises. Concretely for operators: identical hardware and flags now plan more KV pages and more shared snapshot rows than on main; rows/pages are uploaded to the model (memory.rs:1325) and server_config["state_rows"] = (rows - 1) (:1338) changes; a --memory value that previously errored now succeeds. The description's compatibility paragraph says only "No core wire format, Protobuf, CLI, or Prometheus metric schema changes … Pure KV models and models with row_bytes < 2 * alignment are unaffected", which is true but reads as "no behavioural change". It is a behavioural change, and a favourable one — it just is not declared.

Secondary consequence worth stating: the saving is silently absent whenever row_bytes < 2 * alignment (i.e. GDN rows must be ≥ 4 MiB at 2 MiB granularity), so "unaffected" hides a threshold.

Fix. One sentence in the description/release note: on state-pool models the same hardware now plans more KV pages and snapshot rows, the reclaimed row-zero bytes are returned as cache capacity, and plan cache/state_rows therefore differ from the previous engine version. docs/runtime-core-design.md:772-780 already documents this internally; the PR text should not be weaker than the doc.

Finding 5 — Minor: metric/observability span shift in the startup report

helios/src/runtime_core/memory.rs:1249

            gpu_bytes += row_backing_bytes(core, rows - snapshots)? + bytes(core, 1, pages)?;

memory.rs:1291

        let phase = progress.phase("Allocate cache", Some(gpu_bytes));

memory.rs:1341-1345

        phase.finish(format!(
            "{:.1} GiB · {} KV tokens · {snapshots} shared snapshot slots · limited by {limiting}",
            gpu_bytes as f64 / (1u64 << 30) as f64,
            pages * logical_page_tokens,

Assessment. The direction is correct — this total is meant to be physical cache backing and was previously over-reported by the null row's leading granules. But the scope of the number now moves opposite to the counts printed beside it: GiB goes down while pages/snapshot slots go up, so a before/after startup-log comparison on the same model looks self-contradictory unless the reader knows both changed meaning together. No rate, latency, or admission-timing metric changes (estimated_seconds, worth_fetching, inbound_rate and every helios/src/server/metrics/ surface are untouched), and flare inspect deliberately stays virtual (helios/src/runtime_core/describe.rs:571-583, :191-214), so --memory-map will not show the saving. Worth one sentence in the PR so the mismatch is not later filed as a bug.


3. Architecture, Contracts & Charter Compliance


4. Tests & Claim Accuracy

Finding 6 — Major: the code this PR adds is never executed by any runnable check, and the one GPU test that covers it was weakened

The only code that creates the new layout is cache_memory.rs:1416-1447 (sentinel mappings and tail mapping) and :1468-1488 (split zeroing), reachable only through NativeResources::allocate_shared_cache (called from memory.rs:1300). The new CPU test checks the plan, not the allocation:

helios/src/runtime_core/cache_memory.rs:1367-1385 (sentinel_row_aliases_full_granules_onto_one_page) asserts sentinel_saved_bytes, layout.sentinel_granules, layout.fixed_bytes and layout.handle_charge; it never calls allocate_shared_cache.

The only exercising test is:

helios/src/runtime_core/cache_memory.rs:1106-1108

    #[test]
    #[ignore = "requires an assigned CUDA_VISIBLE_DEVICES GPU"]
    fn cuda_aliases_preserve_rows_while_unowned_pages_are_rewritten() {

which the PR states was not run ("all local GPUs were occupied"). Its reported evidence, 191 passed, 0 failed, 11 ignored, means the ignored set is exactly what covers this code. Mapping count, mapping offsets, tail offset, and the reduced zeroing are all unverified by execution; a tail mapped at the wrong offset or not zeroed would stay invisible until a GPU run.

Worse, that test's coverage of the old property was reduced, not extended:

helios/src/runtime_core/cache_memory.rs:1210-1226

                  // Row 0 is the null sentinel row (aliased onto one zero granule when spanning
                  // multiple granules); verify rows 1..7 retain distinct backing and row 0 stays zero.
                  let expected: Vec<Vec<u8>> = (0..7)
                      .map(|row| {
                          if row == 0 {
                              vec![0u8; geometry.row.unit_bytes as usize]
                          } else {
                              ...
                  for (row, bytes) in expected.iter().enumerate().skip(1) {

Row zero is excluded from the distinct-pattern upload and only asserted to remain zero, so there is no assertion that an aliased row-zero write is visible at every leading offset and stays inside its own span — exactly the property Finding 1 says is now load-bearing.

docs/verification.md:14 puts "CUDA ordering, captured state, inactive rows, allocation stability, or resource lifetimes" on "Real execution tests on assigned GPUs". This PR changes inactive-row (row zero) allocation and its zeroing — that row.

Fix. Either run and report that test on 16e2247, or add a CPU test driving allocate_shared_cache through the mock Driver already used at cache_memory.rs:1120-1209 (it records cuMemMap/cuMemsetD8_v2 calls) asserting sentinel_granules mappings of alignment bytes at consecutive offsets, one tail mapping at row.address + sentinel_bytes, and two memsets. That closes the gap without a GPU and would have caught the class of error the diff is exposed to.

Finding 7 — claim-accuracy review of the description

Claim Verdict
(floor(row_bytes/alignment) - 1) * alignment bytes reclaimed per rank Accurate — cache_memory.rs:69-71, used in allocation :1416-1437 and planning memory.rs:405-409; CPU test pins 38 granules for an 82,143,488 B row and 0 for one-granule/sub-granule rows (cache_memory.rs:1366-1372)
Tail separately backed; live/snapshot rows distinct; virtual span preserved Accurate — cache_memory.rs:1428-1437, :1448-1463; fixed_bytes untouched
Handle assertions re-baselined (518,232 → 518,504) Accurate and reproducible by hand — 2 → 19 per rank × 16 = +272 (cache_memory.rs:818-819, :831-834)
"Existing cores load and serve without re-export" Accurate — no format/Protobuf/CLI/metric file in the diff
Pure KV models and row_bytes < 2 * alignment unaffected Accurate — both branches fall through to the old path
32 MiB/rank / 76 MiB/rank figures Arithmetic only — no runtime measurement
"Reclaims … bytes" (framing) Misleading by omission — the bytes come back as extra page/row capacity (Finding 4), and the handle cost is never mentioned (Finding 3)
"Row zero stays zero while rows 1..7 verify distinct backing" Overstated — row 0 is no longer upload-verified at all (cache_memory.rs:1226)

5. Verified-sound note

Beyond the items in Finding 2, I confirm: no lock, queue, or mutex is added or held across the new work; the mappings: Vec<_> built at cache_memory.rs:1418-1426 is bounded by sentinel_granules and dropped after the call, so there is no amplification or retention; nothing on the request/admission/scheduling path is touched, so no head-of-line blocking or failure-propagation blast radius exists at serving time; and the only added startup cost is O(sentinel_granules * readers) driver calls. The change does not reverse #473's alias-range normalization (cache_memory.rs:252-258) and does not slow the small/uncontended paths (sentinel_granules <= 1 takes the pre-existing branch).


Open questions

  1. Row-zero guard ownership. Ignition enforces the contract; Helios can break it (offload/transfer.rs:156-163) and an in-repo GPU test already does (gpu_tests.rs:1476-1481). Should the guard live in the transfer layer, or should the contract be documented as a hard requirement on the model recipe, given recipes are authored in another repository?
  2. Handle margin. With +272 handles on the DCP16 fixture and up to sentinel_granules * row_readers (624 for a 16-reader 82 MiB row) added per rank inside RM_HANDLE_RANGE = 524,288, does any supported wide-DP/peer-read layout now fail where main loaded? A per-layout budget sweep, or the fallback in Finding 3(b), would settle it.
  3. GPU coverage before merge. Is a run of cuda_aliases_preserve_rows_while_unowned_pages_are_rewritten — with an assertion that an aliased row-zero write is visible at every leading offset — required before this merges, given #391 and #473 merged with the same test unrun but neither reduced its assertions?
  4. Operator note. Should the capacity shift (more KV pages / rows on identical hardware) be stated in the description or release notes?
  5. Measurement. One VRAM before/after on a real GDN or Mamba core would convert the headline MiB figures from arithmetic to measurement.

Could not be found / not verifiable with available tools