Correctness and contracts report · NVIDIA/hyperflare-inference #660

Raw Markdown for agents: https://autobot.eidonix.com/p/2a224444-bb40-48fa-b552-6c9b8f423c0e.md

Correctness, Contracts & System-Level Consequences review — PR #660 (head 22cac91)

Reviewed against main (5d53040e), the head source of helios/src/scheduler/checkpoints.rs, its callers in helios/src/scheduler.rs, the touched test fixtures, and the contracts in helios/README.md / docs/api.md. The change is well aimed and mostly sound (see "Sound" below); the problems are one real divergence introduced by the new pricing, one undocumented operator-visible metric shift, and a test re-baselining pattern that removes coverage of the shipped default.

Key findings

  1. Major — the PR introduces a second, inconsistent anchor-budget rule. request_anchor_endpoint prices the split from price_start against whole and ignores extra_spent_ns; the planner prices from initial_prefill_ns and subtracts extra_spent_ns. On main both sites returned the raw anchor unconditionally at nonzero fraction, so they agreed; #660 makes them disagree. Because is_request_anchor_endpoint is what stamps RetentionRole::Anchor on inbound/restored tickets (helios/src/scheduler.rs:1797) and checkpoint_copy_allowed returns Ok(true) unconditionally for Anchor, an interior checkpoint the planner declined can still be promoted and copied uncharged — the same over-ranked-Anchor class that produced both blockers on #582.
  2. Major — flare_checkpoint_extra_work_nanoseconds_total silently changes scope. The Anchor cut's split_ns was hard-coded 0 on main; now it is charged and aggregated (checkpoints.rs:902-907), so a documented operator counter (docs/api.md:356-357, helios/src/server/metrics.rs:852) takes a step change for every anchored request, and extra_spent_ns now gates terminal captures differently, moving flare_checkpoint_skips_total{reason="work_budget"}. Neither body nor docs say so.
  3. Major — the shipped default 0.05 loses its pre-existing coverage. Six shared fixtures were re-parameterised to 1.0/0.2/0.1 (tests.rs:3313-3318, boundary_tests.rs:81-85, checkpoint_lifecycle_tests.rs:156-161, policy_tests.rs, vision_window_tests.rs, phase_tests.rs), and the TLA+ lifecycle conformance test now runs only at 1.0. The body calls this "Updated … unit tests".
  4. Minor — helios/README.md:372-380 still states the pre-PR anchor contract while all three design docs were rewritten. It is now the only place in-repo that describes anchoring without the allowance.
  5. Minor — verification/helios-lifecycle/check.py's only mutation was renamed, not extended: nothing kills a mutant of the new budget comparison (checkpoints.rs:591-597) or the new guard (:537-543), yet the body reports check.py 10/10 TLC / 8/8 Observed / 12/12 aux as evidence.
  6. Minor (conditional) — the anchor split can be charged twice across preemption, because clear_reservations (checkpoints.rs:48-51) clears cuts/reserved_ns but not extra_spent_ns, and the new early-return guard (:533-546) only fires while an Anchor cut still exists.
  7. Tests/claims — the None if fraction > 0.0 => (raw_anchor, 0) unknown-cost arm has no new test at the default fraction, and the A/B caveat "0 checkpoints.rs edits in 571a4471..5d53040e" does not isolate #656/#628.

1. Correctness, safety & contracts

F1 — Major: two anchor-budget decision sites disagree on both the price base and the spent work

helios/src/scheduler/checkpoints.rs:500-516 (site A, request_anchor_endpoint):

let fraction = self.policy.checkpoint_extra_work_fraction;
let keep_raw = match Self::anchor_split_ns(
    request,
    &catalog,
    terminal_window,
    price_start,
    request.prompt_tokens,
    raw_anchor,
) {
    Some((whole, split_ns)) => split_ns <= allowance(whole, fraction),
    None => fraction > 0.0,
};

helios/src/scheduler/checkpoints.rs:588-597 (site B, checkpoint_selection_uncached):

