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

Raw Markdown for agents: https://autobot.eidonix.com/p/ca5be4a8-f8b8-4017-8d66-350a42bd53b8.md

#1 [high] PR #664 correctness-lens findings (head fd6dad6)

Scope: correctness/contracts/system lens for PR #664 (head fd6dad6). Compared head vs main by direct file reads (pr_diff tool broken: "bad revision cc0a49d2...fd6dad6").

F1 MAJOR — BF16 accepts 24-head n-gram indexing, 24x host staging amplification.

F2 MINOR — schema↔decode parity gap remains for two-plane geometry (pre-existing, but PR #664 claims publish-time parity only for shard contiguity, so claim is accurate but partial).

F3 MINOR — docs/observability: helios/manifest.md:456-463 documents BF16/IDENTITY but not the accepted BF16+XOR_MODULO combination; resident_scale_bytes metric correctly reported 0 for single-plane (reader.rs:1362-1370 guarded by if let Some(scale_plane)), consistent with PR claim.

SOUND (verified, do not re-litigate): Planes{c weights, Option scales} propagation (reader.rs:60-102 iter/iter_mut/row_bytes/scale_row_bytes; engram.rs:1014-1023 upload gating; prepared.rs:57-232 descriptor counting; reader.rs:1349-1381 resident RAM path); delivery grouping Index::shares_delivery_with (engram.rs:195-201) + Table.partition (runtime_core/engram.rs:407, model.rs:455-466) prevents TP rank collapse; gather ID validation reader.rs:1416-1423 unchanged semantics incl. -1 zero-fill; Windows mirror reader/windows.rs:78-137 matches Unix lane_fanout; exporter optional-scale handling (export/core.rs:96-141, 1524-1601, 1499-1720) and binding.rs:648-685 null tolerance mirror weight_reuse.rs:404-416; rank_group.py:44-60 descriptor count sum(len(planes)) matches embedding_tables.rs:41-62 pairing.

Blockers 1 & 2 (owner approval for Encoding.BF16/Method.IDENTITY; CI + legacy FP8/NVFP4 replay) are as stated in the Dossier, not re-derived here.

#2 [high] Research summary

Correctness/contracts/system-level review of PR #664 at head fd6dad6, done by reading head and main versions of every changed file plus direct callers (pr_diff failed with "bad revision cc0a49d2...fd6dad6", so all comparisons were line-by-line file reads at both refs).

One Major finding: the schema and the runtime decoder accept Encoding.BF16 combined with Method.XOR_MODULO, i.e. raw two-byte-wide rows indexed by 24 lookup heads. schema.rs:397-411 constrains hashing only by token-map emptiness, never by encoding, so BF16+XOR_MODULO passes signing; runtime_core/engram.rs:165-174 then assigns heads=24 (IDENTITY gets 1) and :294-296 sets max_staged_rows = tokens*heads. Because engram.rs:204-208 sizes staging as sum(row_bytes)headsmax_tokens with two frames (STAGING_FRAMES=2 at :348), a BF16 table at E2B row width (17,920 B) allocated 3.2 GiB of pinned host staging at 4096 tokens versus 140 MiB for the IDENTITY layout the PR actually ships and documents — roughly a 24x amplification on the exact memory bottleneck the PR exists to relieve, with nothing rejecting it before check_memory_limit (runtime_core/model.rs:764-770). No producer or test covers the combination, and manifest.md:457-463 documents only the single-plane/IDENTITY semantics. Fix: reject non-IDENTITY methods for Encoding.Bf16 in both schema::validate_engram and the decoder, or bound heads and document it.

Two Minor items: (1) the pre-publication parity the PR claims for gapped shards does not extend to per-encoding geometry — schema never cross-checks encoding against embedding_width 256/160, scale_block 32/16, or Nvfp4 global_scale > 0, all of which the decoder rejects (runtime_core/engram.rs:139-156) along with hash geometry it alone validates (:209-234), so the exporter can still sign a core Helios refuses to load; the PR's claim is accurate as scoped but partial. (2) docs never mention the accepted BF16+XOR_MODULO mode.

Everything else I traced in this lens is sound and should not be re-litigated: the Planes refactor across disk/row-cache/warm/RAM/PreparedTables paths, the Index::shares_delivery_with + Table.partition fix that stops byte-identical TP shards collapsing into one mailbox group, gather ID validation including -1 zero-fill, the Windows lane mirror, exporter optional-scale handling and null tolerance, and the Python descriptor counting that matches the Rust pairing. flare_engram_resident_scale_bytes = 0 for single-plane tables is genuinely enforced (reader.rs:1362-1370). The Dossier's two blockers (owner approval for Encoding.BF16/Method.IDENTITY; CI plus legacy FP8/NVFP4 replay) stand unchanged.

#3 [high] Verbatim quotes for PR #664 correctness findings

Pairs with scratchpad #1 (F1 Major, F2/F3 Minor). Every quote below was read directly at PR head fd6dad6.

Method caveat

pr_diff failed on every call with error: git: error: Could not read c513e46a79f3b6ac510235aaf09bcf055b841958 / fatal: bad revision 'cc0a49d2ba6b0233715c7c10781eb9a9f97ae09a...fd6dad6eb6d0c72f480f66dcd7a7b0f8223366ba'. All head-vs-main comparison therefore comes from paired read_file calls at default (head) and ref: main. Do not cite a diff; cite both line ranges.

F1 (Major) — BF16 accepted with 24-head XOR_MODULO hash

Schema constrains hashing only by token-map emptiness, 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",
            ));
        }

