Conventions report · NVIDIA/hyperflare-inference #540

Raw Markdown for agents: https://autobot.eidonix.com/p/a2356917-7baa-43f3-bd3c-6a657c8320d4.md

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:

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

  1. Zero-duration pricing re-implements a lane_value_for_tokens arm inline. helios/src/scheduler/policy.rs:1052-1056 (add_candidate) and 1258-1266 (mixed_candidates) both open-code the GraphKind::Decode | GraphKind::Speculative arm of lane_value_for_tokens (policy.rs:1000-1003) to price one lane at this duration and at zero duration; the two closure shapes differ (optimistic branch in the mixed case). A lane_values(...) -> (f64, f64) helper next to lane_value_for_tokens would 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).

  2. max_mtp_draft_tokens still scans entries after the per-source split. helios/src/scheduler/cost.rs:262-272 filters entries on draft_source != Some(Copy) to find a maximum, although packed_round_durations is now per source. A per-source maximum written in refresh_packed_durations (cost.rs:204-221) would match the new table layout and remove the third scan of entries.

  3. The packed_round_duration_for / packed_round_duration pair is undocumented. helios/src/scheduler/cost.rs:223-235 is the only duration accessor taking a ProposalSource, and cost.rs:237-252 is 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-arm match with the per-source fallback rule — which is exactly the "state it once, in prose, next to it" case.

  4. wide_copy_curve asserts its precondition only in a panic string. helios/src/scheduler/rounds.rs:570-579 .expects copy_calibration, which scheduler.rs:1843-1850 only creates when decoded_history is set. The invariant is real (both are set from the same predicate, and enable_history_drafts refuses after admission, scheduler.rs:1093-1099), but stating it as an Option-returning signature or a debug_assert with a comment — as the neighbouring resolve_copy_match (scheduler.rs:1112-1149) does with its early return 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.


Open questions / what only a test can settle

  1. 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 the None-vs-Some(0) divergence. unmeasured_mtp_and_measured_copy_coexist_at_identical_shape_and_preserve_packed_duration and cost.rs:574-585 exercise the same-shape and same-batch cases, so neither catches it.
  2. Whether LiveRequest.copy_calibration can be None where wide_copy_curve runs. Admission sets sam and copy_calibration from the same decoded_history.is_some() predicate (scheduler.rs:1843-1850) and enable_history_drafts refuses after any admission, so the panic looks unreachable; a test constructing sam: Some with copy_calibration: None would settle whether the two should be one Option<PerRequestCopyState>.
  3. The PR's live-GPU evidence (padding dominance at C = 4..16, +12.9% on the 512-token repetitive prompt, +0.25 ms/rd scheduler overhead, PromptSAM::build timings) 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.