Review — PR #540: helios: cost-refresh recovery, prompt+output SAM copy-drafts, and calibrated wide copy-verify
Reviewed at head e5a69669 on base main f377dc85: 33 files, +4,306 / −310. Nothing in the description, comments or changed docs tried to direct this review; every behavioural claim quoted below was checked against the code at that head. No CI checks are reported on this commit and no GPU path was exercised by the reviewers, so the perf evidence limits are disclosed rather than assumed green.
Key findings
- No blockers. The three previous-round blockers are fixed and re-verified in code: the export path no longer coerces
draft_source(heliopause/src/export/binding.rs:201-216derives and validates), the identical-shape MTP/copy collision is gone (cost::Keycarriesdraft_source,cost.rs:61-83; per-source packed tables,:204-221; testcost.rs:533-586), and the contradictory design prose now matches the implementation (docs/cli-design.md:200-208,docs/mtp-design.md:19-73,docs/scheduling-runtime-design.md:71-90,271-283,409-433,docs/scheduling-theory.md:574-582 (not opened),717-744,helios/manifest.md:38(not opened)). - Commit
1b0db227(funded refresh recovery) is clean and could merge on its own —cost.rs:31-38,refresh.rs:71-99(not opened),cost.rs:324-333, documented atdocs/scheduling-runtime-design.md:465-520. - One real code defect remains, and its fix is a deletion: the combined packed-round lookup (
cost.rs:237-252) prices a copy shape by scanning the whole MTP table, so a graph's cost depends on unrelated graphs and the code contradictsdocs/scheduling-runtime-design.md:429-433. - The PR orphaned two entry points it replaced (
history_proposal,select_shape_with_drafts) and left a test-only call-count instrumentation block (~46 lines). - Evidence: four outcomes still share one combined-stack measurement,
@voipmonitor's live run used the default--no-history-drafts, and no run loaded an exported core carryingdraft_source = 2.
Blockers
None.
Should Fix
S1. Delete the combined packed-round lookup — a copy shape's cost must not depend on unrelated MTP shapes
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,
}
}
This commit removed the has_mtp existence scan from refresh_packed_durations (:204-221 now writes both per-source tables unconditionally via min_measured_duration) and reintroduced the same whole-table scan one level up. A copy-only (batch, width) therefore answers Some(0) or None depending on whether any MTP packed shape at any batch and width happens to be measured — the exact non-local coupling the per-source split was meant to remove. It also contradicts the document this PR rewrote: docs/scheduling-runtime-design.md:429-433 promises the combined lookup returns zero "only when covering shapes exist without a positive measurement", but the :244-249 arm tests a different predicate (whether the MTP table is entirely empty). Callers inherit it: rounds.rs:585-589 (speculative_duration) and policy.rs:782-788 (continuation_candidate).
Change: delete packed_round_duration; have rounds.rs:588 and policy.rs:785 call packed_round_duration_for(self.proposal_source, batch, width) — both already know which cohort they price. Move the four packed_round_duration(...) assertions at cost.rs:449-463 to the source-qualified accessor, and state the two tables separately in :429-433.
Why: it is a net deletion (~12 lines), it is the last non-local cost dependency in the file, and code and doc currently disagree about when a lookup returns zero.
S2. Delete RequestScheduler::history_proposal — test-only, and it is the prompt-blind path this PR replaces
helios/src/scheduler.rs:1101-1104:
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);
self.decoded_history.as_ref().map_or((vec![-1; maximum], 0), |history| history.lookup(context, maximum))
}
Both production callers moved to request_history_proposal in this PR (model/packing.rs:405, server/runtime.rs:2146); the survivors are tests only (scheduler/tests.rs:1956-1991 (not opened),2069, server/runtime/phase_tests.rs:583 (not opened),1835). It ignores LiveRequest.sam entirely — exactly the prompt-blind behaviour the PR exists to replace — so leaving it pub invites a future caller to reintroduce it. It also duplicates the capacity clamp with a different overflow rule: completion_token_capacity - 1 panics on zero capacity, while clamp_copy_capacity (scheduler.rs:1106-1110) uses saturating_sub(1).
Change: delete the method; re-point the shared-ring assertions in scheduler/tests.rs (not opened) at request_history_proposal (those tests already admit live requests, so the handle-keyed path proves the same ring behaviour plus the SAM arbitration); make DecodedHistory::lookup (decoded_history.rs:180-183) #[cfg(test)] or fold it into lookup_with_match_len (:162).
Why: −4 lines, −1 duplicated clamp, −1 bypass route; the ring remains reachable as the SAM fallback, so no coverage is lost.
S3. One home for "speculative graphs default to Mtp", and drop the unreachable "any source" wildcard
cost::canonical_draft_source (cost.rs:50-59) states the rule, but pub(super) makes it unreachable outside helios/src/scheduler/, so it is hand-written again 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(...::Mtp) == step.draft_source.unwrap()
Both also begin with step.draft_source.is_none() || … — an "any source" wildcard that is unreachable at this head: every speculative Candidate receives cost::canonical_draft_source(kind, None) (policy.rs:1074) or a canonical shape.draft_source from Key::prepared (rounds.rs:848,1075), so a speculative ScheduledStep always carries Some. Wire validation also forces draft_source ∈ {1, 2} on speculative graphs (runtime_core/selection.rs:244).
Change: move the rule to speculation.rs next to parse/from_wire/to_wire (:46-69) as ProposalSource::canonical(kind, Option<Self>); call it from cost.rs:81,170,292,313, Candidate::cost_key (policy.rs:98), catalog.rs:296-299 and packing.rs:48-51; delete both is_none() arms and the two unwrap()s they license.
Why: the enum's other semantics already live in speculation.rs and are called from four modules (serving.rs:58, python.rs:225-231, selection.rs:141-148, server/config.rs:188-194 (not opened)); the one rule that did not get that home already cost a review round, and the wildcard is a way for a step to bind the wrong graph.
S4. Delete the CURVE_EVALUATIONS counter and its two tests
helios/src/scheduler/rounds.rs:30-33 (#[cfg(test)] thread_local! CURVE_EVALUATIONS), the bump at :565-566 inside powered_curve, and the two tests policy_tests.rs:6289-6331 (not opened) (mixed_refresh_value_reuses_each_decoding_lanes_forecast, decode_refresh_value_reuses_each_decoding_lanes_forecast).
Change: delete all three (~46 lines). Keep the behaviour the counter was added to guard: the single-forecast pricing at policy.rs:1052-1056 and :1258-1266 with zero_duration[slot].
Why: no production reader; the tests assert evaluations <= shapes.len() * lanes, an implementation detail that cannot fail if the sharing is later rewritten into an equally cheap form, plus a trivially true existence check (candidates.iter().any(|c| … c.expected > 0.0)). The reuse is one visible line in policy.rs. (cost.rs:15-19 ENTRY_LOOKUPS is the same pattern but pre-existing on main, so it is out of scope here.)
S5. Evidence: per-commit numbers, one exported-core load, and two stale doc glosses
Four independent outcomes share one combined-stack measurement (1b0db227 refresh recovery; padding dominance + min_match_len 3→6; SAM; wide copy-verify), so no number can be attributed or bisected; @voipmonitor's live TP4 run used the default --no-history-drafts, so the copy-only wide cohorts never executed on hardware; and no run loaded a core carrying draft_source = 2 — binding.rs:1467-1511 is a unit round-trip only.
Change: report per-commit live numbers, and one load-and-serve (plan + completion) of an exported W = 16 / W = 24 core. Fold in two prose fixes: docs/mtp-design.md:542-544 still lists copy proposals as coming only from decoded_history.rs, omitting sam.rs (not opened) (the primary per-request source, scheduler.rs:1112-1153) and the copy-only wide graph family, inconsistent with the same document at :26-34; and docs/api.md:295-296 / docs/cli-design.md:1790 gloss --history-drafts / flare_history_drafts_enabled as shared-history only.
Why: the charter's compatibility obligation is "verify that existing data, artifacts, and exported cores still load"; the copy-only cohort gates (rounds.rs:886-916) currently have only hand-built CPU fixtures behind them, and every repository document is a present-state specification, so a reader of the status list concludes the headline feature does not exist.
Subtract / Simplify
Could remove ~85–90 of the +4,306 added lines. The change is already near-minimal after e5a69669: the earlier candidates (SAM conditional/context API, MatchSource, SamConfig, empty RefreshState::idle, the doubled copy-match algorithm, the duplicated copy-cohort loop, the three-way draft_source ladder, the unreachable wide_copy_curve arm, the duplicated legacy-load assertion) are gone and were re-verified. What remains, ranked by lines:
- ≈46 lines — test-only instrumentation.
rounds.rs:30-33, the bump at:565-566, and bothpolicy_tests.rs:6289-6331(not opened) tests (S4). - ≈12 lines — the combined packed-round lookup.
cost.rs:237-252: delete it, letrounds.rs:588/policy.rs:785passself.proposal_source; the assertions atcost.rs:449-463move (S1). - ≈14 lines — entry points this PR orphaned.
scheduler.rs:1101-1104history_proposal(4) plus its duplicate clamp;decoded_history.rs:180-183lookupwrapper becomes#[cfg(test)](4);catalog.rs:240-245select_shape_with_drafts, whose only caller isselect_shapetwo lines above passingdrafts = 0(6) — haveselect_shapecallselect_shape_with_source(..., 0, None, mode)directly (S2). - ≈12 lines — the 3-ordering cohort preamble written twice.
rounds.rs:785-803(select_host_allocated_candidate) and:1019-1030(packed_round_candidates, GPU branch) are byte-identical (samematch ordering { 0 => full, 1 => base, _ => full/limits }, samerankclosure, samecohort/select_nth_unstable_by/truncate/sort_unstable_by), and both already havefull,base,limits,order,frontierin scope. Oneordered_cohort(...)helper serves both (~10). Alsorounds.rs:920-926clones a whole per-lane curve per wide copy shape (probabilities[slot] = curve.clone()) althoughbuild_host_prefix_ranking(:505-527) only indexes it andHostPrefixRanking.probabilitiesis only read as a slice (:781,816,841) — borrow the cachedcopy_curvesentry (~2, one allocation per shape per plan). - ≈8 lines — unreachable "any source" arms.
catalog.rs:296-299,packing.rs:48-51(S3). - ≈2 lines — two constants for one threshold.
speculation.rs:25 WIDE_COPY_MIN_MATCH_LEN = 6andsam.rs:23 (not opened) DEFAULT_MIN_MATCH_LEN = 6must stay equal or the gate atrounds.rs:905silently stops agreeing withpropose; reference thesamconstant, or drop the rounds gate sinceproposealready refuses shorter matches.
Deliberately not subtracted (so a later round does not re-add them): draft_source in cost::Key / Candidate / ScheduledStep and the per-source packed_round_durations — their absence was the bug e5a69669 fixed (test cost.rs:533-586); Candidate.expected — the zero-duration counterfactual read by compare_refresh (policy.rs:1349-1354), whose removal would change tie-breaking; MutableEdges/RootedLct in sam.rs (not opened) (~600 lines) — the price of the claimed O(log M) recency update; max_mtp_draft_tokens' filter (cost.rs:262-272) — a per-source maximum would add state to save a once-per-plan scan; and the manifest's draft_source == Copy && confidence_width != 0 clause (execution/manifest.rs:844-846) — it fires before catalog.rs:123-131 on the load path and costs 3 lines, so it buys an earlier error.
Nits (5)
- Capability tuples omit
draft_source.helios/src/model.rs:358-360(completion_inputs) and:369-370(speculative_allocations, type atscheduler.rs:108) key on(batch, drafts, width, packed)only, sogpu_prefix_allocation(rounds.rs:443-446) cannot distinguish an MTP GPU graph from an identically shaped copy graph; a copy step would then be priced with the MTP curve andcomplete_with_survival(scheduler.rs:2595-2598) would refuse it for lacking a confidence sidecar, which copy graphs are required not to have (catalog.rs:123-131). It is unreachable at this head because selection keeps MTP depths<= draftsand copy depths> drafts(selection.rs:277-298) and padding dominance now comparesdraft_source(policy.rs:248-258), but that invariant is implicit. Prefer one comment ordebug_assertover threading a sixth tuple element throughmodel.rs,rounds.rsandscheduler.rs:2496,2596. draft_source = 0andMixed + COPY_DRAFTare normalised differently per layer.heliopause/src/python.rs:225-231maps an explicit0toNone;heliopause/src/export/binding.rs:204maps0to"MTP";runtime_core/selection.rs:244rejects0on speculative graphs;execution/manifest.rs:849-850acceptsdraft_source.is_some()onMixedwhileignition/preparation/execution.py:104(not opened) andbinding.rs:213-215reject it. Cheapest single rule: makeexecution/manifest.rs:850rejectdraft_source.is_some()on anything butSpeculative(matching the producer and the exporter) and keeppython.rsmapping throughfrom_wire.RequestScheduler::idle(scheduler.rs:1267-1277) is a validator under a five-line doc comment describing retention it does not implement. Rename toassert_idle(one production caller,server/runtime.rs:1184), cut the doc to one line, and leave the retention argument todocs/scheduling-theory.md:574-582(not opened), which now states it.- The
6-token copy-match threshold still rests on one prompt.sam.rs:22-30(not opened) /speculation.rs:21-25now state derivations for0.88,4.0,2.0andWIDE_COPY_MIN_EXTRA_DRAFTS = 3, but the6is argued from a single 512-token repetitive code-edit prompt; one non-code prompt showing the collision rate below 6 would settle it. binding.rs:216writesdraft_sourceunconditionally, including when the derived value is the proto3 default — the same "always write" shape that produced the previous blocker. Harmless on the wire; write it only when it differs from the default, or leave a one-line comment that it is derived, not defaulted.
Verified clean (no action; recorded so it is not re-litigated)
- Export:
binding.rs:201-216derivesMTP/COPY_DRAFT, rejects unknown values and copy on non-speculative graphs;binding.rs:1467-1511round-trips0/1/2, unknown integer/string andmixed+copy this is the previously blocking defect, fixed. - Wire decode has one home:
ProposalSource::{parse,from_wire,to_wire}(speculation.rs:46-69) used bypython.rs:225-231,serving.rs:55-58,selection.rs:141-148,server/config.rs:188-194(not opened). - SAM lifecycle:
PromptOutputSAMbuilt at admission from the spec prompt (scheduler.rs:1843-1846), re-fed on preempt/readmission from the extended prompt (server/runtime.rs:1550-1553), fed byrecord_decoded_token(scheduler.rs:1217-1228) and the post-completion loop (:3007-3012), each gated on the samedecoded_history.is_some()predicate as construction; covered bypreempted_request_reindexes_generated_history_into_sam_on_readmission(server/runtime/phase_tests.rs:4036-4189(not opened)). resolve_copy_match(scheduler.rs:1112-1150) backs both proposal entry points and states the SAM-first / strictly-longer-ring-fallback order once;abortis the only path that discards earned credit (refresh.rs:95-99(not opened));refresh_order's two-tier(bool, u64)key (cost.rs:324-333) picks the highest-value unattempted stale shape.- Tests worth keeping: the randomized brute-force SAM oracle (
sam.rs:1400-1469(not opened)) andrequest_sam_proposes_prompt_continuations_and_isolates_requests(scheduler/tests.rs:1995-2126(not opened)) prove per-request isolation and output-over-prompt recency;cost.rs:533-586proves identical-shape MTP + copy coexistence. - No
#[allow(dead_code)], no new feature flags or env-var fallbacks, no instruction-like text in the description, comments or changed docs.
Open questions / could not verify
- Is
history_proposalmeant as a stable out-of-tree/embedding API? Nothing in the tree or description says so and it has no in-tree non-test caller; a one-line reply settles S2 the other way. - Are
WIDE_COPY_MIN_MATCH_LENandsam::DEFAULT_MIN_MATCH_LENmeant to diverge later? If yes, the duplicate6becomes a comment fix rather than a deletion. - Can a recipe export an MTP speculative graph with GPU prefix limits at the same
(batch, drafts, width, packed)as a copy graph? If yes, Nit 1 stops being latent and becomes a request-failing path before that recipe ships. - Is
Mixed+COPY_DRAFTintended to be legal?execution/manifest.rs:849-850allows it,binding.rs:213-215andignition/preparation/execution.py:104(not opened) reject it, andcost::canonical_draft_sourcesilently coerces it to "no source". A maintainer decision settles Nit 2 in one line. - Not run by any reviewer: CI on
e5a69669, the reported 1,712 / 620 / 207 / 71 test counts, the SAM microbenchmark, and any GPU path — including the wide copy-verifyW = 16/W = 24cohorts, power-limit refresh transitions, SM121/GB10 and multi-host RoCE. The description discloses all of these, which is why they are evidence limits rather than defects.