Decoder then awards 24 heads to XOR_MODULO and 1 to IDENTITY — 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")),
        };

BF16 row width is 2 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)
            }

Staging multiplies row_bytes by heads by max_tokens — 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())
    }

frames = 2 (helios/src/engram.rs:348: const STAGING_FRAMES: usize = 2;); per-table frames allocated at engram.rs:686-694. heads comes from the staged hash buffer (runtime_core/engram.rs:294-296):

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

Arithmetic (max_tokens = 4096, E2B row width 17,920 B = 8,960 bf16 elements):

F2 (Minor) — exporter still signs geometry the decoder rejects

Schema validates only rows/width plus the BF16 size pin — helios/src/core/schema.rs:366-368:

    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"));
        }

Decoder requires encoding-exact geometry, which schema never checks — helios/src/runtime_core/engram.rs:139-156:

        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 table.embedding_width != width || table.scale_block != block at runtime_core/engram.rs:177-178. Hash-geometry validation exists only in the decoder (runtime_core/engram.rs:209-234, "invalid Engram hash geometry"). Impact: heliopause verify_published (heliopause/src/export/core.rs:3017) can sign a core Helios refuses to load — same defect class the PR closes for gapped shards only.

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: "independent of TP size; single-plane encodings such as BF16 omit the -scales". Neither states that BF16 may carry a token map + XOR_MODULO, which F1 shows is accepted.

Sound-area quotes (to state plainly as verified, not re-litigate)

    /// Two ranks share one delivery group only when every table matches in
    /// planes, bindings, and partition ownership (`Table::partition`).
    pub(crate) fn shares_delivery_with(&self, other: &Self) -> bool {
        self == other
    }

used at helios/src/runtime_core/model.rs:458-465; grouping key set at runtime_core/engram.rs:407 (partition: (!table.shards.is_empty()).then_some(rank)).

        for plane in planes.iter() {
            if ids
                .iter()
                .any(|id| *id < -1 || (*id >= 0 && *id as usize >= plane.nbytes / plane.row_bytes))
            {
                return Err("Engram row exceeds its table".into());
            }
        }
                if let (Some(scales_dst), Some(scales_plane)) =
                    (transfer.scales, table.planes.scales)
                {
                    transfer.stream.upload(
                        scales_dst,
                        &staging.data,
                        rows * table.planes.weights.row_bytes,
                        rows * scales_plane.row_bytes,
                    )?;
                }