Review — PR #540: helios cost-refresh recovery, prompt+output SAM copy-drafts, calibrated wide copy-verify
Head 7ca5430, 25 files, +3965/−119. Judged against the Flare charter (read_charter), AGENTS.md:52-56 (not opened), 72-112, 155-205, 431-465 and docs/design-review.md:14-52 (not opened). Every finding below was re-verified in the code at head. Nothing in the PR description, comments or docs attempted to direct the review; all instruction-shaped text was treated as material to check.
Key findings
- One blocker.
heliopause/src/export/binding.rs:201overwrites every speculative graph'sdraft_sourcewith"MTP"on the only core-export path, so the wide copy-verify graphs this PR introduces are pruned at load on every exported core — silently. - Commit
a85be397(funded-refresh recovery) is correct, self-contained, and mergeable today. Its arithmetic,abortsemantics and two-tierrefresh_orderall check out, anddocs/scheduling-runtime-design.md:425-450matches the code. - The flag docs contradict the code.
docs/cli-design.md:200-202says--history-drafts"does not change the graphs"; after commit 3 it changes which graphs and kernels load and rewritesspeculative_widths. - The subtractive finding is volume, not purpose. All four behaviours map to a stated gap with a measurement; ~550–685 of the +3,965 added lines can go without losing a decision or an assertion.
Blockers
B1. The core-export path relabels every copy graph as MTP, so wide copy-verify never runs on an exported core
Where: heliopause/src/export/binding.rs:196-202, reached from heliopause/src/export/capture.rs:3158 (the only export route, export_capture, invoked at ignition/preparation/runtime_core.py:140).
if kind == "speculative" || kind == "mixed" && speculative {
...
graph.insert("verify_tokens".into(), width.into());
graph.insert("draft_source".into(), "MTP".into()); // unconditional overwrite
}
The producing side now emits the real value: ignition/preparation/execution.py:32 adds draft_source: int = 1, :102-108 validates it and enforces the copy-only invariants, :316-319 writes draft_source=signature.draft_source into the manifest. Two consumers read it and only one was taught about value 2:
- in-process
GraphExecutor:heliopause/src/python.rs:225-233maps0/1/2and rejects anything else — updated by this PR; - export conversion:
binding.rs:201hard-codes"MTP"— untouched.
binding::execution deserializes JSON into the wire Execution via prost_reflect, so it needs the proto enum name; it overwrites rather than derives it. Load then decodes the wire value faithfully (helios/src/runtime_core/serving.rs:58-63), and helios/src/runtime_core/selection.rs:277-298 drops the graph:
let copy_wide = retain_wide_copy
&& graph.kind == "speculative"
&& graph.draft_source == 2
&& graph.token_capacity > 1
&& graph.confidence_width == 0
&& graph.draft_tokens.is_some_and(|depth| depth as usize > drafts);
...
&& (copy_wide || (graph.draft_source == source
&& graph.draft_tokens.is_some_and(|depth| depth <= drafts as u32)
&& ...))
Wide copy graphs are exactly the shapes with depth > base_mtp_drafts (W=16/W=24 with 15/23 drafts against 7 MTP drafts at retain_wide_copy = source == 1 && history_enabled && fixed.is_none(), :184). Mislabelled, they fail copy_wide and fail the MTP branch, so every exported core silently prunes them. Two consequences:
- The headline capability of commit
35ab143acannot be exercised on any core the repository can produce, and the PR's own limitation ("copy-only wide graph GPU export/replay … not benchmarked") becomes impossible to diagnose, because "core was built without copy graphs" and "core's copy graphs were relabelled" are indistinguishable. draft_sourceis also the key for the copy-only contract checks (helios/src/execution/manifest.rs:844-846,helios/src/model/catalog.rs:93-96,123-131), so coercion also lets a mislabelled copy graph (e.g. one carryingconfidence_width != 0) pass validation.
Fix (derivation, not an addition): replace the constant with one match arm — 1/absent-on-speculative => "MTP", 2 => "COPY_DRAFT", otherwise super::invalid(...). Add one round-trip test over binding::execution asserting draft_source == DraftSource::CopyDraft as i32 for a manifest carrying 2; that is the test the PR is missing (tests/preparation/test_execution.py:299-302 and test_packed_speculative_contract.py:54 only cover the manifest encoder, not the export conversion). This is what turns the finding from a code reading into an observed failure.
Should Fix
S1. --history-drafts now changes the loaded graph set, but the CLI and MTP specs say it does not
docs/cli-design.md:200-202: "--history-drafts enables host history tracking and feeds continuations into the captured graphs' history inputs; it does not change the graphs."
After commit 35ab143a the flag decides graph selection: helios/src/runtime_core/selection.rs:182-184 computes retain_wide_copy, :277-298 retains or prunes copy-only graphs, :375-380 drops unselected graphs' kernels (core.graphs.retain, prune_kernels), and :382-396 rewrites speculative_widths in the exported configuration. A fixed width disables the copy path entirely (retain_wide_copy needs fixed.is_none()). The PR's own test wide_copy_graphs_retain_only_when_history_drafts_enabled (selection.rs:1876) asserts widths [1,6,16,24] with history drafts vs [1,6] without. docs/mtp-design.md:22-29 compounds it: "Both settings use the same captured MTP graphs and buffers."
Fix: in docs/cli-design.md:200-202 and the :742 table row, and in docs/mtp-design.md:22-29, state that the flag also elects optional copy-draft-only wide graphs when the core carries them, and only in adaptive mode with no fixed width. Three sentences, no code.
S2. The documents that own this behaviour were not updated (one omits the new field entirely)
docs/mtp-design.md:31-40still describes only the shared 65,536-token ring, "exact eight-token and four-token indexes", "up to seven observed continuation tokens". After commit83ff9ed6the ring is the fallback, used only when it matches strictly longer (helios/src/scheduler.rs:1143-1148); the primary path is a per-request prompt+output automaton withmin_match_len = 6(sam.rs:22), a 131,072-token prompt cap (:25), a 131,072-token output cap (:28) and a 512-token boundary overlap (:32).docs/scheduling-runtime-design.md:6-12enumerates the modules that implement the design and omitssam.rs, so a reader following the document's own pointer cannot reach the copy-proposal implementation. Nothing in the document describes the copy-only graph contract (draft_source == 2), theCopyCalibrationprior, or the wide-copy eligibility gate.docs/scheduling-runtime-design.md:249-254says pruning discards a shape "whose capacities are all at least as large as an alternative".prune_padding's new second pass (helios/src/scheduler/policy.rs:221-254) discards a ragged GPU-allocated speculative candidate when a strictly tighter batch covers the cohort's needed target rows (needed = candidate_round_lengths(index).sum().min(packed_token_capacity)), so the survivor'spacked_token_capacitymay be strictly smaller. This is the paragraph that justifies themax_b == Cresult; it no longer describes the rule.docs/scheduling-runtime-design.md:396-399("minimum positive measured duration across matching shapes, zero only when every matching shape is unmeasured") no longer matchescost.rs:190-208, which skips copy entries whenever any MTP packed entry exists.helios/manifest.md:29-53specifies the graph dictionary field by field and omitsdraft_source, whichheliopause/src/python.rs:225-233now reads (0/1/2, default MTP for speculative). An author following the spec gets the default and then failscatalog::validate.
Fix: rewrite mtp-design.md:22-41 around the SAM-first mechanism with the ring as fallback (caps and the six-token minimum in prose, since neither threshold is flag-exposed); add sam.rs to the module index plus a short draft_source/wide-copy section; restate the covering condition in the pruning paragraph and the copy/MTP split in the packed-duration paragraph; add draft_source to manifest.md.
S3. Two authorities for the proposal source, and it is not in the cost key — so cost semantics depend on which other graphs the core contains
The head already declares a source: speculative_proposal_source → ProposalSource (helios/src/scheduler/speculation.rs:23-38), driving selection at selection.rs:144-199. The PR adds a second, per-graph draft_source, and then needs copy-specific bypasses in shared code: selection.rs:184; :277-298 (copy graphs skip the draft_source == source, draft_tokens <= drafts, fixed-width and mtp_verification_token_budget filters); :382-396 (config speculative_widths rewritten to widths no MTP graph implements); cost.rs:190-208 (has_mtp); cost.rs:223-232 (is_copy_only_step); rounds.rs:752-790 (an entire copy-only candidate branch). Scheduling behaviour is now a function of (config, manifest field, and which other graphs were exported).
The concrete defect inside this:
cost::Key(cost.rs:151-158) has nodraft_source, yetprepared()rejects duplicate keys (:159-161, "prepared graphs require unique shapes"), so an MTP graph and a copy graph with identical B/D/W/P cannot coexist in one core;is_copy_only_step(:223-232) therefore has to look the source up in the table instead of reading the step.refresh_packed_durations'shas_mtp(:192-196) is an existence scan, not a freshness one: one unmeasured MTP packed entry suppresses every measured copy entry (:199-201), andpacked_round_duration(:210-213) then returnsNonefor a shape that was measured — contradictingdocs/scheduling-runtime-design.md:396-399.
Fix (subtractive): add draft_source to cost::Key so is_copy_only_step and packed_round_shapes read the key directly and two sources may share a geometry; replace the existence scan with an explicitly keyed per-source table; and answer "may this shape be scheduled" in one scheduler-level predicate over the captured shape list rather than in selection.rs, cost.rs and rounds.rs.
S4. Calibrated constants ship without a derivation
WIDE_COPY_PRIOR_RATE = 0.88, WIDE_COPY_MIN_MATCH_LEN = 6, COPY_STEP_PRIOR_WEIGHT = 4.0, COPY_DEPTH_SHRINK_WEIGHT = 2.0 (helios/src/scheduler/speculation.rs:15-21), min_copy_len = base_mtp_drafts.saturating_add(3) (helios/src/scheduler/rounds.rs:766) and DEFAULT_MIN_MATCH_LEN = 6 (sam.rs:22, raised from 3). The description argues only the 6 (one 512-token repetitive code-edit prompt) and gives nothing for 0.88, 4.0, 2.0 or +3. These are shared-policy numbers that decide when a graph is scheduled; the charter asks for explicit, pinned values with a stated basis.
Fix: one sentence of derivation per constant in the design doc, or promote the policy decisions into named fields; state why the copy depth margin over the MTP depth is three. Keep it to prose, not new knobs — AGENTS.md:446-456 (not opened) governs where such settings live, and a flag per constant would be worse than a documented derivation.
S5. Evidence: the claims cannot be separated, and the SAM build cost is reported without saying where it is paid
- Attribution. The PR bundles four outcomes in 25 files against
AGENTS.md:194-199(not opened):a85be397refresh recovery,83ff9ed6the SAM,35ab143awide copy graphs,7ca5430cpadding dominance +DEFAULT_MIN_MATCH_LEN3→6. "Combined-stack" is honest labelling for the headline throughput, but it means neither commit 4's padding-dominance effect nor commits 2–3's3.078 → 3.650 emitted tokens/roundcan be attributed or bisected, and the refresh fix needs none of the others. Fix: report per-commit live numbers for the padding-dominance change and the SAM/wide-copy stack in the description (not necessarily a re-cut branch). - Admission cost.
PromptSAM::buildat13.05 ms / 4.52 MiB(131,072 tokens) is not a background cost:admitbuilds it synchronously per admitted request (helios/src/scheduler.rs:1849-1852), i.e. up to ~4.5 MiB of host memory per live request and a stall proportional to prompt length. Fix: one sentence saying the build is paid at admission, that cost and memory scale with prompt length, and that admission latency with--history-draftson a long prompt was not measured live. - Compatibility. No checks are reported on the head commit, and "existing W=8-only cores load, prune, pack, and schedule" rests on unit tests (
helios/src/model/tests.rs:1866-1888,selection.rs:1876) rather than a load-and-serve of a previously exported core, whichAGENTS.md:431-444(not opened) asks for. Fix: one loaded-core check, or an explicit statement that it was not run. - Preempt / re-admission.
helios/src/server/runtime.rs:2068-2108rebuildsincoming.prompt.tokensaslive.tokens() ++ appended(prompt + generated), and readmission rebuildssamfrom that prompt, whileresume_decoded_sequence(scheduler.rs:1212-1223) restores onlydecoded_sequence— so previously generated text is re-indexed through the prompt automaton rather than the output automaton. Worst case is wasted verification slots, not wrong commits, and no test covers it. Fix: one brute-force-oracle test (thesam.rs:1236oracle) over admit → generate → preempt → re-admit, or holdsamandcopy_calibrationbehind onePerRequestCopyStateso they cannot diverge (scheduler.rs:1849-1856currently constructs them from the same predicate, twice).
S6. Python allows draft_source = 2 on mixed speculative graphs; Rust requires speculative
ignition/preparation/execution.py:104-108 validates copy graphs as speculative or speculation-enabled mixed, and binding.rs:196 treats them the same way; helios/src/runtime_core/selection.rs:278-283 and helios/src/model/catalog.rs:94 retain copy-only graphs only when kind == "speculative". A mixed copy graph is exportable and unloadable.
Fix (one line): reject 2 on mixed where it is validated and delete the mixed clause — or support it in selection. Not both.
Subtract / Simplify
Could remove ~550–685 of the +3,965 added lines with no decision or assertion lost. (Test files carry +1,408 of the total: scheduler/tests.rs +583, policy_tests.rs (not opened) +501, model/tests.rs +324.)
- ~150–250 test lines re-prove the same path.
helios/src/model/tests.rs:846-953(history_draft_packing_forwards_per_request_prompt_sam_continuations, 108 lines) repeats the pack-and-assert flow of:1861-2075(215 lines, and the only test that exercisesdraft_source = 2end to end);:1873-1888repeats the legacy-W8-load assertion owned byhelios/src/runtime_core/selection.rs:1876-1940;helios/src/scheduler/tests.rs:1995-2127re-provessam.rs's own unit tests, of which only the admission wiring and per-request isolation are scheduler-specific. Replace with: keep the wide-copy packing test, fold the 846-953 case into it as extra assertions, keep the selection test as the legacy-load proof, trim 1995-2127 to admission + isolation. - ~100 lines: the copy-only candidate loop duplicates the ordinary one.
helios/src/scheduler/rounds.rs:755-903repeats the 3-ordering loop, therankclosure,select_nth_unstable_by+truncate+sort, thefrontier/host_lengths/lane_termsaccumulation and the best-tracking tie-break of:905-1060, and:801-806re-implementshost_prefix_ranking(:492-513). Replace with: one loop taking a per-slot curve provider plus the availability gate, collapsingcurves/copy_curves(:747-748) into one[Option<Vec<f64>>; REQUEST_LANES]. - ~150 lines of SAM API with no production caller (
pub mod sam,helios/src/scheduler.rs:23):propose_conditional_continuations(sam.rs:1112-1189+ test:1491-1514) — its doc names "a building block for conditional copy lookup tables in 2-deep pipelined execution", which exists nowhere in this tree or the description;propose_for_context(:1068-1110+ oracle call:1463);MatchSource+MatchProposal::source+ its constructor sites (:64-69, 80-81, 1217/1219, 1263/1265) and four test assertions;PromptSAM::build(:283, tests can usebuild_capped);push_slice(:1023, tests can looppush_token); the accessor block except what the#[ignore]microbenchmark reads. Re-point the randomized oracle atproposeso the surviving matching path keeps brute-force coverage — the one real cost of this deletion. - ~40 lines: the same match algorithm twice.
helios/src/scheduler.rs:1112-1159(request_history_proposal_with_match_len) and:1163-1205(request_copy_match_stats) share the clamp, the early exit, the request lookup, the SAM propose with OOV truncation, the ring lookup and the strictly-longer tie-break — and have already drifted (.filter(|&(count, _)| count > 0)at:1194exists in one copy only, so a zero-count ring result is a match in one path and not the other, whilerounds.rs:774-776gates onmatch_lenfrom the filtered path).decoded_history.rs:180-183is the in-PR precedent for the wrapper. Replace with: one private helper returning(tokens, count, match_len). - ~20 lines:
RefreshState::idleis an empty function.helios/src/scheduler/refresh.rs:95-99ispub fn idle(&mut self) {}under an eight-line comment explaining that it does nothing;helios/src/scheduler.rs:1277-1283validates the queue and calls it. Retention across idle is now the absence of mutation. Replace with: delete the method and the call, keep the submissions guard, and drop the ~10.idle()assertions that can no longer fail (policy_tests.rs:2610 (not opened), 2638, 2689, 2699, 2730, 2751, 3685, 5714, 5720, 5765); one docs sentence covers the surviving behaviour. - ~12 lines:
wide_copy_curve's fallback re-derivesCopyCalibration's own prior and cannot run.rounds.rs:541-548reproduces the geometric prior seeded atspeculation.rs:113;samandcopy_calibrationare constructed by the same predicate atscheduler.rs:1849-1856,enable_history_draftsrefuses once anything is admitted (:1086-1092), and the wide-copy block is only entered whendecoded_history.is_some()(rounds.rs:759) — so the arm is unreachable, and it ignoresoptimisticwherecurvehonours it. Replace with: take the calibration unconditionally, leavingWIDE_COPY_PRIOR_RATEwith exactly one use site. - ~15 lines: the
0/1/2 → Option<ProposalSource>ladder is written three times —helios/src/runtime_core/serving.rs:58-63,heliopause/src/python.rs:225-233,helios/src/runtime_core/selection.rs:144-148— with three error messages.ProposalSource::parse(speculation.rs:30-38) is the existing pattern. Replace with:from_wire/to_wirenext toparse,python.rsalone owning the absent-key default, and enum comparison instead ofu64inselection.rs.
Explicitly not asking for removal: Candidate.expected alongside Candidate.rate (policy.rs:89-90). rate is expected / duration − age·duration/2 for nonzero durations (utility.rs:122-131, set at rounds.rs:899, 1058), while expected is the zero-duration counterfactual the refresh comparison needs (policy.rs:1285-1290, :1415-1425); neither is recoverable from the other without re-deriving the age price. Likewise the MutableEdges/Link-Cut-Tree machinery in sam.rs (~600 lines) has no smaller equivalent in the repository for O(log M) recency under the 131,072-token cap it benchmarks at 140–317 ns/step.
Nits
- Title and commit independence. The title names three of four outcomes; commit
7ca5430c(padding dominance +DEFAULT_MIN_MATCH_LEN3→6) is the fourth and the headlinemax_b == Cresult depends on it. One sentence saying which commits depend on which tells a reviewer what must land together. refresh_orderlost its contract comment (cost.rs:287-296):(bool, u64)means "attempted while stale with no valid observation, then attempt time". Neighbouring helpers keep their invariants inline (:21-48, 210-213). One comment line, or a named struct.- The SAM oracle is not independent of production code (
sam.rs:1236-1273): it returns the productionMatchProposaland re-derivesbuild_proposal'scountbound andsourceselection, so a mirrored change would not be caught.decoded_history.rs:228-252returns plain tuples — the better shape, and a one-line change. - Copy-only validation is written three times (
execution/manifest.rs:844-846,model/catalog.rs:123-131— the superset, load-time — andignition/preparation/execution.py:102-108): keep the catalog gate, drop the manifest clause and its doc line. AndWIDE_COPY_MIN_MATCH_LEN(speculation.rs:18) duplicatessam::DEFAULT_MIN_MATCH_LEN(sam.rs:22) — two constants for one threshold that must stay equal (rounds.rs:776gates on the first, proposals on the second); use thesamconstant and delete the other.
Positive, no action: the refresh work is well scoped — observed_compute_duration_ns/timing_refresh_duration_ns exclude measured readiness wait while acceptance learning keeps raw duration (cost.rs:31-38, refresh.rs:71-93), abort still discards positive credit (refresh.rs:101-105), and the two-tier refresh_order genuinely fixes "probe the older, smaller shape first"; docs/scheduling-runtime-design.md:425-450 matches that behaviour exactly, and the protobuf already carried DraftSource { NO_DRAFT, MTP, COPY_DRAFT } (helios/proto/runtime_core.proto:842 (not opened),854), so no wire default changes for existing cores (AGENTS.md:437-440 (not opened)). The description also carries the four required sections in order and a correct Discord: line — no prose-formality item worth a bullet.
Open questions
- Was the wide copy-verify path approved in advance as
docs/design-review.md:22-26(not opened) requires for a new operation contract (draft_source = 2plus a new buffer set on speculative graphs)? Nothing in the description says so; a maintainer comment settles it. Only relevant if S6/the single-authority question is resolved in favour of keeping per-graph sources. - Is
has_mtp(cost.rs:192-196) meant as "copy shapes only compete when no MTP packed shape exists", or as a workaround for mixed catalogs? The code has no comment; the description describes the behaviour, not the invariant. S3's key-level fix removes the question. - Is
propose_conditional_continuationsthe front half of an unmerged PR? Its doc names "2-deep pipelined execution" as the consumer; if a follow-up exists, name it in the description (then subtractive item 3 becomes "land with its consumer"), otherwise delete it. - Can commits 2–4's live numbers be reproduced without commit 1? Only the author's rig can answer; this is what S5's per-commit request is for.
What could not be verified
- No CI runs exist on the head commit, so the reported counts (615 passed / 1,625 passed) and the SAM microbenchmark figures cannot be confirmed from the repository; the test paths were read, not executed. B1 is established by code reading; the round-trip test in B1's fix is what makes it an observed failure.
- The live GPU claims (4× RTX PRO 6000 SM120, DeepSeek-V4.1 Flash TP4,
max_b == C,+12.9%tok/s) cannot be checked from the repository; only the fact that they depend on multiple commits simultaneously could be verified. - Whether admission-time SAM construction is a visible serving stall needs a live run with
--history-draftson a ~128K-token prompt; the 13.05 ms figure isbuildalone and excludes allocation under serving memory pressure. - The
rounds.rsloop-merge saving (~100 lines) is structural: it assumes the copy branch'scohort = shape.batch.min(shape.tokens)and itslimit <= base_mtp_drafts + 1gate map onto the ordinary loop's limit without changing which masks are produced. The structures match line for line, but the planner's tests were not run to prove candidate-for-candidate equality.