Correctness scratchpad · NVIDIA/hyperflare-inference #540

Raw Markdown for agents: https://autobot.eidonix.com/p/3559eb2f-a57a-466d-acef-44343dc14677.md

#1 [high] Candidate: exported cores overwrite draft_source with MTP

heliopause/src/export/binding.rs:196-202 (pre-existing, not in the PR diff):

if kind == "speculative" || kind == "mixed" && speculative {
    if !graph.contains_key("draft_tokens") { return Err(...) }
    graph.insert("verify_tokens".into(), width.into());
    graph.insert("draft_source".into(), "MTP".into());
}

This is the only JSON->wire conversion used by export (called from heliopause/src/export/capture.rs:3158 super::binding::execution(execution, &allocations)).

The PR now has ignition/preparation/execution.py:316-319 emit draft_source=signature.draft_source (1 or 2) into the manifest JSON (GraphSignature.draft_source added at execution.py:32, validated 98-108), and heliopause/src/python.rs:225-233 reads it for the in-process GraphExecutor path. But the core-export path unconditionally rewrites it to "MTP", so exported cores can never carry DraftSource::CopyDraft.

Consequence: on load, helios/src/runtime_core/selection.rs:277-298 copy_wide requires graph.draft_source == 2; the wide copy graphs become draft_source=1 with draft_tokens (e.g. 15/23) > drafts (7), so they are pruned by graph.draft_tokens.is_some_and(|depth| depth <= drafts as u32). Also helios/src/model/catalog.rs:93-96 copy_only_graph is false, so the copy-only input-buffer contract is not checked. Net effect: the whole wide copy-verify feature silently disappears for cores produced through export_capture (the flare run path), and any core that did declare copy graphs is mislabeled as MTP. Needs verification with a test that round-trips an export manifest containing draft_source=2 through binding::execution.

#2 [high] Research summary

I reviewed PR #540 through the correctness lens: charter and design rules first, then the changed files in context (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, ignition/preparation/execution.py, docs/scheduling-runtime-design.md), following callers of the changed APIs (refresh_order/idle/abort, record_attempt, request_history_proposal and its two call sites in packing.rs and server/runtime.rs, is_copy_only_step in runtime metrics, CopyCalibration.observe_prefix feeding wide_copy_curve/expected_copy_tokens, draft_source through wire→GraphDescriptor→cost/rounds/catalog/selection).

One confirmed finding is recorded on the scratchpad (entry 1, high): the export path silently drops the new draft_source, so exported cores can never carry COPY_DRAFT graphs. ignition/preparation/execution.py:316-319 now emits draft_source (1 or 2) per speculative graph and heliopause/src/python.rs:225-233 honors it for the in-process GraphExecutor, but the core-export conversion heliopause/src/export/binding.rs:196-202 (called from heliopause/src/export/capture.rs:3158) unconditionally does graph.insert("draft_source", "MTP"), rewriting any copy graph to MTP. On load, helios/src/runtime_core/selection.rs:277-298 only retains wide copy shapes when graph.draft_source == 2, so copy graphs come back as draft_source=1 with draft depth > drafts and are pruned; helios/src/model/catalog.rs:93-96's copy-only contract check (no GPU confidence, no speculative_prefix_limits) is also bypassed. Result: the advertised wide copy-verify feature disappears on the flare run/export path, and any core that did declare copy graphs is mislabeled MTP (potentially skipping the copy-only packing requirements). A round-trip test of an export manifest containing draft_source=2 through binding::execution would settle it; I could not run Rust tests here to confirm empirically.

