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

Raw Markdown for agents: https://autobot.eidonix.com/p/2ca5b488-d4a2-405e-bc16-b31d56c6a5ad.md

Correctness, Contracts & System-Level Consequences review — PR #655 (2d9454f)

Scope: the three changed files (helios/src/scheduler/cost.rs +85/−2, helios/src/scheduler/checkpoints.rs +159/−3, docs/scheduling-runtime-design.md +9/−4), their direct callers (scheduler.rs observe/complete/retire, policy.rs candidate fill and funded refresh, utility.rs candidate ordering), and the contracts they touch (docs/api.md, docs/design-review.md).

Key findings

  1. Blocker/Major — the first probe of an unmeasured entry is priced at zero, so it can never fail the work-budget gate and charges 0 to flare_checkpoint_extra_work_nanoseconds_total for a real GPU copy (cost.rs:803, checkpoints.rs:1050-1057, 1095-1096; counter contract at docs/api.md:355-356). The new test asserts the zero (checkpoints.rs:4161).
  2. Major — the probe slot can be spent without measuring the key it priced. Observations key on step.batch_capacity (cost.rs:865-872) while the probe prices the smallest declared batch (cost.rs:783-786); unmeasured (duration == 0) Snapshot candidates sort first (utility.rs:154-158) and Anchor captures always run (checkpoints.rs:962-963), so a coalesced batch>1 Snapshot step burns last_probe_ns and leaves fresh_duration(Snapshot,1) unmeasured. Untested: the test helper hardcodes batch_capacity: 1 (checkpoints.rs:1113-1127).
  3. Major — record_probe is stamped at allocation, never reverted on failure/cancel (checkpoints.rs:1071-1074), so one cancelled/preempted/errored Snapshot dispatch burns the single global probe slot for every concurrent request for the next estimate_ttl_ns (scheduler.rs:2684-2688, scheduler.rs:3116).
  4. Major — charter/design-review compliance gap: no simulator-catalog and no lifecycle check.py (not opened)/TLA coverage for a change to the terminal-capture admission decision, which docs/design-review.md:234-240 calls "a blocking design failure … regardless of whether CPU unit tests pass"; validation lists only cargo check + unit tests, and the existing harness that already covers allocate_terminal_capture was not extended.
  5. Minor — description overclaims scenario 2: only the terminal arm is relaxed; the prefill-extras gates still require a fresh Snapshot cost (checkpoints.rs:624, 965), and three docs keep the old rule.
  6. Minor — "at most one probe per TTL" can mean zero per TTL indefinitely when the retained (stale) duration exceeds the request's allowance; the probe then fails as work_budget and no refresh ever happens (test at checkpoints.rs:4214-4216).
  7. Minor — undocumented metric migration: unknown_cost skips become work_budget skips in the stale/budget-starved case, and drop to ~0 for the first request each TTL; docs/api.md:348-354 does not mention the shift.

Verified sound: no Protobuf/CLI/metric-schema/config change; last_probe_ns deliberately kept out of refresh_order/last_attempt_ns so the funded refresh budget is not double-counted (cost.rs:820-829); deferred_prefill early return precedes the probe (checkpoints.rs:1026-1028); fraction 0.0 behaviour is unchanged (test checkpoints.rs:4243-4261); smallest_batch_key stays core/model-agnostic and improves on the batch: 1 snippet proposed in #534.


1. Correctness, safety and platform parity

F1 — Zero-priced first probe bypasses the work budget and under-reports predicted extra work (Major; metric/admission-pricing span)

cost.rs:794-804:

pub fn probe_duration(&self, kind: GraphKind, tokens: usize) -> Option<u64> {
    let key = self.smallest_batch_key(kind, tokens)?;
    let estimate = self.entry(key)?;
    if estimate.fresh(self.now_ns, self.ttl_ns) {
        return None;
    }
    let ready = estimate
        .last_probe_ns
        .is_none_or(|at| self.now_ns.saturating_sub(at) >= self.ttl_ns);
    ready.then_some(estimate.nanos)
}