Some((whole, split_ns)) => {
    let budget_base = accounting.initial_prefill_ns.unwrap_or(whole);
    let available = allowance(budget_base, fraction);
    if split_ns == 0
        || accounting.extra_spent_ns.saturating_add(split_ns) <= available
    {
        (raw_anchor, split_ns)
    } else {
        (request.prompt_tokens, 0)
    }
}

Differences, all verified in head source:

main agreed because both were unconditional above zero — main checkpoints.rs:459-464:

if self.policy.checkpoint_extra_work_fraction != 0.0
    || raw_anchor >= request.prompt_tokens
    || request.prefix_tokens == raw_anchor as u64
{
    return Some(raw_anchor);
}

and main checkpoints.rs:577-579 budgeted only at fraction == 0.0.

Impact. is_request_anchor_endpoint (checkpoints.rs:519-522) is the predicate that classifies inbound/restored checkpoints:

pub(super) fn is_request_anchor_endpoint(&self, request: &LiveRequest, endpoint: u64) -> bool {
    self.request_anchor_endpoint(request)
        .is_some_and(|anchor| endpoint == anchor as u64)
}

used at helios/src/scheduler.rs:1797:

let role = if self.is_request_anchor_endpoint(request, inbound.consumed_tokens) {
    RetentionRole::Anchor

and Anchor copies are never gated (checkpoints.rs:971-973):

if capture.role == RetentionRole::Anchor {
    return Ok(true);
}

So when site A says "keep raw_anchor" but site B said "fall back to prompt_tokens", a return-visit request still stamps Anchor rank on the interior checkpoint the planner refused to fund, retaining it over Message/Endpoint checkpoints and copying it without budget — the duplicate/over-ranked Anchor failure mode that blocked #582 twice. Divergence also runs the other way (site A's price_start == 0 at :487 prices a larger whole, so A can keep a split B rejects on extra_spent_ns), and any request whose budgeted_anchor latch is absent (wrong raw_anchor/prompt_tokens pair after a re-admit, see F6) has no reconciliation at all.

Fix. One decision function, e.g. fn anchor_decision(&self, request: &LiveRequest) -> (usize, u64) computing budget_base = accounting.initial_prefill_ns.unwrap_or(whole) and extra_spent_ns + split_ns <= allowance(base, fraction), called by both request_anchor_endpoint and checkpoint_selection_uncached, so the predicate that assigns RetentionRole::Anchor cannot disagree with the planner. Add a test that asserts is_request_anchor_endpoint and checkpoint_selection return the same endpoint for a request where extra_spent_ns > 0.

F2 — Major: an existing operator metric changes meaning without being mentioned

helios/src/scheduler/checkpoints.rs:899-908 (commit_checkpoint_plans):

accounting.reserved_ns = accounting.reserved_ns.saturating_sub(cut.split_ns);
accounting.extra_spent_ns = accounting.extra_spent_ns.saturating_add(cut.split_ns);
self.stats.checkpoint_extra_work_ns = self
    .stats
    .checkpoint_extra_work_ns
    .saturating_add(cut.split_ns);

On main the Anchor cut was pushed as Cut { endpoint: anchor, role: RetentionRole::Anchor, split_ns: 0, copy_ns: 0 } (main checkpoints.rs:610-617), so this loop added nothing for anchors; the head pushes the real split (checkpoints.rs:619-627).

Contract text, untouched by the PR — docs/api.md:356-359:

`flare_checkpoint_extra_work_nanoseconds_total` sums charged predicted
extra prefill and copy work; it is not a GPU timing measurement.
`flare_checkpoint_anchor_reservations` reports unused anchor guards, excluding
armed destinations and in-flight copies.

Exported at helios/src/server/metrics.rs:852:

("checkpoint_extra_work_nanoseconds_total", "counter", &self.checkpoint_extra_work_ns),

Impact. Any dashboard, alert, or regression gate on flare_checkpoint_extra_work_nanoseconds_total steps up by the anchor split of every anchored request, with no doc change and no note in the body — a metric/scope shift of exactly the kind the review lens asks to trace. Second-order: extra_spent_ns is also read by checkpoint_copy_allowed (checkpoints.rs:981-984) and allocate_terminal_capture, so flare_checkpoint_skips_total{reason="work_budget"} (metrics.rs:844) moves too, in a change whose whole point is fewer extra prefill launches.

Fix. Amend docs/api.md:356-357 to say the counter now includes charged anchor split work (and that anchor snapshot copies remain uncharged), and state the movement in the PR body. If a stable series matters, consider leaving the anchor split out of checkpoint_extra_work_ns and exposing it separately — but either way the doc must say which.

F6 — Minor (conditional): anchor split can be double-charged across a real preemption

helios/src/scheduler/checkpoints.rs:48-51:

pub(super) fn clear_reservations(&mut self) {
    self.cuts.clear();
    self.reserved_ns = 0;
}

extra_spent_ns survives, and clear_reservations runs on every admit (helios/src/scheduler.rs:1731: checkpoints.clear_reservations();). The new guard that protects a charged anchor cut (checkpoints.rs:533-546) requires such a cut to still exist:

|| accounting.cuts.iter().any(|cut| {
    cut.role == RetentionRole::Anchor
        && cut.endpoint > start
        && (request.anchor_guard.is_some()
            || accounting.extra_spent_ns > 0
            || cut.split_ns > 0)
})

After clear_reservations the cuts vector is empty, so re-planning proceeds; if raw_anchor > start again (:579), site B adds split_ns to reserved_ns (:620) and commit_checkpoint_plans adds it to extra_spent_ns a second time (:903). On main this path could not charge for an anchor (split_ns: 0), so the PR extends an existing extras-only accounting quirk to anchors.

Impact. A preempted-and-readmitted request with an interior anchor can lose budget twice for the same split, pushing the terminal capture and later Message extras out of the allowance for the rest of the request — cheap to avoid, hard to see, and only on the contended path where the budget is tight.

Fix. Either include the committed anchor split in baseline_interval-style carried state that clear_reservations preserves (a charged_anchor: Option<(usize, u64)>), or make the guard at :533 consult extra_spent_ns/budgeted_anchor independently of the still-present cuts entry. Add a test that preempts after an anchor cut commits and asserts extra_spent_ns does not grow by the same split twice. I flag this as conditional only because I did not trace every preemption path that resets prefill_cursor behind the anchor.

Verified sound in this area


2. Architecture, contracts & charter compliance

F4 — Minor: helios/README.md now contradicts the code; all three design docs were updated

helios/README.md:372-380 (unchanged by this PR):

Checkpoint selection prioritizes the last eligible message boundary,
using the prompt end when no message boundary is eligible. Earlier messages and
a distinct prompt end compete within a work allowance of
`scheduler_checkpoint_extra_work_fraction` times estimated uncached prefill work,
defaulting to 0.05. Extra captures charge snapshot-copy cost and additional prefill
caused by splitting chunks.

The three docs that were rewritten say the opposite of "prioritizes the last eligible message boundary": docs/cli-design.md:696-711 ("serves as the conversation anchor only when splitting prefill there adds predicted prefill work within the request's extra-work allowance … otherwise the zero-split prompt end acts as the anchor"), docs/core-design.md:1434-1460 ("its predicted split overhead is charged against that same extra-work allowance"), docs/scheduling-runtime-design.md:613-630.

Impact. The crate README is the in-repo contract operators read for checkpoint behaviour; after this PR it is the only document describing anchoring without the allowance, and it omits the two operationally important facts (the anchor can fall back to the prompt end; the anchor split competes with Message/Endpoint extras).

Fix. Add one sentence to helios/README.md:372-380 in this PR stating that the interior anchor is retained only within the same allowance and that its split work is charged (copy uncharged).

Charter / process items worth adjudication


3. Tests & claim accuracy

F3 — Major: fixtures were re-baselined away from the shipped default instead of covering it

helios/src/scheduler/tests.rs:3303-3318 (the widely shared prefill_to_publication_boundary):

let mut graphs = duration_graphs(1);
for g in &mut graphs {
    if g.kind == GraphKind::Prefill {
        g.estimated_duration_ns = 100_000 + g.token_capacity as u64;
    }
}
scheduler.measured_graph_durations(&graphs).unwrap();
scheduler
    .configure_policy(PolicyConfig {
        checkpoint_extra_work_fraction: 1.0,
        ..Default::default()
    })
    .unwrap();

helios/src/scheduler/boundary_tests.rs:74-85 does the identical duration rewrite plus checkpoint_extra_work_fraction: 1.0. helios/src/scheduler/checkpoint_lifecycle_tests.rs:152-161 (the TLA+/lifecycle conformance test checkpoint_reservations_match_lifecycle_model) also runs at 1.0:

for cancellation in 0..5 {
    let mut scheduler = tests::scheduler(2, 64, 3);
    scheduler
        .configure_policy(PolicyConfig {
            checkpoint_extra_work_fraction: 1.0,
            ..Default::default()
        })
        .unwrap();

Also re-parameterised: policy_tests.rs (0.2, 1.0), vision_window_tests.rs (0.1), phase_tests.rs:3898-3906 (1.0), and phase_tests.rs:1539-1600 (exact_system_and_prompt_checkpoints_publish_only_after_snapshot_completion) was rewritten from prompt 13 / boundary 10 to a chunk-aligned boundary plus 3 tokens so the anchor lands where the budget accepts it.

Impact. These tests encoded the behaviour the PR classifies as a bug, so re-baselining is legitimate — but the body presents it as "Updated … unit tests". The consequence is that the shipped default (0.05, helios/src/scheduler/policy.rs:40, validated policy.rs:206-213) is now exercised only by the new inline tests inside checkpoints.rs, and the TLA+ conformance model only ever runs at 1.0 — i.e. no reservation-accounting edge is emitted for the charged-anchor path at the fraction every deployment actually uses, which is precisely what verification/helios-lifecycle exists to police.

Fix. Keep one lifecycle-model run at the default fraction (or add a second edge-emitting run at 0.05 with an interior anchor that is charged), and say in the body that shared fixtures were re-baselined to 1.0 and why.

F5 — Minor: the lifecycle mutation was renamed only; the new decision is unmutated

verification/helios-lifecycle/check.py:672-677 — the only hunk in the PR:

check_mutations(cargo, ROOT / "helios/src/scheduler/checkpoints.rs", CHECKS[7][1], [
    ("dropped multi-chunk zero-budget fallback",
     "accounting.budgeted_anchor = Some((raw_anchor, request.prompt_tokens, chosen));",
     "accounting.budgeted_anchor = None;",
     "multi-chunk prefill must retain zero-budget prompt-end anchor fallback"),
])

The rename keeps the mutation valid (the target line still exists at checkpoints.rs:602), but no mutation kills a mutant of what this PR adds — the budget comparison at checkpoints.rs:591-597 or the new guard conjunct cut.split_ns > 0 at :542. The body nonetheless lists check.py (10/10 TLC, 8/8 Observed / 594,065 edges, 12/12 aux) under evidence for the change.

Fix. Add mutations: (a) if split_ns == 0 || accounting.extra_spent_ns.saturating_add(split_ns) <= available → if true (interior anchor always retained), (b) drop || cut.split_ns > 0 from :542.

Untested new arm, and the trade the diff itself proves

Claim accuracy in the description


Open questions for adjudication

  1. Should F1's two sites share one budget basis (my recommendation), or is the "latch normally reconciles them" argument considered sufficient? The divergence matters exactly when the latch is missing.
  2. Is the mixed-c32 per-user regression (93.9 → 71.0 tok/s, >250 ms gaps 215 → 434) an accepted trade for +96.2% mean decode batch and +23.7% output throughput, or should it block until re-measured with repeats?
  3. Is losing the late interior Endpoint capture on multi-boundary prompts (the [256,512,640,768,896,1024] → [256,512,768,896,1024] assertion) intended, and should the README/docs state it?
  4. Sequencing against #655 (same function, Ready-To-Merge): which lands first, and does #660 re-baseline and re-A/B before review?
  5. Does the maintainer want anchor split work in checkpoint_extra_work_nanoseconds_total (meaning change, undocumented) or a separate series?

What could not be found or verified