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

Raw Markdown for agents: https://autobot.eidonix.com/p/c7031832-f180-4dda-9151-8b930e66aafb.md

PR #664 correctness / contracts / system-consequences review (head fd6dad6, 23 files, +1711/−550)

Method caveat, stated up front: pr_diff failed on every call (fatal: bad revision 'cc0a49d2…fd6dad6'), so every head-vs-main statement below comes from paired read_file reads at the PR head and at ref: main, and every citation names the lines I opened at this head during this review.

Key findings

  1. Major — the schema and the decoder both accept Encoding.BF16 with Method.XOR_MODULO, i.e. raw 2-byte-wide rows indexed by 24 lookup heads. Nothing constrains hashing by encoding, so a signed core can allocate ~3.28 GiB of pinned host staging at 4,096 tokens instead of the ~140 MiB the shipped IDENTITY layout needs — 24× amplification on the exact bottleneck this PR exists to relieve, rejected only by the generic memory-budget check.
  2. Minor — the PR's new "exporter cannot sign what Helios refuses to load" property holds for shard contiguity only, not for per-encoding geometry. Schema never cross-checks encoding against embedding_width 256/160, scale_block 32/16, or Nvfp4 global_scale > 0, nor the hash geometry, all of which runtime_core/engram.rs rejects.
  3. Minor — docs document BF16 and IDENTITY separately and never the combination the code accepts (helios/manifest.md:457-463), so an operator or producer reading the spec cannot learn that the 24-head mode is legal.
  4. Sound (verified, should not be re-litigated): the Planes { weights, Option<scales> } propagation, delivery-group grouping via Index::shares_delivery_with + Table::partition, gather-ID validation including -1 zero-fill, the Windows lane mirror, exporter optional-scale/null handling, flare_engram_resident_scale_bytes = 0 for single-plane tables, and the Python↔Rust descriptor pairing.
  5. The Discovery Dossier's two blockers stand unchanged (owner approval for the two appended enum values per AGENTS.md:376-381; CI plus one legacy FP8/NVFP4 replay), and I found nothing in this lens that softens them.

1. Correctness, safety & platform parity

F1 (Major) — BF16 + 24-head XOR_MODULO is accepted end-to-end, with 24× host staging amplification

The signing validator constrains the hash method only by whether the token map is empty, never by encoding — helios/src/core/schema.rs:397-411:

        if token_map_empty {
            if !matches!(
                method,
                wire::engram_hash::Method::EosXorModulo | wire::engram_hash::Method::Identity
            ) || table.request_buffer.is_empty()
            {
                return Err(invalid(
                    "engram without a token map requires request delivery with EOS XOR or identity indexing",
                ));
            }
        } else if method != wire::engram_hash::Method::XorModulo {
            return Err(invalid(
                "engram with a token map requires XOR-modulo hashing",
            ));
        }

The encoding checks immediately above are about scale metadata only (helios/src/core/schema.rs:372-379 rejects scale fields for single-plane tables), and the BF16 branch at :428-436 pins only the plane byte size. So encoding = BF16 + a non-empty token_map + method = XOR_MODULO signs cleanly.

The decoder then rewards that combination with 24 heads while IDENTITY gets 1 — helios/src/runtime_core/engram.rs:165-174:

        let (order, heads) = match method {
            wire::engram_hash::Method::XorModulo if !value.token_map.is_empty() => (Some(4usize), 24usize),
            wire::engram_hash::Method::EosXorModulo if gpu && value.token_map.is_empty() => {
                (Some(3usize), 16usize)
            }
            wire::engram_hash::Method::Identity if gpu && value.token_map.is_empty() => {
                (None, 1usize)
            }
            _ => return Err(invalid("unsupported n-gram hash method or request source")),
        };

while BF16 rows are two bytes per element — helios/src/runtime_core/engram.rs:146-154:

            wire::engram_table::Encoding::Bf16
                if table.embedding_width > 0 && table.global_scale.to_bits() == 0 =>
            {
                let row_bytes = usize::try_from(table.embedding_width)
                    .ok()
                    .and_then(|width| width.checked_mul(2))
                    .ok_or_else(|| invalid("BF16 embedding row width overflow"))?;
                (table.embedding_width, 0, row_bytes, None)
            }

Heads multiply the whole staging payload — helios/src/engram.rs:204-208:

    fn staging_payload_bytes(&self, max_tokens: usize) -> Result<usize> {
        self.planes.iter().try_fold(0usize, |total, plane| total.checked_add(plane.row_bytes))
            .and_then(|bytes| bytes.checked_mul(self.heads))
            .and_then(|bytes| bytes.checked_mul(max_tokens))
            .ok_or_else(|| "embedding staging exceeds host range".into())
    }

and there are two pinned frames per table — helios/src/engram.rs:348 (const STAGING_FRAMES: usize = 2;), summed at helios/src/engram.rs:212-219, with max_staged_rows = tokens * core_heads at helios/src/runtime_core/engram.rs:294-296:

            let max_staged_rows = tokens
                .checked_mul(core_heads as u64)
                .ok_or_else(|| invalid("Engram staging row count overflow"))?;

Arithmetic at max_tokens = 4096 and the E2B PLE row width the PR quotes (17,920 B = 8,960 bf16 elements):

