Subtraction, Simplicity & Conventions — PR #664 (head fd6dad6eb6d0c72f480f66dcd7a7b0f8223366ba)
Key findings
Verdict: the diff is already lean and idiomatic. The central shape change — Planes { weights: Plane, scales: Option<Plane> } with iter()/iter_mut() chained over the Option (helios/src/engram/reader.rs:60-102) — is exactly the right collapse of a fixed [Plane; 2], and #[cfg(test)] single()/two() constructors kept ~15 fixture call sites unchanged. Docs edits are consistent, both enum variants are appended (= 3), the proto is regenerated, and no new config knob, module, or flag was introduced (the --embedding-table-resident-scales guard reuses an existing option). I found no structural AGENTS.md (not opened) violation. What follows is four worthwhile subtractions (one high, three medium) and three optional minors; nothing here is a blocker, and none of it is a correctness bug restated.
S1 (HIGH) — schema.rs decides the encoding three times per table
validate_engram already knows whether the table has a scale plane at line 367, then re-derives it twice more downstream, and derives "is BF16" a third way by raw tag comparison.
helios/src/core/schema.rs:367 (verbatim):
for table in &engram.tables {
let has_scales = engram_encoding_has_scales(table.encoding)?;
helios/src/core/schema.rs:330-341 (verbatim):
pub fn engram_scales<'a, T>(encoding: i32, scales: &'a Option<T>) -> Result<Option<&'a T>> {
if engram_encoding_has_scales(encoding)? {
scales
.as_ref()
.ok_or_else(|| invalid("engram table has no scales plane"))
.map(Some)
} else if scales.is_some() {
Err(invalid("single-plane engram table cannot carry scales plane"))
} else {
Ok(None)
}
}
helios/src/core/schema.rs:428-436 (verbatim):
let bf16_row_bytes = if table.encoding == wire::engram_table::Encoding::Bf16 as i32 {
Some(
u64::from(table.embedding_width)
.checked_mul(2)
.ok_or_else(|| invalid("BF16 engram row width overflow"))?,
)
} else {
None
};
and then again at :452 and :496 (engram_scales(table.encoding, &table.scales) / &shard.scales).
Replace with: make engram_scales take the already-known predicate — fn engram_scales<'a, T>(has_scales: bool, scales: &'a Option<T>) — and compute bf16_row_bytes from the same bool: twice-pinned plane sizes at :443-451 and :487-495 do not change.
This is safe because :318-327 already rejects Unspecified and unknown encodings before line 367, so within validate_engram !has_scales is "encoding == Bf16". Net: one enum re-parse and one raw tag comparison per table deleted, and the encoding stops being able to disagree with itself.
Same pattern one module over (same fix applies): helios/src/runtime_core/engram.rs:35 computes let has_scales = crate::core::schema::engram_encoding_has_scales(encoding)?; and then re-passes encoding into engram_scales at :45 and :59. helios/src/core/reader.rs:231 shows the cleaner counter-example already in the PR — it computes has_scales once and uses the bool at :234 and :241 rather than calling engram_scales again.
S2 (HIGH) — has_tables is a dead parameter once has_scale_planes exists
helios/src/runtime_core/selection.rs:52-70 (verbatim):
pub(super) fn validate_embedding_resident_scales(
&self,
has_tables: bool,
has_scale_planes: bool,
) -> Result<()> {
if self.embedding_table_resident_scales == Some(true) {
if !has_tables {
return Err(invalid(
"resident embedding scales require an embedding table catalog",
));
}
if !has_scale_planes {
return Err(invalid(
"resident embedding scales require an embedding table with a scale plane",
));
}
}
Ok(())
}
The only production caller is helios/src/runtime_core/model.rs:477-481 (verbatim):
let has_scale_planes = engram
.iter()
.flat_map(|(index, _)| &index.tables)
.any(|table| table.planes.scales.is_some());
options.validate_embedding_resident_scales(!engram.is_empty(), has_scale_planes)?;
has_scale_planes == true implies !engram.is_empty(), so the !has_tables arm is unreachable — the first error message can never fire in production. Remove the has_tables parameter and its arm; the surviving message ("require an embedding table with a scale plane") already states the stronger condition. The table-level test at :1049-1056 keeps compiling with one argument, and its first two assertions (false, false / true, false → is_ok() == override != Some(true)) still hold unchanged. This is a knob introduced by the PR that only its own test exercises.
S3 (MEDIUM) — four overlapping presence checks for one optional plane
heliopause/src/embedding_tables.rs:41-62 (verbatim):
if planes.is_empty() || planes.len() > 2 {
return Err(PyValueError::new_err(
"embedding table requires weight plane and optional scale plane",
));
}
let weights_plane = planes.remove(0);
let scales_plane = (!planes.is_empty()).then(|| planes.remove(0));
let scales_name: Option<String> = match table.get_item("scales") {
Ok(item) if item.is_none() => None,
Ok(item) => Some(item.extract()?),
Err(error) if error.is_instance_of::<PyKeyError>(table.py (not opened)()) => None,
Err(error) => return Err(error),
};
let scales = match (scales_plane, scales_name) {
(Some(plane), Some(name)) => Some((plane, name)),
(None, None) => None,
_ => {
return Err(PyValueError::new_err(
"embedding table scale plane and scale buffer binding must both be present or both absent",
));
}
};
The target type TableSource.scales: Option<(PlaneSource, String)> (helios/src/engram/prepared.rs:43) makes the pairing unrepresentable once built, so the three-arm match is only patching the artefact of reading the two halves separately (plane from planes, name from scales).
Replace with: read scales_name first (keep the PyKeyError → None tolerance), then require planes.len() == 1 + usize::from(scales_name.is_some()) with the existing "weight plane and optional scale plane" message, and let scales = scales_name.map(|name| Ok((planes.remove(0), name))).transpose()?;. That is ~22 lines to ~8, one error message instead of two near-identical ones, and one fewer PyValueError path. Behaviour for legitimate inputs is identical: a mismatch becomes a count error rather than a pairing error.
S4 (MEDIUM) — five hand-copies of "weights plane + optional scales plane"
The same shape appears twice in the role builder, twice in the payload locator, and twice in core_engram's job planner. heliopause/src/export/core.rs:99-111 (verbatim, shared case):
result.push(Role {
kind: 4,
owner: None,
span: table
.weights
.clone()
.ok_or_else(|| invalid("embedding table lacks payload plane"))?,
});
if let Some(scales) =
helios_core::core::schema::engram_scales(table.encoding, &table.scales)?
{
result.push(Role { kind: 4, owner: None, span: scales.clone() });
}
Repeats at :122-138 (sharded case), :411-419 (locate shared), :426-436 (locate shard), and :1538-1547 / :1579-1592 (job planning). helios_core::core::schema::engram_scales is called six times in this one file: :108, :131, :416, :431, :1538, :1580.
Replace with one private helper in this module, e.g.
fn planes<'a>(encoding: i32, weights: Option<&'a Span>, scales: &'a Option<Span>) -> Result<Vec<&'a Span>> (interpreted through engram_scales, or through the has_scales bool if S1 lands), then have each of the five sites iterate the returned slice pushing Role { kind: 4, owner, span } / calling locate. Plane count is variable only because of this PR, so now is the moment to have one place that knows the rule; today a change to the plane contract needs five coordinated edits inside one file.
Minor (optional, not blocking)
helios/src/engram.rs:195-201— the method is literally==:
pub(crate) fn shares_delivery_with(&self, other: &Self) -> bool {
self == other
}
Its doc duplicates the doc already on the field at :179 (/// Owning partition rank (None for shared tables); keeps partitioned delivery groups distinct.). It is used once in production (helios/src/runtime_core/model.rs:460) and once in a test. Keeping the named method is defensible (it documents intent at the call site), but two doc comments for one equality rule is one too many — keep either the field comment or the method doc, not both.
helios/src/engram/prepared.rs:161-166and:270—Tablecarries the scale plane twice (planes.scalesandscales: Option<String>) and the halves are rejoined with.zip()/if let (Some, Some), which silently drops the plane on mismatch. Build both inindex()from the singleOption<(PlaneSource, String)>onTableSourceso they cannot disagree. (Cheap insurance, not a reported bug.)Planes::iter()/iter_mut()(helios/src/engram/reader.rs:95-101) are implemented independently oftotal_nbytes/row_bytes, which could be.iter()-based one-liners; at two call sites each this is not worth churn — noted only so it is not re-raised later.
What is right and should not be re-litigated on this lens
Planescollapse with chainedOptioniteration (helios/src/engram/reader.rs:60-102) — a[Plane; 2]with a sentinel empty scale plane would have been the plausible-but-worse alternative; this PR picked the right one.#[cfg(test)] single()/two()constructors: keeps the large fixture surface inhelios/src/runtime_core/engram.rs/enginetests from churning.- No speculative generality: BF16 and IDENTITY are not feature-flagged, not model-allowlisted, and add no new captured-graph op family — the PR description's claim matches the code.
engram_scalescentralization itself (helios/src/core/schema.rs:329-341) is a good subtraction of four previously-local validity checks; S1 above only asks that its input be the bool that is already computed, not that it be removed.
Open questions / what I could not verify
- I did not open
AGENTS.md(not opened) myself in this run; the "no structural convention violation" conclusion rests on the observable diff facts (appended enum tags, regenerated proto, no new module/flag knob) rather than on a line-by-line reading of the charter's conventions section. If another lens has a specificAGENTS.md(not opened) rule in hand (e.g. on new-option naming), that should take precedence. - S1's simplification presumes
engram_scaleshas no other caller that needsencoding; the six sites inheliopause/src/export/core.rsplushelios/src/runtime_core/engram.rs:45,59andhelios/src/core/schema.rs:452,496all already have (or can trivially obtain) ahas_scalesbool, butexport/core.rsconsumes the function across a crate boundary — S1 and S4 should land together or S1 becomes an API churn for no net line saving. - I did not run the test suite, so the claim that removing
has_tablesleaves the tests green is a reading ofhelios/src/runtime_core/selection.rs:1049-1056, not an execution.