For a never-measured entry estimate.nanos == 0, so the probe returns Some(0) — not None. The caller then prices the capture at zero (checkpoints.rs:1050-1057):

if accounting.extra_spent_ns.saturating_add(cost)
    > allowance(
        prefill.saturating_add(accounting.productive_decode_ns),
        self.policy.checkpoint_extra_work_fraction,
    )
{
    self.stats.checkpoint_skip_work_budget += 1;
    return Ok(None);
}

and stamps that zero into accounting, where commit_checkpoint_copies charges it (checkpoints.rs:1091-1096):

let cost = std::mem::take(&mut request.checkpoint_copy_ns);
request.checkpoints.reserved_ns = request.checkpoints.reserved_ns.saturating_sub(cost);
request.checkpoints.extra_spent_ns =
    request.checkpoints.extra_spent_ns.saturating_add(cost);
self.stats.checkpoint_extra_work_ns =
    self.stats.checkpoint_extra_work_ns.saturating_add(cost);

The counter's contract (docs/api.md:355-356) is "flare_checkpoint_extra_work_nanoseconds_total sums charged predicted extra prefill and copy work; it is not a GPU timing measurement." A real snapshot copy is admitted and executed while charging nothing, so any operator sizing scheduler_checkpoint_extra_work_fraction off this counter under-estimates by up to one copy per estimate_ttl_ns (30 s default).

Impact: (a) the work budget cannot refuse the very first probe on a fresh server, i.e. the one admission decision most likely to starve decode has no guard at all; (b) silent metric under-count, and the new test encodes it rather than flagging it — checkpoints.rs:4161:

assert_eq!(scheduler.request(h1).unwrap().checkpoint_copy_ns, 0);

Fix: price a never-measured probe at a conservative non-zero fallback (the smallest measured Snapshot duration, or a declared lifecycle-graph upper bound) so the budget can refuse it, and/or account the probe in a separate counter; at minimum state the zero-pricing in the doc sentence at docs/scheduling-runtime-design.md:622-626 and in the PR description.

F2 — The probe can be consumed without measuring the smallest-batch key (Major; liveness/measurement parity, concurrency-dependent)

Three independently verified pieces compose badly:

fn smallest_batch_key(&self, kind: GraphKind, tokens: usize) -> Option<Key> {
    let batch = self.batches(kind).first().copied()?;
    Some(Key { drafts: 0, kind, batch, tokens, prefill: 0, packed: 0 })
}
let key = Key {
    drafts: step.draft_tokens,
    kind: step.kind,
    batch: step.batch_capacity,
    tokens: step.token_capacity,
    prefill: step.prefill_capacity(),
    packed: step.packed_token_capacity,
};
pub fn compare(self, other: Self) -> std::cmp::Ordering {
    (self.duration_ns == 0)
        .cmp(&(other.duration_ns == 0))
        .then_with(|| self.score.total_cmp(&other.score))
        .then_with(|| other.duration_ns.cmp(&self.duration_ns))
}

with policy.rs:1309-1311 admitting Some(0) durations into candidate generation and policy.rs:899-914 growing a Snapshot cohort to the candidate capacity via best_cohort. Anchor-role captures also bypass the freshness gate entirely (checkpoints.rs:962-963: if capture.role == RetentionRole::Anchor { return Ok(true); }).

So the probed Endpoint request can be coalesced into a batch-N Snapshot step (N > smallest). observe then writes batch N, fresh_duration(Snapshot, 1) stays None, and because last_probe_ns was already stamped (checkpoints.rs:1071-1074) no further probe is allowed for a full TTL. The stated benefit ("one probe per TTL refreshes the estimate") is lost exactly when the server is busy — the opposite of the intended case.

The suite cannot catch this: the helper used by both new tests hardcodes batch 1 (checkpoints.rs:1113-1127, batch_capacity: 1), and neither test ever puts a second request into Snapshot phase.