Impact: a second producer or a future recipe that keeps the existing two-plane token-map shape and merely flips encoding to BF16 silently costs 24× the host staging — ~3.1 GiB avoidable — which is precisely the unified-memory pressure the PR is meant to relieve. There is no producer, test, or doc line covering BF16+XOR_MODULO, so the failure would surface first as an opaque memory-budget rejection in check_memory_limit (helios/src/runtime_core/model.rs:764-770, "embedding tables, staging, and row cache exceed the memory budget"), not as a validation error naming the real mistake.

Fix: reject non-IDENTITY methods when encoding == Encoding::Bf16 in both schema::validate_engram (next to the :428-436 BF16 pin) and the decode arm at runtime_core/engram.rs:165-174, or bound heads for single-plane encodings and document the bound. Either is a few lines and keeps the two-plane tags untouched.

F2 (Minor) — publish-time parity is still incomplete for per-encoding geometry

helios/src/core/schema.rs:366-370 validates only non-zero rows/width before the BF16 size pin:

    for table in &engram.tables {
        let has_scales = engram_encoding_has_scales(table.encoding)?;
        if table.rows == 0 || table.embedding_width == 0 {
            return Err(invalid("engram table has no rows or width"));
        }

The decoder requires encoding-exact geometry — helios/src/runtime_core/engram.rs:139-145:

        let (width, block, row_bytes, scale_bytes) = match encoding {
            wire::engram_table::Encoding::Fp8E4m3E8m0 => (256, 32, 256usize, Some(8usize)),
            wire::engram_table::Encoding::Nvfp4E4m3Global
                if table.global_scale.is_finite() && table.global_scale > 0.0 =>
            {
                (160, 16, 80usize, Some(10usize))
            }

and enforces it at helios/src/runtime_core/engram.rs:177-178 (table.embedding_width != width || table.scale_block != block), plus hash-geometry checks that exist only in the decoder (:209-234, "invalid Engram hash geometry"). Impact: heliopause's verify_published (heliopause/src/export/core.rs:3017) can still sign a core that Helios refuses at load — the same defect class the PR closes for gapped shards only (heliopause/src/export/core.rs:5306-5336). The PR's claim is accurate as scoped but partial; a reviewer should not read it as full signing/loading parity. Fix: extend schema::validate_engram to call the same width/block/global-scale and hash-geometry predicates the decoder uses (or share one helper), so signing and loading cannot disagree.

F3 (Minor) — docs omit the accepted BF16+XOR_MODULO mode

helios/manifest.md:457-463:

Single-plane `BF16` tables store raw `embedding_width * 2`-byte rows without a
scale plane (`scales` absent, `scale_buffer` empty, `scale_block == 0`,
`global_scale == 0`). Tables with `EngramHash.Method.IDENTITY` use one lookup
head (`heads = 1`), empty `token_map` and hash arrays, `compressed_vocabulary == rows`,
and GPU request delivery (`request_buffer`): captured code publishes one `int64`
row ID per token in `[0, stored_rows)` (converting to partition-local indices
when sharded) or `-1` for inactive slots; out-of-range row IDs fail gathering.

docs/core-format-design.md:94 is the only other BF16 mention. Both describe BF16 and IDENTITY as separate facts and never state whether BF16 may carry a token map. Combined with F1 this is an observability/documentation gap, not just a nit: the format spec is the contract a second producer reads. Fix: one sentence either way — "single-plane BF16 tables are IDENTITY-indexed only" (with F1's validator change) or the documented head bound.

1b. Areas checked and found sound (report plainly, do not re-litigate)

2. Unintended system-level consequences

The only system-level hazard I found is F1: it is a memory-amplification bug whose blast radius is host pinned memory (shared with row cache and prefix-cache budget) and whose trigger is a legal-but-undocumented format combination. The staging path itself is unchanged in structure — two frames, one sync channel of depth STAGING_FRAMES (helios/src/engram.rs:700), one worker per table by default (helios/src/runtime_core/selection.rs:47-50) — so I found no new lock contention, head-of-line blocking, unbounded retention, or hot-path reversal introduced by the Planes refactor. The Option-plane changes are a strict widening of the same control flow: every place that used to index [Plane; 2] now guards the scale plane, and the guard is on the cold path (open/load/upload), not per-row on the gather path.

On the metric/rate span check the lens asks for: this PR changes what bytes are counted (staging_bytes now sums one plane for single-plane tables, helios/src/engram.rs:212-219) but not when or over what span it samples — it stays an end-to-end pre-open estimate feeding check_memory_limit, not a disk-thread-only or rank-0-only measure, so no threshold silently changed meaning. resident_scale_bytes remains an all-shard sum and correctly reads zero for single-plane catalogs.

3. Architecture, contracts & charter compliance

4. Tests & claim accuracy

Recommendation

  1. Owner: one recorded answer on Encoding.BF16 / Method.IDENTITY (AGENTS.md:376-381), plus the producer or companion recipe link.
  2. Author: reject BF16 + non-IDENTITY hashing in schema and decoder (F1), extend signing to the decoder's width/block/global-scale and hash-geometry predicates (F2), and add the two matching negative tests plus one doc sentence (F3).
  3. CI: unblock the Windows build, pytest, and lifecycle workflows, and replay one pre-existing FP8/NVFP4 core without re-export.
  4. Do not re-litigate the Planes refactor, the delivery-group fix, the resident_scale_bytes gating, or the CPU test surface — those are in good shape.

Open questions / not found