Items I was still verifying when the time limit hit, and which I deliberately did not record as findings: (a) the sam/PromptOutputSAM lifetime across preemption re-admission (scheduler.rs:1846-1860 builds it from spec.prompt at admission while record_decoded_token/complete_inner push tokens separately — whether the readmitted spec.prompt already contains the generated tokens determines whether the output automaton is double-fed after a preempt/re-admit cycle); (b) whether ActionCosts::refresh_order's new (bool, u64) tiering can starve a never-attempted stale key when stale_keys() excludes the ordinary winner (policy.rs:1296-1329), and whether refresh_packed_durations' has_mtp guard silently hides measured copy-shape durations used by speculative_duration when speculative_fixed_width is set; (c) CopyCalibration::observe_prefix indexing survival[depth] for depth < copy_prefix where copy_prefix is the trailing-ones of copy_offered_mask while survival rows follow offered_drafts length (scheduler.rs:2877-2890) — a possible out-of-range/index-mismatch if the copy mask exceeds the offered prefix.

#3 [medium] Unverified candidate: SAM state on preemption/re-admission double-feed

Not verified — needs a test to settle.

helios/src/scheduler.rs admission builds the per-request automaton from the admission prompt only:

let sam = self.decoded_history.is_some().then(|| sam::PromptOutputSAM::new(&spec.prompt));

(around scheduler.rs:1846-1860, new in this PR).

Tokens are fed to it in three separate places, each guarded only by if let Some(sam) = &mut request.sam:

Questions to settle:

  1. resume_decoded_sequence (scheduler.rs:1211-1223) restores decoded_sequence but does not rebuild sam; if a request is resumed from a parked/readmitted state (server runtime parked/readmitted path, server/runtime.rs ~2080-2110), does spec.prompt already include the tokens that were previously generated? If yes, PromptSAM will contain output text (harmless) but the output vector starts empty while prompt_cursor is positioned at the true sequence end — probably fine; if no, the SAM misses the previously generated prefix (loss of proposals only, not incorrectness).
  2. Whether the preempted → idle/readmit path re-creates LiveRequest with the original prompt while push_token was already applied, causing each previously generated token to be indexed twice (once inside the prompt text, once in output), which would make build_proposal emit a continuation that duplicates text. PromptSAM is immutable and Arc-shared, so the double-index would only affect proposals, not correctness of committed tokens.

Settling test: admit a request, generate > min_match_len tokens, preempt, readmit, and compare propose() against the brute-force oracle already present in helios/src/scheduler/sam.rs (tests module, brute_force_oracle).

#4 [medium] Unverified candidate: refresh tiering starvation and copy-shape duration masking

Not verified — needs reading/experiment.

(1) Tier-0 keys never attempted while stale. ActionCosts::refresh_order returns (false, 0) for every entry whose last_attempt_ns < observed_at_ns + ttl, so all unattempted stale keys share the same sort key (0). Selection in helios/src/scheduler/policy.rs:1296-1329 then sort_by_key(|(order, _)| *order) and breaks out of the loop once best_order < order. Because tier-0 keys tie at (false, 0), the loop scans every tier-0 target before any tier-1 target — that is intended — but the ordering within tier 0 is now the Vec order from stale_keys() (insertion order of the prepared graph catalog) rather than "highest expected useful value first" as the PR description and docs/scheduling-runtime-design.md claim ("Within the active tier, candidates rank by indeterminate-duration expected useful value"). The compare_refresh tie-break only picks the best candidate for a given target; it does not order the targets. Worth confirming with the docs claim in the PR body ("the first funded refresh probes the highest-expected-value unattempted stale shape") and with policy_tests.rs:2536-2545 / 5888.

(2) refresh_packed_durations skips copy shapes whenever any MTP packed shape exists: helios/src/scheduler/cost.rs:190-208 — has_mtp is computed over all entries and copy-source entries are continued, so copy sources contribute neither a row duration nor are they measurable through packed_round_duration. packed_round_shapes() (cost.rs:215-221) still yields them and rounds.rs:752-... handles them specially, so this looks deliberate; but speculative_duration (rounds.rs:559-568) folds packed_round_shapes() with min_measured_duration when speculative_fixed_width.is_some(), and now mixes MTP and copy shapes of the same (batch,width) — a copy shape's duration could select the duration used for an MTP round. Note the fixed-width path is guarded to not use wide copy shapes (rounds.rs:759-764 skips copy shapes when speculative_fixed_width.is_some()), so this is likely unreachable in practice; verify before reporting.