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,102-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 a draft depth beyond the learneddrafts, andhelios/src/runtime_core/selection.rs:277-298prunes them. - Should fix — the same line 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-131— 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 theprost_reflectenum name string;python.rs:225-233reads an integeru32(1/2, 0 = none). Nothing in the suite round-trips a manifest containingdraft_source = 2throughbinding::execution, which is why this slipped through. - Three other candidates were investigated and dropped as non-defects or unreachable (details in "Candidates checked and dropped"). A fourth — SAM state across preempt/re-admit — was settled from code as a behaviour note, not a defect (see below), and still deserves a regression test.
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 102-108 validate it and enforce the copy-only invariants (confidence_width == 0, no speculative_prefix_limits, speculative graph kind); lines 316-319 emit it into the manifest together with draft_tokens/verify_tokens. The PR description states these graphs carry draft_source metadata 1 = MTP, 2 = COPY_DRAFT, and the wire enum matches: helios/proto/runtime_core.proto:854 (NO_DRAFT = 0; MTP = 1; COPY_DRAFT = 2), field declared at runtime_core.proto:842.
Two consumers, only one updated.
- In-process
GraphExecutorpath:heliopause/src/python.rs:225-233— new in this PR, 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(binding.rsregistersexport_captureat line 105; the export entry point isignition/preparation/runtime_core.py:140(not opened),flare_heliopause.export_capture(...)). 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 (not opened) faithfully decodes the wire enum back (1 → Mtp, 2 → Copy), so the loss happens entirely 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 9caba2c7 — 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 on live hardware.
Fix: preserve the field. Either pass the incoming JSON value through (graph.get("draft_source")), or derive it explicitly: emit "COPY_DRAFT" when the manifest said 2, "MTP" 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::COPY_DRAFT as i32; that is also what would settle this empirically (the Rust test suite was not run in this review).
2. Should fix — silent coercion bypasses the copy-only contract
Where: same line, heliopause/src/export/binding.rs:200-201.
heliopause/src/python.rs:225-233 treats an unknown draft_source as a hard error (Some(_) => return Err(... "unsupported graph draft_source")); 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-131:copy_only_graphis… && graph.draft_source == Some(ProposalSource::Copy); the copy-only buffer requirements (four copy inputs,confidence_width == 0, noSpeculativePrefixLimit) and the extraCopyGrammarMask/CopyGrammarCountrequirements 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, the 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 from the Python dict. Both are legal for their own reader, but nothing ties them together and there is no test that exercises draft_source through binding::execution — the tests added by the PR cover the Python side (tests/preparation/test_execution.py (not opened), tests/preparation/test_packed_speculative_contract.py (not opened)) and the load side (helios/src/runtime_core/selection.rs around lines 1896-1937, helios/src/model/tests.rs (not opened), helios/src/scheduler/tests.rs (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 research list; they are not defects, verified in context this session:
ActionCosts::refresh_ordertiering (helios/src/scheduler/cost.rs:287-296, consumed athelios/src/scheduler/policy.rs:1295-1330). The concern was that every unattempted stale key sorts as(false, 0), so ordering within that tier would be catalog insertion order rather than expected useful value, contradicting the PR body anddocs/scheduling-runtime-design.md(not opened). 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 ("the first funded refresh probes the highest-expected-value unattempted stale shape").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 a 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(not opened)) and the load-time geometry checks (helios/src/runtime_core/selection.rs:244-247). Correct for values 0/1/2; the only problem is that the export writer never lets2through (Findings 1-2).
Settled from code (behaviour note, not a defect) — SAM across preempt / re-admission
The earlier open question — whether the new per-request suffix automaton double-feeds tokens after a preempt/re-admit — resolves negatively:
Worker::park(helios/src/server/runtime.rs:2068-2088) copieslive.tokens().to_vec(), extends it with the appended/held token, setsincoming.prompt.tokens = tokens; incoming.prompt.max_new_tokens = remaining; incoming.readmitted = true;, and saveslive.decoded_sequenceintoCarried.- Re-admission restores only the decoded sequence:
self.scheduler.resume_decoded_sequence(handle, parked.carried.decoded_sequence)(helios/src/server/runtime.rs:1550-1553), which setsrequest.decoded_sequenceand nothing else (helios/src/scheduler.rs:1211-1223). PromptOutputSAMis built per admission from the already-extendedspec.prompt(helios/src/scheduler.rs:1849-1852), andpush_tokenis fed only fromrecord_decoded_token(scheduler.rs:1227-1238) and the post-completion loop (scheduler.rs:3010-3021), both of which run for the new admission only.
Therefore no token is indexed twice and propose() cannot emit a self-duplicating continuation. Two consequences worth knowing (not defects): features that depended on the dynamic output side (recency tie-break MatchSource::Output, default_min_match_len freshness, boundary_overlap straddling) degrade to prompt-only behaviour for the remainder of a re-admitted request, and earlier output beyond max_prompt_tokens = 131_072 (helios/src/scheduler/sam.rs:22 (not opened)) is dropped. A preempt→readmit test comparing propose() against the in-module brute-force oracle (helios/src/scheduler/sam.rs (not opened) tests module) would be the right guard, since nothing in the suite exercises this path.
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(not opened), 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
binding::executionround-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.
- Charter check: this is squarely in the "Supported matrix & compatibility … verify that existing data, artifacts, and exported cores still load" obligation (
read_charter, line ~42); the export path is exactly a persisted-artifact compatibility surface, and it was not updated for the new field.