Subtraction, Simplicity & Conventions review — PR #664 (helios,heliopause,ignition: support single-plane BF16 and identity-indexed offloaded embedding tables)
Head reviewed: 263dfe9b (23 files, +1722/−548). All citations below were re-verified in the code at that commit.
Key findings
The diff is lean and idiomatic for what it does — the [Plane; 2] → Planes { weights, scales: Option<Plane> } refactor consistently removes indexing assumptions rather than adding a second code path, and I found no env-var knob, supports_*/can_* flag, model allowlist, or new captured-graph op family in the code (the approval question belongs to the contracts lens and is not re-litigated here).
Four things are worth cutting, and two of them are branches that cannot execute today:
- HIGH — dead duplicate encoding validation in
helios/src/core/schema.rs:367-372: five lines that re-derive exactly whatengram_encoding_has_scalesalready rejects, with the identical error string. - HIGH — dead
Nonearm inhelios/src/runtime_core/engram.rs:257-268: thescales.is_some()rejection inside thePlanesconstruction is already performed for both shared (:191) and partitioned (:97-101) tables three hundred lines earlier. - HIGH — speculative legacy fallback in
helios/src/runtime_core/engram.rs:29-34whose own comment says its justification is test fixtures; the strictUnspecifiedrejection this PR adds everywhere else means no published core can reach it. - MED-HIGH — a third and fourth copy of the same engram-plane walk (
heliopause/src/export/core.rs:96-142,:408-440, andhelios/src/runtime_core/engram.rs:19-68spans), with a duplicated error message in two of them.
Net: ~30 removable lines with zero behaviour change, plus one shared walker replacing three near-identical loops. Nothing else in the diff should be deleted.
1. HIGH — validate_engram re-validates the encoding it is about to validate again (delete 5 lines)
helios/src/core/schema.rs:365-372:
let roles = [wire::PayloadRole::Weights, wire::PayloadRole::TunedWeights];
for table in &engram.tables {
let encoding = wire::engram_table::Encoding::try_from(table.encoding)
.map_err(|_| invalid("engram table has no encoding"))?;
if encoding == wire::engram_table::Encoding::Unspecified {
return Err(invalid("engram table has no encoding"));
}
let has_scales = engram_encoding_has_scales(table.encoding)?;
engram_encoding_has_scales (helios/src/core/schema.rs:316-327) is:
pub fn engram_encoding_has_scales(encoding: i32) -> Result<bool> {
match wire::engram_table::Encoding::try_from(encoding) {
Ok(
wire::engram_table::Encoding::Fp8E4m3E8m0
| wire::engram_table::Encoding::Nvfp4E4m3Global,
) => Ok(true),
Ok(wire::engram_table::Encoding::Bf16) => Ok(false),
_ => Err(invalid("engram table has no encoding")),
}
}
Unspecified is Ok(Unspecified) and unknown tags are Err, so both fall into the _ arm and return the same "engram table has no encoding" message. The try_from/map_err and the if encoding == Unspecified are unreachable-by-effect.
Concrete change: delete lines 367-371, keep let encoding = wire::engram_table::Encoding::try_from(table.encoding).map_err(...)?; only if the typed encoding is still needed — it is, at :433 (encoding == Encoding::Bf16) and :457/:501 pass table.encoding untyped. So keep one line, drop four:
let encoding = wire::engram_table::Encoding::try_from(table.encoding)
.map_err(|_| invalid("engram table has no encoding"))?;
let has_scales = engram_encoding_has_scales(table.encoding)?;
This is also the conventions point: the PR's stated goal is that scale-plane validation is centralized in engram_scales/engram_encoding_has_scales; the leftover hand-rolled copy is exactly the duplication that centralization was meant to remove.
2. HIGH — the Planes construction carries an unreachable rejection (delete 7 lines)
helios/src/runtime_core/engram.rs:257-268:
let planes = Planes {
weights: plane(weights, row_bytes)?,
scales: match scale_bytes {
Some(bytes) => Some(plane(scales, bytes)?),
None => {
if scales.is_some() {
return Err(invalid("single-plane Engram table cannot carry scales"));
}
None
}
},
};
scale_bytes is None exactly when the encoding has no scale plane (:139-156: FP8 → Some(8), NVFP4 → Some(10), BF16 → None). In that case both call paths have already rejected a present scale plane:
- shared table:
helios/src/runtime_core/engram.rs:187-193if has_scales { if table.scale_buffer.is_empty() || !buffers.insert(table.scale_buffer.clone()) { return Err(invalid("invalid Engram table encoding or bindings")); } } else if !table.scale_buffer.is_empty() || table.scales.is_some() { return Err(invalid("single-plane Engram table cannot carry scale bindings")); } - partitioned table, via
validate_shards(&table, world, has_scales)?at:158,helios/src/runtime_core/engram.rs:97-101
and} else if shard.scales.is_some() { return Err(invalid( "single-plane embedding partition cannot carry scales", )); }scaleshere is taken from that same shard at:242.
So the inner if scales.is_some() can never fire, and its message is a third wording of the same invariant ("cannot carry scale bindings" / "cannot carry scales" / "cannot carry scales plane" — cf. helios/src/core/schema.rs:337, :383).
Concrete change: replace the whole match with
scales: scale_bytes.map(|bytes| plane(scales, bytes)).transpose()?,
No test coverage is lost: the only test touching this area, helios/src/runtime_core/engram.rs:1091-1094, builds shard_scales and asserts both validate_shards and decode fail with "cannot carry scales" — both errors come from validate_shards (:99), which decode calls at :158, i.e. before this block.
3. HIGH — the legacy encoding == 0 shim is justified only by a hand-encoded test fixture
helios/src/runtime_core/engram.rs:28-35:
for table in index.engram.iter().flat_map(|e| &e.tables) {
// Legacy pre-encoding `ModelIndex` fixtures leave `encoding == 0` with two planes.
let encoding = if table.encoding == wire::engram_table::Encoding::Unspecified as i32 {
wire::engram_table::Encoding::Fp8E4m3E8m0 as i32
} else {
table.encoding
};
let has_scales = crate::core::schema::engram_encoding_has_scales(encoding)?;
Three reasons this should be deleted rather than kept:
- Its own comment names fixtures as the justification, and there is exactly one:
helios/src/runtime_core/engram.rs:495-519metadata_without_partitions_retains_shared_planes, which decodes a hand-written byte string (:498-500) with no encoding field and then asserts two planes (:513-518). That fixture callsspans/validate_shardsdirectly, bypassingcore::schema, which is why it survives. - No published core can carry
encoding == 0past this PR's own validators:helios/src/core/schema.rs:316-327rejectsUnspecifiedwhen signing and when reading, and indecodeitself the fallback is what hides the inconsistency — without it,:139-156would fall to_ => return Err(invalid("invalid n-gram encoding or global scale"))at:155, which is the correct, consistent answer. AGENTS.mdexplicitly rejects "speculative compatibility, fallback layers"; this is the textbook shape of one (a silent reinterpretation of an invalid value, on the hot load path, for one test).
Concrete change: delete the four-line if/else and keep let encoding = table.encoding; (or inline it), then drop encoding entirely and call engram_encoding_has_scales(table.encoding) / engram_scales(table.encoding, ...) as the sibling validate_engram does. Then add field 12 (encoding = Fp8E4m3E8m0) to the fixture bytes at :498-500, or construct the fixture with wire::EngramTable { encoding: ..., .. } in Rust instead of raw bytes. Caveat for the author: if a real pre-existing binary core exists with encoding unset, then this is a compatibility bug (missing migration) rather than excess code — either way, the shim as written cannot be the answer, because the PR rejects encoding == 0 everywhere else and signing would never have produced such a core.
4. MED-HIGH — the engram-plane walk exists three times (plus a duplicated error string)
The same for table { if shards.is_empty() { weights } else { for shard { weights, scales } } } walk, including the same engram_scales calls, appears at:
heliopause/src/export/core.rs:96-142(roles, quoted in the earlier read:if table.shards.is_empty() { ... } else { if table.weights.is_some() || table.scales.is_some() { return Err(invalid("partitioned embedding tables cannot also hold shared planes")) } ... });heliopause/src/export/core.rs:408-440(validate_ranks,:420-437):} else { if table.weights.is_some() || table.scales.is_some() { return Err(invalid( "partitioned embedding tables cannot also hold shared planes", )); } for shard in &table.shards { locate( &source.payload, shard.weights.as_ref().unwrap_or(&wire::Span::default()), )?;helios/src/runtime_core/engram.rs:19-68(spans), which walks it better — it rejects a missing plane (ok_or_else(|| invalid("missing table plane"))?,:43) instead ofunwrap_or(&wire::Span::default())as bothheliopausecopies do atcore.rs:413and:429.
Difference worth noting: the two heliopause copies do not check shard.rank as usize >= index.ranks.len() in validate_ranks (heliopause/src/export/core.rs:426-437) although roles does (:119-121). That asymmetry is a symptom of the copy, not a separate bug to patch.
Concrete change (structural, not a line count): add one helper next to engram_scales, e.g. helios_core::core::schema::engram_planes(index) -> Result<Vec<(Option<usize>, &wire::Span)>> (the body is already written twice — runtime_core/engram.rs:19-68 and schema.rs has the catalog/Roles context to host it). Then roles() becomes for (owner, span) in engram_planes(index)? { result.push(Role { kind: 4, owner, span: span.clone() }) }, validate_ranks becomes for (_, span) in engram_planes(&source.index)? { locate(&source.payload, span)? }, and the duplicated "partitioned embedding tables cannot also hold shared planes" string disappears from both sites. If the author prefers not to cross the crate boundary, the minimum ask is to delete the second copy in validate_ranks by having it reuse the already-pub(crate) roles() for the engram spans.
5. LOW — shares_delivery_with is self == other with a doc comment restating Table::partition's
helios/src/engram.rs:195-201:
impl Index {
/// 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
}
}
The method does give the invariant a name at the call site (helios/src/runtime_core/model.rs:458-460, tested at helios/src/runtime_core/engram.rs:1079-1084), which is why I list it last and would not insist. If anything is cut, it is seven lines of wrapper replaced by a != b at the two call sites plus the invariant moved into the comment above Table::partition (helios/src/engram.rs:179-180). Judgement call; keeping it is defensible.
6. Checked and cleared — do not report these as excess
I looked for dead code in every new public item; all are used:
Planes::iter—helios/src/engram.rs:205(staging_payload_bytes) andhelios/src/engram/reader.rs:1419.Planes::iter_mut— single consumerhelios/src/runtime_core/model.rs:849.Planes::total_nbytes—helios/src/engram.rs:634,640.Planes::row_bytes—helios/src/engram/reader.rs:1014,1417,helios/src/engram.rs:435.Planes::scale_row_bytes— onlyhelios/src/engram/reader.rs:1094,1202; two callers is enough to keep.Planes::single/Planes::twoare#[cfg(test)](helios/src/engram/reader.rs:60-77) and used across ~25 test sites (reader.rs:1500,1656,1772,…,2546;engram.rs:1066,1250,1392,1493;windows.rs:227,322;threaded.rs:1457,1599) — not speculative generality.engram_scales(helios/src/core/schema.rs:329-341) andengram_encoding_has_scales(:316-327) are genuine centralization: without them this invariant is open-coded inschema,runtime_core::engram,heliopause::export::core(×2) andexport::binding. Finding 1 is only about the one site that didn't get converted.
Refactors that net-simplify and should not be re-litigated:
heliopause/src/embedding_tables.rs:41-62deletes the[planes.remove(0), planes.remove(0)]dance and pairs plane + buffer name once, asOption<(PlaneSource, String)>.helios/src/engram/prepared.rs:143-160, 177-215replaces pairedplanes.remove(0)calls withload_plane/dup_planeclosures;descriptors()(:215-224) matches the Pythonexpected = sum(len(table["planes"]) ...)atignition/preparation/rank_group.py:47.helios/src/engram/reader.rs:1350-1365nests resident-scale loading underif let Some(scale_plane), removing an index-out-of-range assumption rather than adding a branch.helios/src/runtime_core/selection.rs:52-79splittingvalidate_embedding_resident_scalesout ofembedding_resident_scalesis a behaviour the PR documents (docs/cli-design.md,--embedding-table-resident-scaleserrors when no table has a scale plane), not a speculative knob — it removes the silent no-op.ignition/preparation/rank_group.py:44-61extracting_receive_embedding_tablesis net-zero in lines and exists sotests/preparation/test_embedding_table_handoff.py:11can import it; behaviour (descriptors closed infinally,control.send("embedding_tables_ready")last) is unchanged.heliopause/src/export/binding.rs:652-657's 3-lineif parts.is_null() { continue; }is declared in the PR description as matchingweight_reuse.rs; it is the smallest correct form, not a fallback layer.heliopause/src/export/core.rs:3017-3035verify_publishedis a test-only helper doing the full sign+verify round trip; ~18 lines that replace repeated setup in the new tests.
Conventions checked, not violated: no env-var knob, capability flag or model allowlist added; partition: Option<usize> (helios/src/engram.rs:180) is geometry, not model identity; proto additions are appended as = 3 (helios/proto/core.proto, helios/proto/runtime_core.proto (not opened)); ignition/preparation/runtime_core_pb2.py (not opened) is a pure +109/−109 regeneration with no hand edits; the four doc files were updated in the same change set as the behaviour; new tests are behavioural (buffers, decode errors, publish round-trips, descriptor counts), not source-text checks.
Open questions / not found
- Is there a real pre-existing core with
encodingunset? Finding 3 is written as a subtraction (delete the shim), but the two readings are mutually exclusive: if such cores exist, the shim is a missing migration and the correct fix is to reject-and-migrate explicitly, not to silently reinterpret0as FP8. The repository does not answer this; the PR's own comment points at fixtures only. - Where should the shared plane walker live?
helios_core::core::schemais the natural host (heliopause already callsengram_scalesfrom there), butspanscurrently carries runtime-specific concerns (world,selectedrank) athelios/src/runtime_core/engram.rs:19-26. I did not find an existing abstraction that already does this walk correctly across both crates. weight_reuse.rsunexamined in depth. The dossier notesheliopause/src/export/weight_reuse.rs:389-402(engram_uses) is a further copy of the walk that this PR did not touch; I read the citation but not the surrounding logic, so I treat it as context for finding 4 rather than a separate demand on this PR.- Line-count claims: "~30 removable lines" covers findings 1-3 only (5 + 7 + ~4-6 plus fixture repair); finding 4 is structural and roughly line-neutral, and the numbers are estimates from the quoted hunks, not a patch I applied.