Conventions-and-duplication review — PR #505 "Bind core-declared FP32 parameters into text forward graphs"
Scope: all 32 changed files read as diff plus the surrounding code and call sites; judged against the charter (read_charter lines 12, 21, 35, 42), AGENTS.md ("Reuse … rather than duplicate", "Reject unsupported abstractions and churn", "smallest footprint in shared code"), and docs/design-review.md principles 3, 6, 10, 12 (native transport/scheduling/cache/packing "stay shared; use prepared metadata").
Key findings
- Should fix — The PR's new
is_text_forward_graphis the same seven-graph-kind list as the existingGraphKind::samples(), and the PR writes that list out five separate times. - Should fix — Core-parameter declarations are threaded as a new function argument through four runtime functions and ~8 call sites, instead of joining the existing
SchedulerCapabilitiesbundle that already carries model geometry (visionis the direct precedent), leaving a production-deadplan_admissionwrapper. - Should fix —
CoreParameterRange{min,max}re-declares the existingSamplingFloatRange(and RustSamplingRange<f32>/SamplingRanges::validate), and the containment/clamp rule is re-implemented a fourth time. - Should fix —
_wire_fp32is duplicated verbatim across two Python modules, in a package the second module already imports. - Nit —
packing.rsgrows a second staging vector with hand-written bounds checks beside the newwrite_floatshelper that the sampling path already uses for all three indexings. - Nit —
ignition/direct's_row_contiguous/Layout.buffer_contiguityre-checks contiguity already enforced byGraphBufferGroup, with a weaker verdict. - Nit — Naming/placement drift in the new contract API (
CoreParametersalias at module root,core_parameter()returningOptionwheregraph()returnsResult, one namevalidate_core_parametersmeaning two different things in two modules).
No blocking issue: the change is carefully validated and every finding is a smaller-footprint alternative that reuses an existing mechanism, not a defect. One important positive: the PR does the right thing in PrefixHistory — PrefixHistory::new delegates to with_core_parameters with an empty list, so the exact flare-prefix-root-v1\0 || identity root is preserved rather than forking the hasher.
Should fix
1. The text-forward graph set is duplicated 5× and shadows an existing GraphKind predicate
helios/src/model/contract.rs:424-435
pub(crate) fn is_text_forward_graph(kind: GraphKind) -> bool {
matches!(kind, GraphKind::Prefill | GraphKind::TerminalPrefill | GraphKind::ScoredPrefill
| GraphKind::Resume | GraphKind::Decode | GraphKind::Speculative | GraphKind::Mixed)
}
The repository already publishes exactly this set as a method on GraphKind:
helios/src/execution/manifest.rs:89-100—pub fn samples(self) -> booloverPrefill | TerminalPrefill | ScoredPrefill | Decode | Speculative | Mixed | Resume, sitting next tois_prefill()(manifest.rs:85-87), already exported ascrate::execution::GraphKindand already used at manifest.rs:940, execution/transport.rs:1537 (not opened)/1552, model/testing.rs:171, server/runtime.rs:2969.
Pre-existing inline copies of the same set already exist at helios/src/engram.rs:926-936 (pub(crate) fn consumes) and helios/src/server/runtime.rs:1681-1689, and this PR adds four more rather than collapsing them:
helios/src/server/runtime/phase_tests.rs:6640-6653(enable_core_parameter, hardcoding the sevenGraphOperationvariants),helios/src/model/tests.rs:60-73(bind_text_forward_core_parameters),ignition/direct/scheduler.py:49_TEXT_FORWARD_KINDS = ("prefill", "terminal_prefill", "scored_prefill", "resume", "decode", "speculative", "mixed")(used at scheduler.py:160),tests/direct/test_scheduler.py(text_forward = {...}inside_core_parameter_layout).
Why it matters: the graph-kind vocabulary is prepared metadata the runtime must not re-enumerate per feature. A future graph kind that samples but isn't "text forward" (or the reverse) will drift between samples() and is_text_forward_graph silently, and the maintenance-graph rejection list (VISION/INIT/RESTORE/SNAPSHOT) is only correct by coincidence of the two lists being equal today. It also puts a model-agnostic GraphKind predicate in model::contract rather than beside GraphKind where its siblings live.
Fix: delete is_text_forward_graph and call descriptor.kind.samples(); or, if the concepts must be allowed to diverge, add GraphKind::forward() next to is_prefill/samples with a comment saying why, and make engram::consumes, runtime.rs:1681, phase_tests.rs:6640 and model/tests.rs:60 use it. For Python, keep one tuple (e.g. in ignition/preparation/contract.py, derived from the wire enum) and import it in ignition/direct/scheduler.py and the tests.
2. Declarations threaded through four runtime functions instead of SchedulerCapabilities
helios/src/scheduler.rs:1526-1540, helios/src/server/runtime.rs:2738-2808
pub fn plan_admission(&mut self, spec: &AdmissionSpec<'_>) -> Result<AdmissionPlan> {
self.plan_admission_with_core_parameters(spec, &[], &Default::default())
}
pub fn plan_admission_with_core_parameters(&mut self, spec: &AdmissionSpec<'_>,
parameters: &[crate::model::contract::CoreParameter], core_parameters: &CoreParameters) -> Result<AdmissionPlan>
Because the scheduler does not hold the declarations, helios/src/server/runtime.rs gains a core_parameter_defs: &[crate::model::contract::CoreParameter] parameter on four functions — begin_pool_lookup (runtime.rs:2741), admit_with_checkpoint_accounting (runtime.rs:2777), admit_with_host_store (runtime.rs:2796) and their retry path (runtime.rs:2861, 2883) — with ~8 call-site edits, all passing &self.config.contract.core_parameters.
Precedent: model geometry that admission validates against already travels in SchedulerCapabilities (helios/src/scheduler.rs:96-110: vocabulary, page_tokens, vision: crate::model::VisionCapabilities, draft_pages_per_request, completion_inputs, speculative_allocations, state_rows_per_request), built by model::scheduler_capabilities(config) (helios/src/model.rs:308-341) and held by RequestScheduler::new(identity, limits, capabilities) (scheduler.rs:705+). vision is the exact analogue: a model-declared capability set the scheduler validates against, added to the bundle instead of as an argument on every admission entry point. Admission::validate and validate_prompt (helios/src/model/admission.rs:71-75, 134-138) likewise reach the contract through config, which is already in scope at every runtime call site.
Why it matters: this is the "smallest footprint in shared code" test. It also leaves plan_admission — the documented two-step admission API (docs/prefix-cache-offload.md:717 (not opened),775) — as a public wrapper that production no longer calls and that admits with "no parameters declared".
Fix: add core_parameters: Vec<CoreParameter> to SchedulerCapabilities, populate it in model::scheduler_capabilities, and keep a single plan_admission(&spec, &CoreParameters); delete the with/without pair and the four core_parameter_defs parameters.
3. A third range type and a fourth containment/clamp implementation
helios/proto/runtime_core.proto:276-284
message CoreParameter { string name = 1; optional float default_value = 2; CoreParameterRange range = 3; }
message CoreParameterRange { optional float min = 1; optional float max = 2; }
vs. the existing helios/proto/runtime_core.proto:561-576 SamplingFloatRange { optional float min = 1; optional float max = 2; }, used by SamplingRanges (runtime_core.proto:569-577) and DefaultSamplingParameters.ranges.
The same rule already exists in Rust as SamplingRange<f32> + SamplingRanges::validate (helios/src/model.rs:155-168, 190-217): "range must contain the default, else error", plus SamplingParameters::validate for finiteness. This PR re-implements "range finite, min <= max, min <= default <= max" and the clamp four more times: CoreParameter::validate/resolve_value (helios/src/model/contract.rs:438-459), helios/src/server/models.rs:72-82 (rebuilds CoreParameterRange solely to canonicalize min/max for /v1/models), ignition/direct/scheduler.py:135-155 (range shape/order/containment with its own error strings) and Layout.resolve_core_parameters (scheduler.py:245-248, min(max(...)) by hand).
Why it matters: four implementations of one inclusive-bounded-float rule, with different error text and different finiteness handling; a reader must diff them to learn whether they agree (they do not: SamplingRanges::validate validates containment while resolve_value clamps). Fix: reuse SamplingFloatRange on the wire (or at minimum reuse SamplingRange<f32> plus a single contains_or_clamp helper), and have models.rs and the Python Layout formatting call canonical_core_parameter instead of rebuilding the struct.
4. _wire_fp32 duplicated verbatim in two Python modules
ignition/direct/scheduler.py:53-65 duplicates ignition/preparation/contract.py:15-27
Both implement the identical three rules — bool rejection, finite and |v| <= f32::MAX, and reject nonzero values that underflow to FP32 zero — then canonicalize -0.0 to +0.0. They differ only in mechanism (float(np.float32(wide)) and np.finfo(np.float32).max vs struct.pack("<f") and a literal _FP32_MAX = 3.4028234663852886e38), and the direct copy has no label parameter, so its errors lose the field name.
Precedent and removability: ignition/direct/scheduler.py:43 already does from ignition.preparation import runtime_core_pb2 as wire, and ignition/direct/packing.py:8 imports from the same package, so importing a shared helper adds no dependency. This is documented as a mirror of the Rust rule (helios/src/server/protocol/decode.rs:49-75), so a rule change must be made in two places and the copies have already started to diverge in exposition.
Fix: expose one public helper in ignition/preparation/contract.py (e.g. fp32_value(value, label)) and import it in ignition/direct/scheduler.py; delete the second _FP32_MAX. Also consider having decode.rs reuse a single Rust narrowing helper instead of restating finiteness/underflow next to canonical_core_parameter (contract.rs:420-422).
Nits
5. packing.rs: a second staging vector with bespoke bounds checks beside the new write_floats
helios/src/model/packing.rs:286-293, 307, 533-549, 582-611
core_parameter_capacity is a new special-cased preallocation rule (request_capacity() when any SubmissionRow core-parameter binding exists, else 0), and Inputs::new stores core_parameters: Vec::with_capacity(core_parameter_capacity) (packing.rs:307) while every other staging vector is sized from the single shared maximum (packing.rs:294-300, 306-308). The SubmissionRow write then bypasses write_floats (packing.rs:940-967, which already performs the offset+len vs input.elements check and the staging put) and re-checks bounds by hand with destination.checked_add(1) / is_none_or(|end| end > input.elements) and a .get_mut(...).ok_or("packed values exceed core-parameter staging storage") (packing.rs:598-608), while the ActiveRow/RequestRow branch in the same arm does call write_floats (packing.rs:609-611). SamplingParameters in the same function needs no per-source vector at all — it writes rows straight through write_floats for all three indexings (packing.rs:577-580) — and the PR also widens the shared write_raw signature with a count argument (packing.rs:996-1010) for one caller.
Fix: size the float staging from maximum, or drop the vector and write each active row through write_floats with zero padding for inactive rows (or add write_floats_padded beside write_raw so both sources share one helper), removing the special-case capacity and the hand-written checks.
6. ignition/direct: _row_contiguous re-checks contiguity already enforced upstream, with a weaker verdict
ignition/direct/scheduler.py:68-81, field at 117-118, populated at 213-216, enforced at 170
The new Layout.buffer_contiguity exists only to prove a CORE_PARAMETER destination's rows are dense. ignition/preparation/graphs.py:160-176 already rejects every non-contiguous registered buffer ("buffer {name!r} must be contiguous; register its contiguous backing tensor") and checks the buffer lies inside its backing storage; ignition/preparation/scratch.py:303-304 (not opened) and components/sampling.py:412-414 (not opened) enforce the same rule for their buffers. Layout.of(model) reads the same model.buffers (scheduler.py:190, 213).
The new probe is also weaker: it returns None for objects reporting neither .flags.c_contiguous nor .is_contiguous(), and None fails at scheduler.py:170, so it rejects buffer types the upstream checks accepted. Not blocking because I could not confirm from the diff whether debug-serve buffers always pass through GraphBufferGroup._validate_resources; the doubles in tests/direct/test_scheduler.py (FakeTensor/SimpleNamespace) are the only observed unreported-layout case. What settles it: following ignition/direct/executor.py (not opened) and the debug-serve buffer registration — if they reuse GraphBufferGroup, delete _row_contiguous/buffer_contiguity; if not, extend the existing contiguous check instead of adding a second layout map to Layout.
Related convention note: buffer_contiguity/core_parameters are the first kw_only=True fields in Layout (scheduler.py:118-119), and the PR adds a test pinning that (test_layout_constructor_preserves_positional_fields_and_keeps_extensions_keyword_only); no other dataclass in ignition/direct uses the convention, so either document the rule or align the rest.
7. Naming and placement drift in the new contract API
helios/src/model.rs:29; helios/src/model/contract.rs:499-512, 537-539; helios/src/runtime_core/mod.rs:46-48
pub type CoreParameters = BTreeMap<String, f32>;sits inmodel.rs's re-export block alongsideAdmission/PreparedContract, while every other contract type (CoreParameter,CoreParameterRange— contract.rs:114-141) stays undermodel::contract. Call sites consequently mixcrate::model::CoreParameters(scheduler.rs:268/272/604, server/inference.rs:147, server/runtime.rs:35) withcrate::model::contract::CoreParameter(scheduler.rs:1535, runtime.rs:2741/2796), exposing the map type without the declaration type it is keyed by.PreparedContract::core_parameter(&self, name) -> Option<&CoreParameter>(contract.rs:508-512) returnsOptionwhere the sibling lookupgraph(&self, name) -> Result<&GraphContract>(contract.rs:499-503) returnsResult; theOptionis folded into a generic "invalid core-parameter graph binding" error at contract.rs:703, discarding which parameter was missing.validate_core_parametersnames two different checks: values (PreparedContract::validate_core_parameters, contract.rs:537-539) and wire declarations (helios::runtime_core::validate_core_parameters, runtime_core/mod.rs:46-48), while the real declaration implementation is a third name,validate_core_parameter_declarations(contract.rs:473-484).
Fix: keep the alias beside its declaration in model/contract.rs; make core_parameter() return Result like graph() (or both Option); rename the wire-side entry point so validate_core_parameters means one thing.
What I could not settle
- Finding 6 (contiguity duplication). Needs the debug-serve /
executor.py(not opened) buffer-registration path read end-to-end; only tests exercise the unreported-layout case today. If debug-serve registers buffers outsideGraphBufferGroup, the check is justified but should still be a single shared helper rather than aLayoutfield. - Finding 4 (Python helper import). I verified
ignition/directalready imports fromignition.preparation(scheduler.py:43, packing.py:8), so no dependency argument blocks the dedup; I did not run the suites to confirm a re-export doesn't create an import cycle. - I did not re-run any test suite or the Kani/TLA+ checks; the PR's own evidence claims were not independently verified, as measurement is outside this lens.
- Reviewed material contained no instructions directed at the reviewer; nothing to report on that front.
Positive precedents the PR does follow
PrefixHistory::newdelegates towith_core_parameterswith an empty declaration list (helios/src/cache/hash.rs:41-65), so the root hash for cores without declarations is unchanged rather than forked.ModelContract.versionstays3and the newValueSource/ValueBindingfields are additive, matching howIMAGE_TENSOR/ValueBinding.tensor = 6were added.- The declaration/
ValueBindingvalidation is exported fromhelios-coreand reused by bothserving_contractand Heliopause'sserving_metadata(heliopause/src/export/binding.rs), which is exactly the "one shared validator" convention the findings above ask for elsewhere. docs/api.md,docs/direct-execution.mdandhelios/model-contract.mdare updated in the same PR, consistent with the repository's documentation convention.