Code review summary report · NVIDIA/hyperflare-inference #540

Raw Markdown for agents: https://autobot.eidonix.com/p/774ee922-769b-4a28-a398-a87b599f8033.md

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


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:

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:

  1. The headline capability of commit 35ab143a cannot 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.
  2. draft_source is 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 carrying confidence_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)

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:

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

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.)

  1. ~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 exercises draft_source = 2 end to end); :1873-1888 repeats the legacy-W8-load assertion owned by helios/src/runtime_core/selection.rs:1876-1940; helios/src/scheduler/tests.rs:1995-2127 re-proves sam.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.
  2. ~100 lines: the copy-only candidate loop duplicates the ordinary one. helios/src/scheduler/rounds.rs:755-903 repeats the 3-ordering loop, the rank closure, select_nth_unstable_by+truncate+sort, the frontier/host_lengths/lane_terms accumulation and the best-tracking tie-break of :905-1060, and :801-806 re-implements host_prefix_ranking (:492-513). Replace with: one loop taking a per-slot curve provider plus the availability gate, collapsing curves/copy_curves (:747-748) into one [Option<Vec<f64>>; REQUEST_LANES].
  3. ~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 use build_capped); push_slice (:1023, tests can loop push_token); the accessor block except what the #[ignore] microbenchmark reads. Re-point the randomized oracle at propose so the surviving matching path keeps brute-force coverage — the one real cost of this deletion.
  4. ~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 :1194 exists in one copy only, so a zero-count ring result is a match in one path and not the other, while rounds.rs:774-776 gates on match_len from the filtered path). decoded_history.rs:180-183 is the in-PR precedent for the wrapper. Replace with: one private helper returning (tokens, count, match_len).
  5. ~20 lines: RefreshState::idle is an empty function. helios/src/scheduler/refresh.rs:95-99 is pub fn idle(&mut self) {} under an eight-line comment explaining that it does nothing; helios/src/scheduler.rs:1277-1283 validates 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.
  6. ~12 lines: wide_copy_curve's fallback re-derives CopyCalibration's own prior and cannot run. rounds.rs:541-548 reproduces the geometric prior seeded at speculation.rs:113; sam and copy_calibration are constructed by the same predicate at scheduler.rs:1849-1856, enable_history_drafts refuses once anything is admitted (:1086-1092), and the wide-copy block is only entered when decoded_history.is_some() (rounds.rs:759) — so the arm is unreachable, and it ignores optimistic where curve honours it. Replace with: take the calibration unconditionally, leaving WIDE_COPY_PRIOR_RATE with exactly one use site.
  7. ~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_wire next to parse, python.rs alone owning the absent-key default, and enum comparison instead of u64 in selection.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

  1. Title and commit independence. The title names three of four outcomes; commit 7ca5430c (padding dominance + DEFAULT_MIN_MATCH_LEN 3→6) is the fourth and the headline max_b == C result depends on it. One sentence saying which commits depend on which tells a reviewer what must land together.
  2. refresh_order lost 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.
  3. The SAM oracle is not independent of production code (sam.rs:1236-1273): it returns the production MatchProposal and re-derives build_proposal's count bound and source selection, so a mirrored change would not be caught. decoded_history.rs:228-252 returns plain tuples — the better shape, and a one-line change.
  4. Copy-only validation is written three times (execution/manifest.rs:844-846, model/catalog.rs:123-131 — the superset, load-time — and ignition/preparation/execution.py:102-108): keep the catalog gate, drop the manifest clause and its doc line. And WIDE_COPY_MIN_MATCH_LEN (speculation.rs:18) duplicates sam::DEFAULT_MIN_MATCH_LEN (sam.rs:22) — two constants for one threshold that must stay equal (rounds.rs:776 gates on the first, proposals on the second); use the sam constant 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

  1. 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 = 2 plus 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.
  2. 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.
  3. Is propose_conditional_continuations the 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.
  4. 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