Review of PR #540 — helios: cost-refresh recovery, prompt+output SAM copy-drafts, and calibrated wide copy-verify
Lens: Correctness — does the change work everywhere it reaches (callers, configurations, platforms, state transitions, compatibility with existing artifacts).
Key findings
- Blocking — the wide copy-verify feature is dead on the core-export path.
heliopause/src/export/binding.rs:196-202rewritesdraft_sourceto"MTP"for every speculative graph while converting the Preparation manifest to the wireExecution. The PR addsdraft_source = 2(COPY_DRAFT) to that manifest on the Python side (ignition/preparation/execution.py:32,98-108,316-319) and teaches the in-process reader to honour it (heliopause/src/python.rs:225-233), but the export path is untouched and overwrites it. Every exported core therefore re-imports its wide copy graphs as MTP graphs with draft depth beyond the learneddrafts, andhelios/src/runtime_core/selection.rs:277-298prunes them. - Should fix — the same line silently coerces instead of rejecting. The export path performs no validation of
draft_source; the sibling reader does (python.rs:230returns "unsupported graph draft_source"). Because the field is also the only key that triggers the copy-only contract checks (helios/src/execution/manifest.rs:845-846,helios/src/model/catalog.rs:93-96— no GPU confidence, nospeculative_prefix_limits, four copy input buffers), a mislabelled graph is not merely dropped: it skips those checks. - Nit — two encodings for one field, no round-trip test.
binding.rs:201writes the Progruft enum name string;python.rs:225-233reads an integeru32(1/2, 0 = none). Nothing in the test suite round-trips a manifest containingdraft_source = 2throughbinding::execution, which is why this slipped. - Three other candidates were investigated and dropped as non-defects or unreachable (details in "Candidates checked and dropped"). One remains an open question needing a test (SAM across preempt/re-admit).
1. Blocking — exported cores relabel copy-draft graphs as MTP and drop them
Where: heliopause/src/export/binding.rs:196-202
if kind == "speculative" || kind == "mixed" && speculative {
if !graph.contains_key("draft_tokens") {
return Err(super::invalid("speculative graph lacks explicit proposal depth"));
}
graph.insert("verify_tokens".into(), width.into());
graph.insert("draft_source".into(), "MTP".into()); // <-- unconditional
}
What the PR does on the producing side. ignition/preparation/execution.py:32 adds draft_source: int = 1 to GraphSignature; lines 98-108 validate it and enforce the copy-only invariants (confidence_width == 0, no speculative_prefix_limits); line 319 emits it into the manifest as draft_source=signature.draft_source. The PR description states these graphs carry draft_source metadata 1 = MTP, 2 = COPY_DRAFT.
Two consumers, only one updated.
- In-process
GraphExecutorpath:heliopause/src/python.rs:225-233— new, reads 0/1/2 and maps2tohelios_core::scheduler::speculation::ProposalSource::Copy, rejecting anything else. - Core-export path:
super::binding::execution(execution, &allocations)atheliopause/src/export/capture.rs:3158— the only JSON→wire conversion used byexport_capture(heliopause/src/export/binding.rs:17,105, invoked fromignition/preparation/runtime_core.py:140(not opened)). It still hard-codes"MTP", overwriting the value the manifest just supplied.
Why it matters — the graphs are then pruned at load. helios/src/runtime_core/serving.rs:58-63 faithfully decodes the wire enum back (1 → Mtp, 2 → Copy), so the loss happens on the write side and is invisible downstream. In helios/src/runtime_core/selection.rs:
- line 184:
let retain_wide_copy = source == 1 && history_enabled && fixed.is_none(); - lines 277-283:
copy_widerequiresgraph.draft_source == 2anddraft_tokens > drafts.
A wide copy graph arriving with draft_source = 1 fails copy_wide, and then the ordinary MTP branch at lines 291-293 rejects it because graph.draft_tokens.is_some_and(|depth| depth <= drafts as u32) is false (the whole point of those graphs is depth > base_mtp_drafts, e.g. W=16/W=24 with 15/23 drafts versus 7 MTP drafts). So the graph is removed from the catalog and the wide copy-verify feature — the headline of commit 35ab143a — never runs on any core produced through export. The failure is silent: there is no diagnostic distinguishing "core was built without copy graphs" from "core's copy graphs were relabelled and pruned", which will make the limitation in the PR body ("copy-only wide graph (W=16/W=24) GPU export/replay … not benchmarked") very hard to interpret for anyone who tries it.
Fix: preserve the field. Either pass the incoming JSON value through (graph.get("draft_source")), or derive it explicitly: emit 2 when the manifest said 2, 1 for a speculative graph with no field, and reject unknown values the way python.rs:230 does. Add a unit test that round-trips an execution manifest containing draft_source = 2 through binding::execution and asserts wire::Execution.graphs[i].draft_source == DraftSource::CopyDraft as i32 — that is also what would settle this empirically (I could not run the Rust test suite in this review).
2. Should fix — silent coercion bypasses the copy-only contract
Where: same line, heliopause/src/export/binding.rs:200.
heliopause/src/python.rs:225-233 treats an unknown draft_source as a hard error; binding.rs treats every value as "MTP". The field is load-bearing for validation as well as selection:
helios/src/execution/manifest.rs:845-846:graph.draft_source == Some(ProposalSource::Copy) && graph.confidence_width != 0→ "speculative B/D/W/P geometry is invalid". With the value coerced to MTP, a copy graph that (incorrectly) carries GPU confidence passesvalidate().helios/src/model/catalog.rs:93-96:copy_only_graphis… && graph.draft_source == Some(ProposalSource::Copy); the copy-only buffer/confidence_width == 0requirements hang off it.
So the coercion does not just drop a feature; it also lets an invalid copy graph through manifest validation, and the two readers now disagree about the same artifact (in-process accepts and validates 2, exported core says 1). Fixing Finding 1 fixes this too, provided the export path also rejects out-of-range values rather than mapping them to MTP.
3. Nit — divergent encodings, no regression test
binding.rs:201 writes a prost_reflect enum name ("MTP"); python.rs:225-233 extracts an integer. Both are legal for their own reader, but nothing ties them together and there is no test in the PR (or found in the tree) that exercises draft_source through binding::execution — the tests added by the PR cover the Python side (tests/preparation/test_execution.py:299-302 (not opened), tests/preparation/test_packed_speculative_contract.py:54 (not opened)) and the load side (helios/src/runtime_core/selection.rs:1896-1937, helios/src/model/tests.rs:1944 (not opened), helios/src/scheduler/tests.rs:4183 (not opened)), not the export conversion. Prefer one encoding for both readers, and add the round-trip test noted above.
Candidates checked and dropped
These were on my list from research; I read them in context this session and they are not defects:
ActionCosts::refresh_ordertiering (helios/src/scheduler/cost.rs:287-296, consumed athelios/src/scheduler/policy.rs:1295-1330). My concern was that every unattempted stale key sorts as(false, 0)and the ordering within that tier would be insertion order rather than expected useful value, contradicting the PR body anddocs/scheduling-runtime-design.md. Reading the loop: for tier-0 pairsbest_order < orderis never true, so the loop scans all tier-0 targets andcompare_refresh(policy.rs:1285-1290,ValueRate::new(0, expected, age_price)) selects the maximum across them; the break only fires on the transition to tier 1 (false, …) < (true, …)). Tier 1 is then ordered bylast_attempt_ns. Behaviour matches the documented claim.refresh_packed_durations'has_mtpguard (helios/src/scheduler/cost.rs:190-207) andspeculative_duration's mixed fold (helios/src/scheduler/rounds.rs:559-568). The concern was that a copy shape's measured duration could select the duration for a fixed-width MTP round. Unreachable: copy-only wide graphs are pruned when the fixed width is retained (helios/src/runtime_core/selection.rs:184,293—fixed.is_none()gatescopy_wide) and are also skipped during candidate generation (rounds.rs:755-764), so nodraft_source == Copyentry survives intocosts.entriesin that mode.draft_sourcein the wire/serving decode (helios/src/runtime_core/serving.rs:58-63) and the manifest geometry checks (helios/src/execution/manifest.rs:840-851). Correct for values 0/1/2; the only problem is that the export writer never lets2through (Findings 1-2).
Open question — needs a test, not a code reading
PromptOutputSAM across preempt / re-admission (new helios/src/scheduler.rs, admission builds sam from spec.prompt; tokens pushed in record_decoded_token, complete_inner and the decoded-sequence append path). resume_decoded_sequence restores decoded_sequence but does not rebuild sam. If the readmitted spec.prompt already contains tokens generated before the preempt, they are indexed twice (once in the immutable PromptSAM, once in the dynamic OutputSAM), and request_history_proposal could propose a continuation that repeats text. Because PromptSAM is only a source of proposals, the worst case is wasted verification slots and reduced acceptance, not incorrect committed tokens — but I could not show from code alone whether server/runtime.rs re-admission passes the original or the extended prompt. Settle it with the brute-force oracle already present in the helios/src/scheduler/sam.rs test module: admit, generate more than min_match_len tokens, preempt, readmit, and compare propose() against the oracle.
Coverage and what I could not verify
- Read in context (not only the diff):
helios/src/scheduler.rs,scheduler/{cost,refresh,policy,rounds,speculation,sam,decoded_history}.rs,execution/manifest.rs,model/{catalog,packing}.rs,runtime_core/{selection,serving}.rs,server/runtime.rs,heliopause/src/{python.rs,export/binding.rs,export/capture.rs},ignition/preparation/execution.py,docs/scheduling-runtime-design.md, plus the cited tests. - Not run: the Rust test suites, the SAM microbenchmark, and any GPU path — so Findings 1-2 are established by code reading only; the round-trip test described under Finding 1 is what would turn them into an observed failure.
- Not covered by this lens' evidence: live GPU behaviour for the copy-only wide shapes, and SM121/GB10 — consistent with the PR's own stated limitations.