Correctness, Contracts & System-Level Consequences — PR #664
Reviewed at head c769355. Every finding below was verified by opening the changed file at head; quotes are verbatim.
Key findings
- Major — memory amplification: BF16 row width is unbounded and staging/miss workspace scale with
embedding_width * 2, so the feature can spend more host memory than the device memory it frees, on the exact unified-memory class it targets (§1). - Major (charter/process) — new core contract, no owner approval:
Encoding.BF16 = 3,Method.IDENTITY = 3and a new mailbox contract are added as captured-graph contract while the description claims no new captured-graph surface (§2). - Minor —
engram_encoding_has_scalesis wrong forUnspecifiedyet is now the authority for plane presence in eight call sites (§3). - Minor — the "distinct partitioned delivery groups" fix is an invisible side effect of derived
PartialEqon a field no production code reads, and is set inconsistently across paths (§4). - Minor — undeclared input relaxation (
"weights": null) and collapsed diagnostics on the signing/validation side (§5). - The stricter shard-contiguity rule is a real fix and does match the loader, but it changes validation for artifacts that used to sign; no test covers an older gapped core (§6).
- The single-plane reader path is tested across disk, cache, warm and RAM — I expected otherwise from the description and was wrong; the residual claim problem is only the unfinished Validation section and the total absence of GPU/serving evidence (§7).
1. Memory amplification: BF16 row width inflates per-table staging and miss workspace with no cap (Major)
The staging machinery was sized for fixed 256 B (FP8) / 80 B (NVFP4) rows. It is now embedding_width * 2, embedding_width is an unconstrained u32, and both buffers are allocated per table:
helios/src/engram.rs:195-201
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())
}
helios/src/engram.rs:677-685 allocates STAGING_FRAMES (2) full-size frames per table:
let staging_bytes = table.staging_payload_bytes(max_tokens)?;
let mut staging = Vec::with_capacity(STAGING_FRAMES);
for _ in 0..STAGING_FRAMES {
staging.push(Staging {
data: stream.mapped_host_buffer(staging_bytes)?,
ready: stream.mapped_host_buffer(4)?,
and a second full-size buffer exists in the miss workspace, helios/src/engram/reader.rs:1049
let miss_output = allocated(max_rows * row_bytes, 0u8)?;
The width the PR itself tests with is 8,960 BF16 elements = 17,920-byte rows (helios/src/engram/reader.rs:2540: let row_bytes = 17920; // 8960 BF16 elements). At 4,096 packed tokens and heads == 1 (IDENTITY forces one head, helios/src/runtime_core/engram.rs:180-182), that is ~73 MiB per frame ⇒ ~147 MiB of mapped host staging plus ~73 MiB miss_output ≈ 220 MiB per table. The motivating catalog is 35 (E2B) to 42 (E4B) tables ⇒ roughly 7.5–9.2 GiB of pinned host memory for a 4.38–5.25 GiB on-disk table.
Impact: that memory is charged against the host budget at helios/src/runtime_core/model.rs:762-768 and :777 (check_memory_limit(..., embedding_host_bytes)), and staged payloads are also counted in staging_bytes at model.rs:489-491. On DGX Spark / Thor-class unified memory the staging cost is drawn from the same pool whose headroom the feature is supposed to buy back, so a BF16 catalog with the motivating row width has a plausible net loss of usable memory; nothing in validation rejects it and the failure surfaces only as "embedding staging exceeds the memory budget" or a memory-limit error at load.
Fix: bound embedding_width for Encoding::Bf16 in validate_engram (helios/src/core/schema.rs:421-429 is where the row size is derived — add an upper bound there, e.g. ≤ 8 KiB per row), and/or reduce STAGING_FRAMES/max_tokens for wide-row tables, and document the per-table staging cost next to the new single-plane paragraph in helios/manifest.md:455-470.
Note on where this belongs: the arithmetic is checked, so nothing overflows or panics — this is a sizing/accounting defect, not a safety one.
2. New core-contract surface with no recorded owner approval (Major, charter)
helios/manifest.md:455-470 (added by this PR) and both .proto files document Encoding.BF16 = 3, Method.IDENTITY = 3 and a new mailbox contract: one int64 row ID per token in [0, stored_rows), partition-local when sharded, -1 for inactive slots, out-of-range IDs failing gather. The .proto comments are at helios/proto/core.proto:254-300 and helios/proto/runtime_core.proto:657-703.
The charter states: "Captured-graph op contracts: Adding a new one—even if it reuses an existing graph kind—requires owner approval before you write it." The PR body asserts the opposite without evidence:
"Extend the existing offloaded-embedding contract with two orthogonal primitives — no model allowlists, capability flags, or new captured-graph operation families"
A device-published row-ID mailbox is a new graph-output contract: the captured graph must now write int64 row IDs with a specific range and -1 sentinel into request_buffer for every consuming graph. There is no approval note, issue reference, or reviewer sign-off in the PR — unlike the direct predecessor #566, which carried an explicit maintainer-contract-approval note for its prefetch mailbox, and #535, which is the open approval thread for the neighbouring advisory mailbox and does not cover IDENTITY.
Fix: request and record approval for the IDENTITY mailbox semantics (row-ID range, -1 inactive, partition-local IDs on sharded tables, out-of-range ⇒ gather error) before merge. The enum append itself is clean — values = 3 only, no existing tags, defaults or FP8/NVFP4 layout touched (verified in both .proto files), so this is a process blocker, not a wire blocker.
3. engram_encoding_has_scales returns "has scales" for an invalid encoding (Minor, contract hygiene)
helios/src/core/schema.rs:319-329
pub fn engram_encoding_has_scales(encoding: i32) -> Result<bool> {
match wire::engram_table::Encoding::try_from(encoding) {
Ok(
wire::engram_table::Encoding::Unspecified
| wire::engram_table::Encoding::Fp8E4m3E8m0
| wire::engram_table::Encoding::Nvfp4E4m3Global,
) => Ok(true),
Ok(wire::engram_table::Encoding::Bf16) => Ok(false),
Err(_) => Err(invalid("engram table has no encoding")),
}
}
Unspecified is mapped to Ok(true) with a comment explaining that legacy spans fixtures rely on it. This function is now the single authority for plane presence across the reader, decoder and exporter (helios/src/core/reader.rs:229, helios/src/runtime_core/engram.rs:29, heliopause/src/export/core.rs:98, :423, :1546).
Impact: an encoding = 0 table is reported as needing a scale plane rather than as having no encoding, so the caller errors with a plane-shaped diagnostic ("embedding table lacks payload plane") instead of "engram table has no encoding". It is correct today only because validate_engram (schema.rs:357-359) and decode (runtime_core/engram.rs:165) happen to reject Unspecified first — an ordering dependency that will not survive the next caller added outside those two paths.
Fix: return the legacy two-plane default only where legacy fixtures need it (an explicit constant or a caller-side flag), and make the shared helper reject Unspecified.
4. "Distinct partitioned delivery groups" rests on an unread field used as an implicit equality key (Minor, fragility)
helios/src/engram.rs:176-187 adds partition: Option<usize> to Table, set in helios/src/runtime_core/engram.rs:425 ((!table.shards.is_empty()).then_some(rank)). Grep over helios/src shows partition is never read in production code — only declared, set, set to None, and asserted in tests (runtime_core/engram.rs:1076, execution/threaded.rs fixtures).
Its entire effect comes from derived PartialEq feeding the dedup key at helios/src/runtime_core/model.rs:458:
if let Some((_, ranks)) = engram.iter_mut().find(|(existing, _)| existing == &index)
{
ranks.push(local);
}
Additionally helios/src/engram/prepared.rs:131 sets partition: None unconditionally for every RAM/peer-attached table, so the marker is carried on one path and dropped on the other.
Impact: the invariant "two TP ranks with byte-identical shard bytes must not collapse into one shared gather group" is enforced by an invisible side effect of a derived trait on a field nothing reads. Any later content-based dedup, a HashMap keyed on planes, or a refactor of Index silently re-introduces the bug it fixes, and there is no test on the prepared/RAM path.
Fix: make the key explicit — a delivery_key() that includes partition, used at model.rs:458 — or assert the invariant in PreparedTables::index, and set partition consistently in prepared.rs.
5. Undeclared input relaxation and collapsed diagnostics on the signing side (Minor)
heliopause/src/export/binding.rs:653-657
for name in ["weights", "scales"] {
if let Some(parts) = value.get_mut(name) {
if parts.is_null() {
continue;
}
This tolerates "weights": null as well as the intended "scales": null, and nothing in the description mentions the change. A null weights plane now passes append_planes, is embedded into output.index.engram (binding.rs:515) and only fails much later in core_engram (heliopause/src/export/core.rs:1540-1546). Fix: keep the early error for weights, tolerate null only for scales, and state the relaxation in the description.
helios/src/core/schema.rs:455-461 collapses four previously distinct conditions into one message:
if table.weights.is_some()
|| table.scales.is_some()
|| table.request_buffer.is_empty()
|| table.shards.len() != ranks as usize
{
return Err(invalid("invalid partitioned engram table"));
}
On main these were separate errors for shared planes on a partitioned table. An operator debugging a rejected core can no longer distinguish a shared-plane misuse from a missing mailbox or a rank-count mismatch. Fix: keep distinct messages.
6. Shard-contiguity tightening: genuine fix, but a compatibility change with no test for old artifacts (Minor)
helios/src/core/schema.rs:462-503 now requires shard.rank as usize == rank, shard.first_row == end, shard.rows != 0, and a final end == table.rows:
if shard.rank as usize != rank || shard.first_row != end || shard.rows == 0 {
return Err(invalid(
"engram partitions must cover table rows in rank order",
));
}
...
if end != table.rows {
return Err(invalid("engram partitions must cover all table rows"));
}
This makes signing agree with loading — helios/src/runtime_core/engram.rs:80-117 (validate_shards) already enforced contiguity and rank order pre-PR — so the fix is correct and the description does declare it.
Two consequences worth recording. First, validate_deployment runs on the load path (helios/src/core/protection.rs:637, :988), so a previously signed core with a gapped or short shard list now fails verification rather than failing later in decode; that is the right outcome, but the charter's compatibility clause ("verify that existing data, artifacts, and exported cores still load") is not exercised — the new tests only assert rejection of freshly built tables (heliopause/src/export/core.rs:5347-5377). Second, no issue or reproduction is linked, so it is unclear whether this was an observed corruption case or a theoretical one. Fix: add a checked-in old-style gapped core fixture and assert it fails with the new message, and link the motivating report.
7. Tests and claim accuracy
What is genuinely covered (and better than the description admits). helios/src/engram/reader.rs:2535-2599, single_plane_bf16_gathers_across_disk_cache_ram_and_warm, drives a single-plane table at the real 17,920-byte row width through Reader::from_files in disk mode (both resident_scales settings), asserts resident_scale_bytes == 0, then the cached reader including warm(&planes, &[-1, 7, 31, 999]) with hit/miss accounting, then the RAM reader — and asserts out-of-range and negative-beyond-sentinel IDs error:
assert!(reader.gather(&planes, &[rows as i64], &mut vec![0; row_bytes]).is_err());
assert!(reader.gather(&planes, &[-2], &mut vec![0; row_bytes]).is_err());
That exercises the if scales > 0 guards I was concerned about (reader.rs:1102-1104, :1156-1159) and the scale_base arithmetic (reader.rs:1095). The Planes::single constructor is not unused. Similarly helios/src/engram/prepared.rs:440-466 covers single-descriptor preparation, the metadata-mismatch error, descriptor-count mismatches, and the RAM gather with a -1 slot.
What is not covered.
- No GPU, serving or benchmark evidence anywhere, and the Validation section still contains the author's placeholder while the Result paragraph is written in the completed tense: "(update this line once the Thor E2B export + benchmark completes)". The 4.38 GiB / 5.25 GiB figures are arithmetic only, and my §1 arithmetic shows the host-side cost that the description does not count.
- No producer:
ignition/components/engram.py:36-49still hardcodescol = tl.arange(0, 256)withweight.view(torch.float8_e4m3fn)and 8-byte E8M0 scales, so nothing in-tree emitsEncoding.BF16orMethod.IDENTITY. The Python change in this PR is descriptor counting only (ignition/preparation/rank_group.py:47). The consumer side is therefore qualified against fixtures it constructs itself. - Windows:
helios/src/engram/reader/windows.rsis changed, but only as test-fixture type updates (Planes::twoat:227,:322), and the author states Windows builds were not run. No new Windows-specific code path is introduced, so the parity risk is low but unverified.
Metric/rate span check: no finding. No metric's measured window or scope changed. resident_scale_bytes is charged only when a scale plane exists (reader.rs:1363-1368, asserted zero in the new test at :2569); cache_bytes/capacity_rows remain allocated-byte gauges (reader.rs:1056-1061); estimated_export_fds counts planes generically and its new single-plane assertion is (14, 14, 0) (heliopause/src/export/core.rs:4924-4936); the start-up phase label change to "disk" for single-plane catalogs (helios/src/runtime_core/model.rs:891-897) is accurate.
Verified sound
- Wire compatibility: values appended only; FP8/NVFP4 tags, defaults and layout untouched (both
.protofiles);runtime_core_pb2.py(not opened) regenerated consistently. - Staging/upload layout consistency for one plane: reader writes weights at
row * weights(reader.rs:1099-1108),scale_base = ids.len() * weights(:1095) is dead for single-plane, andTransfers::enqueueuploads weights at offset 0 (helios/src/engram.rs:999-1014) — consistent for one and two planes. - Resident-scales fast path cannot misfire: keyed on
ordinal == 1(reader.rs:803-809), andPlanes::iter()yields scales second only when present. - Mixed catalogs:
--embedding-table-resident-scalesstill works when some table has scales (has_scale_planes = any(...),model.rs:475-478); explicit use with no scale plane errors with a clear message (helios/src/runtime_core/selection.rs:63-67);Reader::from_filesskips scale loading for the single-plane table; resident-bytes accounting chains the optional plane. - Descriptor accounting:
1 + scales.is_some()per table (helios/src/engram/prepared.rs:182-190) matchesdescriptors()(:216-223) andignition/preparation/rank_group.py:47, with a mismatch error atprepared.rs:71. validate_bufferrewrite (runtime_core/engram.rs:315-332) removes an out-of-boundsbuffer.shape[0]read thatmainperformed before checkingshape.len() == 2— a latent panic fixed, not introduced.- No new locks, queues or serialization on a hot path; the
Planeschange is a type refactor over existing code paths, and the per-table staging allocation count is unchanged (stillSTAGING_FRAMESper table).
Open questions / what could not be found
- Who approved the
IDENTITYmailbox contract? No issue, comment or note records it; #535 covers the advisory mailbox, not this. Given §2 this is the gate I would hold the PR on. - Where does the producer live? Not in this repo;
docs/model-preparation.md:326-330(not opened) permits external recipes, and no companion recipe PR is referenced (contrast #566 →local-inference-lab/hyperflare-recipes#70). Without it, neither the memory claim nor the end-to-end gather can be reproduced. - Did anyone observe a gapped-shard core? No linked issue or reproduction for the contiguity fix (§6).
- Does any hosting/publishing tool outside the changed paths assume a
-scalespayload per Engram table? Not established; this PR fixesheliopause/src/embedding_tables.rs(:41-56accepts 1–2 planes, optionalscales) andverify_published, but I did not audit resumable export or external scripts. - Should host staging for wide BF16 tables be budgeted separately (§1)? The PR adds no limit and no documentation of the per-table cost.