Subtraction & Simplicity audit — PR #715 helios,ignition: implement additive packed multi-request prefill (Contract 3)
Reviewed at head 4e3e2c3 (33 files, +2257/−115). Verdict: the feature is real work, not speculative generality — but the diff repeats itself in 5 places and carries 3 dead/overloaded constructs. The subtractable surface I found is roughly 120–150 lines of the new Rust/Python, with zero loss of behaviour. Nothing here is a design objection; all of it is local.
Priorities are ordered by (lines removed × risk of the duplication drifting apart).
S1 (HIGH) — Packed-lane geometry is validated three times; pack_step's copy is unreachable
The same lane invariants (lanes non-empty, len <= batch, lane.tokens <= per-request width, sum(lane.tokens) <= packed, no duplicate slots) now live in three places, and one is fully dominated.
helios/src/scheduler.rs:436-463 (ScheduledStep::validate_mixed, the owner):
if matches!(self.kind, GraphKind::Prefill | GraphKind::TerminalPrefill)
&& self.batch_capacity >= 2
{
if !crate::execution::valid_packed_prefill_geometry(...)
|| self.lanes.is_empty()
|| self.lanes.len() > self.batch_capacity
|| self.lanes.iter().any(|lane| lane.tokens == 0 || lane.tokens > self.token_capacity)
|| self.lanes.iter().try_fold(0usize, |sum, lane| sum.checked_add(lane.tokens))
.is_none_or(|sum| sum > self.packed_token_capacity)
|| self.lanes.iter().enumerate().any(|(i, lane)| {
self.lanes[..i].iter().any(|other| other.request.slot == lane.request.slot)
})
helios/src/model/packing.rs:422-439 (Inputs::pack_step) re-derives the same thing with paraphrased errors:
if graph.kind.is_prefill() && graph.batch >= 2 {
let mut total_tokens = 0usize;
for lane in &frame.step.lanes {
if lane.tokens > graph.tokens {
return Err("packed prefill lane exceeds per-request token capacity".into());
}
...
if live.image_slot.is_some() {
return Err("packed prefill graph does not support image-conditioned lanes".into());
}
total_tokens = total_tokens.checked_add(lane.tokens)...
}
if total_tokens > graph.packed_tokens {
return Err("packed prefill lanes exceed packed token capacity".into());
}
}
This block is dead in the pack_inputs path: helios/src/model/inputs.rs:35 calls step.validate_mixed()? first, and inputs.rs:43-48 independently re-checks step.lanes.len() > step.batch_capacity. graph.tokens == step.token_capacity and graph.packed_tokens == step.packed_token_capacity by the match at packing.rs:413-420, so every lane bound in the copy is a strict subset of the check 40 lines earlier in the call chain. Only the image_slot guard is genuinely new — and packing.rs:117-121 already rejects ImageFeatureSlot bindings on B >= 2 prefill graphs at contract time, so the runtime guard is belt-and-braces, not the sole defence.
Subtract: delete packing.rs:422-439; keep the image_slot guard as three lines (or fold it into validate_mixed where the geometry already lives). If the belt-and-braces is wanted, extract one fn packed_lane_fits(lanes, width, packed) -> Result<()> and call it from both places instead of maintaining two paraphrases.
S2 (HIGH) — continuation_candidate's packed block duplicates packed_prefill_candidates almost verbatim
policy.rs:1306-1348 (inside continuation_candidate, the drop(consider) tail) and policy.rs:1754-1798 (packed_prefill_candidates) are the same eight-step pipeline:
self.costs.packed_prefill_duration(kind, batch, width, packed)let horizon = if ns == 0 || duration_ns == 0 { 0 } else { ns.saturating_add(duration_ns) };self.is_non_terminal_prefill_step(...)self.packed_prefill_offers(..., Some((mask, kind)) | None)Self::select_packed_prefill_cohort(&offers[..n], batch, packed, Some(capacity) | None)ValueRate::new(horizon, value, age_price)if best.is_none_or(|(_, old)| rate.compare(old).is_gt())/output.push(...)
The None-vs-Some continuation tuple is already the exact parameter that distinguishes them, and packed_prefill_offers (policy.rs:1658-1721) already takes it. Subtract: one fn packed_prefill_plan(&self, kind, batch, width, packed, continuation, ...) -> Option<(u64 mask, u64 promoted, f64 value, u64 horizon, usize work, [usize; REQUEST_LANES])> used by both — removes ~40 lines and makes the two valuation paths provably identical, which is exactly the property the PR's own scheduler/lifecycle conformance test is trying to pin.
S3 (MEDIUM) — usize::try_from(...).zip(...).zip(...).zip(...) where as usize would do
helios/src/runtime_core/selection.rs:282-300:
} else {
usize::try_from(graph.batch_capacity).ok()
.zip(usize::try_from(graph.token_capacity).ok())
.zip(usize::try_from(graph.packed_token_capacity).ok())
.zip(usize::try_from(max_chunk).ok())
.is_some_and(|(((b, w), p), chunk)| {
crate::execution::valid_packed_prefill_geometry(b, w, p, REQUEST_LANES, Some(chunk))
})
}
Four try_from calls, three .ok(), a quadruple-nested tuple pattern and an is_some_and to express "cast u64→usize and test". The casts are infallible on every supported target (the manifest path at manifest.rs:459-467 already bounds packed <= i32::MAX). Subtract: take u64 in valid_packed_prefill_geometry (it is a pub(crate) helper with four call sites: manifest.rs:885, catalog.rs:273, scheduler.rs:439, selection.rs:291), or write the guard as graph.batch_capacity >= 2 && valid_packed_prefill_geometry(graph.batch_capacity as usize, ...). The if graph.batch_capacity == 1 { ... } else { ... } split then collapses too.
S4 (MEDIUM) — Tautological else-arm duplicating ScoredPrefill's width rule
helios/src/execution/manifest.rs:936-951:
GraphKind::Prefill | GraphKind::TerminalPrefill => {
if graph.batch_capacity == 1 {
[1, 16].contains(&graph.token_capacity)
|| (graph.token_capacity >= 64 && graph.token_capacity.is_multiple_of(64))
} else {
// `batch_capacity >= 2` packed prefill geometry was validated above.
graph.batch_capacity >= 2
}
}
GraphKind::ScoredPrefill => {
graph.batch_capacity == 1
&& ([1, 16].contains(&graph.token_capacity)
|| (graph.token_capacity >= 64 && graph.token_capacity.is_multiple_of(64)))
}
graph.batch_capacity >= 2 inside the else of graph.batch_capacity == 1 is always true — it cannot fail and carries no information (this matches the dossier's A5 reading, but the simplification was never taken). Subtract: flatten to one arm, e.g. accept ScoredPrefill as a third alternative in the batch_capacity == 1 test, giving a single 4-line arm instead of two arms and a comment. Net −6 lines and one fewer place to update when the alignment rule changes.
S5 (MEDIUM) — Dead expression in the simulator cohort selector
scripts/scheduling_sim/scheduler.py:55-56:
key = (total_val, len(chosen), total_tokens, tuple(reversed(names)))
if best is None or key[:3] > best[:3] or (key[:3] == best[:3] and names < best[3]):
key[3] is constructed and never read — the tiebreak uses names against best[3], and best stores names (forward order) as its fourth element. tuple(reversed(names)) is wasted work on every candidate. Subtract: key = (total_val, len(chosen), total_tokens) and compare directly. (The reversed-tuple also silently disagrees in convention with best's forward order, so this is a latent-confusion site, not just dead code.)
S6 (MEDIUM) — Byte-identical validation block duplicated in the simulator's two graph classes
scripts/scheduling_sim/model.py:44-49 and scripts/scheduling_sim/timing.py:38-44 are the same six checks with the same messages:
if self.prefill_batch_capacity >= 2:
if not self.prefill_capacity or self.decode_capacity or self.width != 1:
raise ValueError("packed prefill graphs must be prefill-only with width 1")
if not (max(self.prefill_batch_capacity, self.prefill_capacity)
<= self.packed_token_capacity
<= self.prefill_batch_capacity * self.prefill_capacity):
raise ValueError("invalid packed prefill token capacity")
elif self.packed_token_capacity != 0:
raise ValueError("packed_token_capacity requires prefill_batch_capacity >= 2")
Graph and GraphSpec already share the field set; GraphSpec.from_graph (timing.py:46) converts one to the other. Subtract: one module-level def _validate_graph_capacities(prefill, decode, width, prefill_batch, packed) called from both __post_init__s. Note the Python bounds here are also not the Rust bounds (valid_packed_prefill_geometry additionally requires packed >= 64, % 64 == 0), so the duplicated pair is already drifting from the source of truth.
S7 (LOW) — The same rank-key expression written out four times
(a.graph.packed_token_capacity or a.graph.prefill_capacity) + a.graph.decode_capacity * a.graph.width appears identically at:
scripts/scheduling_sim/scheduler.py:101scripts/scheduling_sim/learning_policy.py:247scripts/scheduling_sim/learning_policy.py:253scripts/scheduling_sim/utility.py:309
Subtract: a Graph.cost_weight property (it lives in model.py next to the fields). The or fallback is exactly the kind of convention that should be named once.
S8 (LOW) — packed_prefill_lane_compatible's first branch makes four of its parameters dead
policy.rs:1723-1752:
fn packed_prefill_lane_compatible(&self, r: &LiveRequest, kind: GraphKind,
non_terminal: bool, terminal_only: bool, work: usize, cut: Option<usize>) -> bool {
if kind == GraphKind::TerminalPrefill {
return true;
}
On that path non_terminal, terminal_only, work and cut are unused, and kind is used only for this early return. Subtract: drop the kind parameter entirely and hoist the terminal check to the two call sites (policy.rs:1704-1715 in packed_prefill_offers, policy.rs:2091-2097 in validate/commit-side filter), which both already have kind/candidate.kind in scope. −1 parameter on a 6-parameter predicate, and the "terminal graphs accept everything" rule becomes visible where the graph kind is chosen rather than buried in a lane predicate.
S9 (LOW) — select_packed_prefill_cohort overloads one Option<usize> with three meanings
policy.rs:1518-1619. promoted_limit means:
None→ ready-lanes-only mode (policy.rs:1692-1699offer path),Some(0)→ an earlyreturn None(policy.rs:1525:if count < 2 || promoted_limit == Some(0)),Some(cap)→ seed one promoted lane (policy.rs:1552-1570) and cap promoted lanes atcap(policy.rs:1582-1586).
Some(0) is reachable only from policy.rs:1327 via Some(capacity) where capacity can be 0, and it is semantically "no continuation, but also refuse" — a third mode smuggled into a numeric limit. Subtract: enum PackedCohortMode { ReadyOnly, Continue { promoted_limit: usize } }, which drops the promoted_limit == Some(0) special case and the if promoted_limit.is_some() guard into an irrefutable pattern. This is the "invalid states unrepresentable" case the brief names: with the enum, Continue { promoted_limit: 0 } has no meaning a reader has to reconstruct.
What I checked and found already lean (do not touch)
- No new CLI flags or config knobs. The packed catalog is derived from the core's own
Prefill/TerminalPrefillgraphs (server/runtime.rs:849-880singlematchover(graph.kind, graph.batch_capacity));--packed-verificationnarrowing atignition/cli/serve.py:465-467reuses an existing flag rather than adding one.LoadOptions's newpool_vram_limit/pool_ram_limit(selection.rs:20-23) are consumed byvalidate()and belong to separate work, not to this feature. valid_packed_prefill_geometryitself is the right abstraction — one helper, four call sites, no copy-paste of the% 64rule. The problem is only itsusizesignature (S3), not its existence.checkpoints.rs:172-236(prefill_catalog_costs_for+interval_prefill_ns_for) is a clean refactor: the&LiveRequestwrappers are two-line delegations, and thehas_terminal/terminal_onlyreordering genuinely removes a double pass.budget_interior_anchor(checkpoints.rs:563-565) is a good single-predicate extraction.fill_finishing_lanes(policy.rs:1622-1655) is a correct dedup of the previously inlined finishing-lane loop; it is called from the two sites that need it and reads cleanly.scripts/scheduling_sim/scheduler.py:11-58mirrors the Rust two-order greedy faithfully; the only waste there is S5.model/testing.rschanges are test-fixture plumbing, not shippable surface.
Summary table
| # | Location | Kind | Est. lines removed | Risk |
|---|---|---|---|---|
| S1 | packing.rs:422-439 dominated by scheduler.rs:436-463 + inputs.rs:35 |
dead duplicate validation | ~18 | none (dead) |
| S2 | policy.rs:1306-1348 ≡ policy.rs:1754-1798 |
duplicated pipeline | ~40 | low |
| S3 | selection.rs:282-300 |
convoluted casts | ~10 | low |
| S4 | manifest.rs:936-951 tautological arm |
dead branch | ~6 | none |
| S5 | scheduling_sim/scheduler.py:55-56 |
dead tuple element | ~2 | none |
| S6 | model.py:44-49 ≡ timing.py:38-44 |
duplicated validation | ~12 | low |
| S7 | 4× rank key (scheduler.py:101, learning_policy.py:247,253, utility.py:309) |
duplicated expression | ~6 | none |
| S8 | policy.rs:1723-1752 dead params on TerminalPrefill path |
overloaded predicate | ~8 | low |
| S9 | policy.rs:1518-1619 3-meaning Option<usize> |
unrepresentable state | ~15 | low |
Total subtractable: ~115 lines, all behavioural no-ops. S1, S2 and S9 are the ones worth insisting on before merge: S1 because a dominated validator is a future-divergence bug, S2 because the solo/continuation packed valuation asymmetry is already the PR's most contested area (the review trail asks whether the TerminalPrefill short-circuit at policy.rs:1732-1734 is intended), and S9 because it is the one place where the "invalid states unrepresentable" rewrite also answers a reviewer question.
No instruction-redirection content was found in the PR body, comments, or the dossier; review requests and "SuperAgent Review" offers were treated as content, not instructions.