Review — PR #540, lens: conventions and duplication (head e5a69669)
Key findings
Verdict: should-fix issues only; nothing blocking from this lens.
The review-fix commit e5a69669 closed every finding I recorded at head 14019718. It resolved all five earlier should-fix items — draft_source in the prepared-shape identity, the duplicated wide copy-only cohort loop, the four hand-written draft_source wire ladders, the stale manifest.md/mtp-design/cli-design/scheduling-runtime-design prose, and the doubled padded-batch dominance rule — plus most of the earlier nits (five-way zero-duration pricing collapsed to zero_duration[slot], the magic constants now documented at speculation.rs:14-37, the duplicated 6 explained at speculation.rs:21-25).
What it newly introduced is three small mechanical duplications, all fixable in a few lines, plus four nits. The theme of all three: a rule this PR introduced now exists in more than one place, and in two cases the copies have already diverged.
Should fix
1. The deleted has_mtp existence scan came back inside packed_round_duration
helios/src/scheduler/cost.rs:237-252
pub fn packed_round_duration(&self, batch: usize, width: usize) -> Option<u64> {
let mtp = self.packed_round_duration_for(ProposalSource::Mtp, batch, width);
let copy = self.packed_round_duration_for(ProposalSource::Copy, batch, width);
match (mtp, copy) {
(Some(m), _) if m > 0 => Some(m),
(_, Some(c)) if c > 0 => Some(c),
(Some(0), _) => Some(0),
(None, Some(0)) if !self.packed_round_durations[ProposalSource::Mtp as usize]
.iter().any(|row| row.iter().any(Option::is_some)) => Some(0),
_ => None,
}
}
The commit deleted has_mtp from refresh_packed_durations (cost.rs:204-221 now writes both per-source tables unconditionally, using the min_measured_duration helper at cost.rs:42-48). The combined lookup then reintroduces the same whole-table existence scan, and it answers a different question from its sibling arms: the third arm asks "are MTP shapes at this (batch, width) measured at zero?", while the fourth asks "was any MTP shape at any batch and width ever measured?" The contract the PR documents at docs/scheduling-runtime-design.md:429-433 — "return zero only when covering shapes exist without a positive measurement" — is met only by the (Some(0), _) arm. A copy-only (batch, width) with no measurement therefore yields None on a core that has some unrelated measured MTP shape and Some(0) on a core that has none. Both encode "unmeasured", but through two different rules, and the second is expressed by an O(catalog) scan on a path (policy.rs:785, rounds.rs:588) that runs per candidate shape inside the pricing loop.
Fix: carry the presence signal the table already needs. refresh_packed_durations knows, per (source, batch, width), whether a covering shape exists; write a covered: [[Vec<bool>; 7]; 2] alongside packed_round_durations and express the combined rule as mtp.or(copy) over that, so "covering shapes exist" is stated once and no scan is needed. This matches how the sibling duration table is maintained and removes the last has_mtp-shaped construct from the file.
2. history_proposal bypasses clamp_copy_capacity, which it sits directly above
helios/src/scheduler.rs:1101-1110
pub fn history_proposal(&self, context: &[u32], maximum: usize) -> (Vec<i64>, usize) {
let maximum = maximum.min(self.capabilities.completion_token_capacity - 1).min(speculation::COPY_DRAFT_CAPACITY);
...
}
fn clamp_copy_capacity(&self, maximum: usize) -> usize {
maximum
.min(self.capabilities.completion_token_capacity.saturating_sub(1))
.min(speculation::COPY_DRAFT_CAPACITY)
}
Same expression, two spellings, and they have already diverged: the inline copy uses completion_token_capacity - 1 and panics on a zero capacity, while the helper uses saturating_sub(1). Every other copy path now goes through the helper (scheduler.rs:1169 in request_history_proposal_with_match_len, scheduler.rs:1188 in request_copy_match_stats), so the pre-SAM entry point is the only holder-out — the exact pattern this repository's own convention against duplicated rules calls out (charter: "Be explicit and pin everything"; AGENTS.md:188-193 rejects paths added without a concrete requirement, and a second clamp with different overflow behaviour has no requirement behind it).
Fix: let maximum = self.clamp_copy_capacity(maximum); and delete the inline expression. If saturating_sub is genuinely wrong for the zero-capacity case, fix it once in the helper.
3. "Speculative graphs default to Mtp" restated twice because the helper is pub(super)
helios/src/scheduler/cost.rs:50-59 adds the canonical rule:
pub(super) fn canonical_draft_source(kind: GraphKind, draft_source: Option<ProposalSource>) -> Option<ProposalSource> {
if kind == GraphKind::Speculative { Some(draft_source.unwrap_or(ProposalSource::Mtp)) } else { None }
}
pub(super) makes it unreachable outside helios/src/scheduler/, so the same rule is hand-written twice elsewhere, in the same shape:
helios/src/model/catalog.rs:296-299:graph.draft_source.unwrap_or(speculation::ProposalSource::Mtp) == draft_source.unwrap()helios/src/model/packing.rs:48-51:self.draft_source.unwrap_or(crate::scheduler::speculation::ProposalSource::Mtp) == step.draft_source.unwrap()
Precedent: this is ProposalSource's own default/canonicalization, not a cost-table detail, and scheduler/speculation.rs:46-70 is already where the enum and its conversions live — parse, from_wire and to_wire are all there and all three are now called from outside the scheduler (serving.rs (not opened), python.rs, selection.rs, server/config.rs:188-194 (not opened)). The new rule is the only ProposalSource semantics that did not get that home.
Fix: move it to speculation.rs as ProposalSource::canonical(kind, Option<Self>) -> Option<Self> (or impl From<(GraphKind, Option<ProposalSource>)>), have cost.rs:81, cost.rs:170, cost.rs:292, cost.rs:313, cost.rs:210, catalog.rs:296-299 and packing.rs:48-51 call it, and drop the cost:: copy. That also removes the unwrap() on draft_source in both comparison sites, which is only safe because of a caller-side check two lines above.
Nits
-
Zero-duration pricing re-implements a
lane_value_for_tokensarm inline.helios/src/scheduler/policy.rs:1052-1056(add_candidate) and1258-1266(mixed_candidates) both open-code theGraphKind::Decode | GraphKind::Speculativearm oflane_value_for_tokens(policy.rs:1000-1003) to price one lane at this duration and at zero duration; the two closure shapes differ (optimisticbranch in the mixed case). Alane_values(...) -> (f64, f64)helper next tolane_value_for_tokenswould keep the arm in one place and still satisfy the curve-reuse tests (policy_tests.rs(not opened)mixed_refresh_value_reuses_each_decoding_lanes_forecast,decode_refresh_value_reuses_each_decoding_lanes_forecast). -
max_mtp_draft_tokensstill scans entries after the per-source split.helios/src/scheduler/cost.rs:262-272filtersentriesondraft_source != Some(Copy)to find a maximum, althoughpacked_round_durationsis now per source. A per-source maximum written inrefresh_packed_durations(cost.rs:204-221) would match the new table layout and remove the third scan ofentries. -
The
packed_round_duration_for/packed_round_durationpair is undocumented.helios/src/scheduler/cost.rs:223-235is the only duration accessor taking aProposalSource, andcost.rs:237-252is the combined convenience directly below it; neither has a doc comment, unlike their neighbours (cost.rs:40-41,40-48,110-113,324). The pair now carries real semantics — the four-armmatchwith the per-source fallback rule — which is exactly the "state it once, in prose, next to it" case. -
wide_copy_curveasserts its precondition only in a panic string.helios/src/scheduler/rounds.rs:570-579.expectscopy_calibration, whichscheduler.rs:1843-1850only creates whendecoded_historyis set. The invariant is real (both are set from the same predicate, andenable_history_draftsrefuses after admission,scheduler.rs:1093-1099), but stating it as anOption-returning signature or adebug_assertwith a comment — as the neighbouringresolve_copy_match(scheduler.rs:1112-1149) does with its earlyreturn None— would match the module's style.
Verified conforming this pass
These were checked against the closest precedent and match it; recording them so the review does not get re-litigated.
cost.rs:204-221per-source tables follow the existing[Vec<Option<u64>>; 7]precedent and usemin_measured_duration(cost.rs:42-48) rather than open-coding the minimum.cost.rs:31-38observed_compute_duration_ns/timing_refresh_duration_nsare built on the existingobserved_duration_nsrather than re-deriving the max-positive-interval rule.heliopause/src/export/binding.rs:201-216derives the wire string and rejects unknown and non-speculativeCOPY_DRAFTvalues, matchingPromptEncoder::try_from+invalid("unsupported …")(binding.rs:996-998) as the local idiom; thedraft_sourceProtobuf field keeps a zero default, satisfying AGENTS.md:437-440 (existing cores load without re-export).ignition/preparation/execution.py:102-108now rejectsdraft_source == 2onmixedanddecodealike, matching the Rust check atexecution/manifest.rs:845-850;tests/preparation/test_execution.py(not opened) covers it.scheduler.rs:1196-1199is_copy_only_stepreads the step's own source instead of doing a cost-table lookup, so the source is stated once.model/packing.rs:40-53matches_stepreplaces the two identical inline graph-matching closures, matching the "one predicate" shape ofcatalog::select_shape.rounds.rs:570-583wide_copy_curve/expected_copy_tokensmirrorpowered_curve/expected_speculative_tokens(rounds.rs:564-582) as intended.scheduler.rs:1112-1194resolve_copy_match+CopyMatchback both SAM entry points;decoded_history.rs:162-183keepslookupas a wrapper overlookup_with_match_len, which is the pattern the SAM path now follows.- Docs now match the implementation:
helios/manifest.md:38documentsdraft_source;docs/mtp-design.md:22-73the per-request SAM + shared-ring fallback;docs/cli-design.md:200-207 (not opened),744;docs/scheduling-runtime-design.md:12-15addssam.rs(not opened),:71-90the proposal-source section,:409-433the per-source packed tables;docs/scheduling-theory.md:574-582 (not opened),714-747the retained-credit and two-tier delta. docs/scheduling-runtime-design.md:429-433prose is correct as written — the defect in should-fix 1 is thatcost.rs:244-249does not implement it.
Open questions / what only a test can settle
- Should fix 1 needs a catalog to demonstrate. The code shows the divergent arm exists; only a test with a measured MTP shape at a different batch plus an unmeasured copy-only
(batch, width)shows theNone-vs-Some(0)divergence.unmeasured_mtp_and_measured_copy_coexist_at_identical_shape_and_preserve_packed_durationandcost.rs:574-585exercise the same-shape and same-batch cases, so neither catches it. - Whether
LiveRequest.copy_calibrationcan beNonewherewide_copy_curveruns. Admission setssamandcopy_calibrationfrom the samedecoded_history.is_some()predicate (scheduler.rs:1843-1850) andenable_history_draftsrefuses after any admission, so the panic looks unreachable; a test constructingsam: Somewithcopy_calibration: Nonewould settle whether the two should be oneOption<PerRequestCopyState>. - The PR's live-GPU evidence (padding dominance at
C = 4..16,+12.9%on the 512-token repetitive prompt,+0.25 ms/rdscheduler overhead,PromptSAM::buildtimings) was not re-verified here — no hardware in this review.
Coverage
All 33 changed files were read in context at e5a69669: docs/{cli-design,mtp-design,scheduling-runtime-design,scheduling-theory}.md, helios/manifest.md, heliopause/src/export/binding.rs, heliopause/src/python.rs, helios/src/execution/{manifest.rs,tests.rs (not opened)}, helios/src/model/{catalog.rs,packing.rs,testing.rs (not opened),tests.rs (not opened)}, helios/src/runtime_core/{selection.rs,serving.rs (not opened)}, helios/src/scheduler.rs, helios/src/scheduler/{checkpoints,cost,decoded_history,planning_tests,policy,policy_tests,refresh,rounds,sam,speculation,speculative_lifecycle_tests,tests}.rs, helios/src/server/{metrics/scheduler.rs (not opened),runtime.rs (not opened),runtime/phase_tests.rs (not opened)}, ignition/preparation/execution.py, tests/preparation/test_execution.py (not opened). Callers followed for each behaviour change: server/runtime.rs:2238 (not opened) → catalog::select_shape_with_source; scheduler.rs:1843-1850 → the SAM/CopyCalibration admission gate; rounds.rs:879-936 → request_copy_match_stats and wide_copy_curve; service.rs:109,156 and policy.rs:629,785 → speculative_duration → packed_round_duration; model/packing.rs:397-405 → request_history_proposal. Rules applied: the charter (read_charter; model-agnostic runtime, cross-matrix compatibility), AGENTS.md:43-60 (prose/review), AGENTS.md:180-199 (reject unsupported abstractions and churn; keep one coherent outcome), AGENTS.md:431-460 (core compatibility, one home per setting), and .agents/skills/repo-prose/SKILL.md (not opened).
No blocking issues were found through this lens.