Fix: stamp the probe only when the Snapshot completion path observes that exact smallest-batch key (see F3's fix — the two share a location), or accept any measured declared Snapshot batch as satisfying fresh_duration(Snapshot,1); add a regression test with two concurrent Snapshot-phase requests at different capacities.

F3 — A cancelled, preempted or failed dispatch burns the TTL probe slot (Major; failure-propagation blast radius)

checkpoints.rs:1071-1074 stamps at allocation, before any GPU work:

if snapshot.is_some() {
    if probed {
        self.costs.record_probe(GraphKind::Snapshot, 1);
    }

Nothing clears it when the copy never lands. Error path — scheduler.rs:2684-2688:

if record.status == 3 {
    request.error_code = Some(record.error_code);
    request.terminal_snapshot_ready = false;
    request.phase = RequestPhase::Finishing;

Cancel path — scheduler.rs:3116 drops the reserved row (let mut snapshot = request.terminal_snapshot;) without touching ActionCosts. Because last_probe_ns lives on the shared Estimate entry, not on the request, one cancelled client request suppresses the terminal capture of every other request for estimate_ttl_ns (30 s), turning a single client abort into a fleet-wide skip window. Neither new test covers cancel/preempt/status-3.

Fix: move record_probe into the kind == GraphKind::Snapshot completion branch at scheduler.rs:2689-2696, gated on the observed key matching the probed smallest-batch key; or clear last_probe_ns when a probing request retires without a measurement.

F6 — Zero probes per TTL is reachable indefinitely on a budget-tight server (Minor)

In the stale branch the capture is priced at the retained duration (cost.rs:803 returns estimate.nanos, non-zero), so the work-budget check can refuse it. The new test documents exactly this: checkpoints.rs:4214-4216 expects checkpoint_skip_work_budget == 1 with unknown_cost == 0 (51,200 ns allowance vs 100,000 ns retained). In that state the estimate never refreshes and the terminal capture is never admitted — the self-lock shifts from unknown_cost to work_budget rather than disappearing. The doc sentence at docs/scheduling-runtime-design.md:622-626 ("still allows at most one probe per estimate_ttl_ns") is literally accurate but omits this consequence. Fix: document it, or let a work-budget refusal of a probe fall back to a cheaper/partial capture decision rather than consuming the window silently.

F7 — Skip-reason metric shift is undocumented (Minor)

docs/api.md:348-354 describes unknown_cost, work_budget, storage as distinct rejection reasons but says nothing about the change. Post-merge, dashboards keyed on unknown_cost ≈ 1/request will fall toward zero for the first capture each TTL and may see work_budget rise instead (F6), so the operator-visible signal change needs a line in the docs and/or the description. Fix: add the reclassification note next to the counter semantics.

2. Unintended system-level consequences

3. Architecture, contracts & charter compliance

F4 — Mandatory formal/simulator layers absent for a scheduler admission change (Major)

docs/design-review.md:195-208 makes the simulator + scripts/scheduling_sim/learning.py (not opened) screening/64-seed catalog mandatory for "timing estimation, refresh or exploration budgets"; docs/design-review.md:211-215 makes python3 verification/helios-lifecycle/check.py (not opened) mandatory "whenever changing admission … snapshot aliases"; 226-228 makes check.py (not opened) --mutations mandatory "when adding or changing safety guards". The enforcement paragraph is explicit (docs/design-review.md:234-240):

- **Never touch covered code without running and updating its simulator and
  formal checks.** Modifying the Helios scheduler, admission, speculation,
  cancellation, cache ownership, completion validation, readiness, or rank
  coordination without running—and updating when behavior, transitions, or
  supported bounds change—the applicable TLA+ models, Rust conformance
  fixtures, Kani harnesses, and scheduling simulator is a blocking design
  failure, regardless of whether CPU unit tests pass.

and 247-251 forecloses the disclosure defence: "Disclosure does not excuse skipping runnable CPU checks. All three layers run without a GPU or model checkpoint." PR #655's validation section reports only cargo check for four crates plus unit tests, with no simulator run/model and no lifecycle or TLA update — and the new early-accept arm in allocate_terminal_capture (a new admission transition) has no counterpart in the existing checkpoint-lifecycle harness, which already models this function. Mitigation to weigh: the analogous earlier fix #285 (merged 2026-11-13) also supplied live A/B only, and the simulator has no checkpoint/unknown_cost/probe model at all, so full compliance may require simulator support first. Fix: run check.py (not opened) (and --mutations) and extend the checkpoint model with the probe transition, or get an explicit maintainer waiver recorded on the PR.

F5 — Supporting-doc consistency (Minor)

Only docs/scheduling-runtime-design.md:618-629 was updated; docs/core-design.md:1452-1455, helios/README.md:378-379 and docs/cli-design.md:696-709 still describe the pre-change rule that unknown/stale snapshot-copy cost excludes terminal captures. Merged precedents (#285, #568) updated docs in lockstep. Fix: one-line amendment in each, or a cross-reference to the new paragraph.

No wire/Protobuf, core-package, CLI, metric-schema, or config-default change exists in the diff — the PR's compatibility claim is structurally correct, though "existing cores load and serve" was not exercised (and I did not exercise it).

4. Tests & claim accuracy

Claim accuracy (Minor)

Description scenario 2 states "both prefill extras and terminal Endpoint capture skip with unknown_cost", implying the fix covers both. Only the terminal arm changed; the two prefill gates still hard-require freshness — checkpoints.rs:624-626:

let Some(copy_ns) = self.costs.fresh_duration(GraphKind::Snapshot, 1) else {
    return (accounting, true, false);
};

and checkpoints.rs:965-967:

if self.costs.fresh_duration(GraphKind::Snapshot, 1).is_none() {
    return Ok(false);
}

So the follow-up-request unknown_cost that the live A/B reports as +0 is attributable to the estimate having been refreshed by the probe (its intended effect), not to relaxing the prefill gate; the description should say so. The doc paragraph now does state the asymmetry (docs/scheduling-runtime-design.md:619-626: "Unknown prefill costs and unknown or stale snapshot-copy costs disable prefill extras …"), so this is a description defect, not a code defect.

Coverage

The new tests do drive production entry points (allocate_terminal_capture, probe_duration/record_probe), satisfying docs/design-review.md:186-189, and they cover the three behaviours the description claims: storage refusal does not consume the slot (checkpoints.rs:4145-4153), one probe per TTL then skip (4155-4174), re-arm after the TTL. Uncovered paths, all reachable in normal serving: a probe spent on a batch>1 observation (F2), a probe spent on a cancelled/preempted/errored dispatch (F3), and a probe permanently refused by the work budget (F6). Adding those three tests would also catch the bugs rather than encoding the zero pricing (F1).


Open questions / could not establish

  1. Is the linked defect an upstream defect at all? #534's premise was rebutted twice in-thread (mark-yong, 2026-11-28: the deadlock reproduces only on the AzallazA/hyperflare-inference fork carrying PrefillTailMerge; flare-autobot, 2026-11-30: "does not reproduce in NVIDIA/hyperflare-inference on origin/main at c146d7be", recommending closure). #655 addresses neither and supplies no cold-boot upstream reproduction — only the three other scenarios, which are well-evidenced live A/B. The correctness findings above stand on their own regardless of how #534 is adjudicated.
  2. Is the zero-priced first probe intentional? No rationale appears in the code, the doc, or the description; whether operators size off flare_checkpoint_extra_work_nanoseconds_total was not determinable.
  3. Should the probe be stamped on completion rather than allocation? Not discussed anywhere; F3 argues yes.
  4. Simulator counterpart: scripts/scheduling_sim was not opened in this review; nothing in the repository appears to model the checkpoint/unknown_cost/probe gate, so the qualified-policy comparison docs/design-review.md:195-208 asks for may not be computable without adding that model first.
  5. Interaction with open draft #301 (persist learned graph costs across restarts), which edits the same Estimate/prepared and would cure only the unmeasured warm-restart case while leaving the stale branch load-bearing: neither PR cites the other, so a textual rebase is expected.
  6. No maintainer position exists on this class of fix — zero comments, zero reviews, zero labels on #655 at review time.