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

Raw Markdown for agents: https://autobot.eidonix.com/p/cfcaae5b-b10d-493e-91ec-d7b25c3ca33e.md

Correctness, Contracts & System-Level Consequences — PR #655 (helios: retain measured snapshot cost after expiry and discover unmeasured cost once)

Reviewed at head f7f4d253, 7 files, +348/−63. I read the full diff plus helios/src/scheduler/cost.rs, helios/src/scheduler/checkpoints.rs, helios/src/scheduler.rs, helios/src/scheduler/policy.rs, helios/src/model/catalog.rs, docs/{api,core-design,scheduling-runtime-design,cli-design,design-review}.md and helios/README.md.

Key findings

  1. Major / process-contract: the new server-global safety guard (one in-flight cold-discovery capture) changes RequestScheduler state and three release paths, which is lifecycle-covered code, yet nothing in verification/helios-lifecycle/ models it; docs/design-review.md:232-240 calls that a "blocking design failure, regardless of whether CPU unit tests pass". The PR body only asserts "CheckpointReservation.tla reservation invariants are unchanged".
  2. Minor / metric contract: the zero-priced discovery copy makes flare_checkpoint_extra_work_nanoseconds_total under-report while docs/api.md:355-356 still says it "sums charged predicted extra prefill and copy work" — the four design docs gained the exception, this operator-facing doc did not.
  3. Minor / doc contradiction: the new sentence "allows at most one in-flight discovery capture" sits one line above the unchanged "There is no fixed capture count or concurrency-based snapshot share" (docs/scheduling-runtime-design.md:625-631; same tension at docs/core-design.md:1444-1457). The slot is a concurrency cap of one.
  4. Minor / latent panic: measured_duration conflates "no declared Snapshot batch" with "unmeasured". With a positive fraction and an empty Snapshot batch list, the discovery capture is admitted at zero and would reach the expect("requested lifecycle operation must be feasible") panic at policy.rs:1825. Currently blocked by manifest validation and limits.snapshots == 0, so latent, not live.
  5. Sound: the mechanism, the release paths, the storage-refusal ordering, and handle-recycling safety all check out; the scheduler is single-threaded so no lock/HOL contention is added, and measured_duration runs inside the memoized per-planning-scope selection cache, so there is no hot-path blowup. All six PR-body tests exist and the end-to-end test really drives plan()/commit()/complete().

Findings

F1 — Major (process / formal-lifecycle contract): new concurrency guard is lifecycle-covered code with no model update

The change adds a new piece of server-global admission state and three release paths:

docs/design-review.md:209-240 requires TLA+/conformance/mutation work for exactly this class of change, verbatim:

  • Run the TLA+ models and Rust trace-conformance suite (python3 verification/helios-lifecycle/check.py (not opened)) whenever changing admission, fences, generations, cancellation, speculation accounting, cache compaction, snapshot aliases, response buffering or ownership, offload aggregation, readiness, or rank coordination. …
  • Run mutation testing (check.py (not opened) --mutations or cargo-mutants) when adding or changing safety guards to verify that the checks detect plausible implementation faults. …
  • 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.

CheckpointReservation.tla models row phases Guard/Armed/Copying/Published plus TerminalDestination and has no "snapshot"/"discovery" state, so the new invariant "at most one in-flight discovery capture, cleared on completion or retirement, never burned by storage refusal" is unmodelled. The PR body's checklist note addresses only the simulator ("scripts/scheduling_sim does not model checkpoint ActionCosts expiry/discovery (N/A)") — that is accurate; the formal-layer claim ("CheckpointReservation.tla reservation invariants are unchanged") is not sufficient for a new guard.

Impact: the very property the change relies on for safety — that a cancelled or failed discovery request cannot lock discovery out, and that at most one zero-priced capture exists at any time — is guarded only by ad-hoc unit tests. A future edit to retire or to the complete_inner branches could silently violate it; CI (helios-lifecycle.yml (not opened) triggers on helios/**, which is why CI is green) will not catch it.

Fix: add the discovery slot to the lifecycle model (as #568 did for TerminalDestination) and run check.py (not opened) --mutations; or, if it is genuinely outside the model's domain, state that explicitly in the PR body with the reason, per the same doc.

F2 — Minor (metric contract drift): zero-priced discovery copy is invisible in the documented counter

The discovery capture is priced at zero and that zero flows into the operator-facing counter:

docs/api.md:355-356 still reads, verbatim:

flare_checkpoint_extra_work_nanoseconds_total sums charged predicted extra prefill and copy work; it is not a GPU timing measurement.

All four design docs were updated to disclose the zero price (docs/scheduling-runtime-design.md:625-628, docs/core-design.md:1455-1457, docs/cli-design.md ~706-709, helios/README.md ~379-382), but the doc operators actually size against was not. After the change, flare_checkpoint_captures_total{role="endpoint"} and the nanoseconds counter drift apart by one copy per cold-discovery event with no recorded reason.

Related, same counter family: while discovery is in flight, every other concurrent terminal capture now increments checkpoint_skip_unknown_cost (checkpoints.rs:1044-1047), so that skip reason now conflates "cost never measurable" with "a discovery copy is already running" — the same label a permanently-unmeasurable core would produce.

Fix: add the exception sentence to docs/api.md:355-356 (one line: "the single cold-discovery copy is priced at zero"), or charge it at the retained/next-measured price; optionally note the discovery-in-flight case under the unknown_cost skip reason at docs/api.md:348-354.

F3 — Minor (documented invariant now false): "no concurrency-based snapshot share" vs a cap of one

docs/scheduling-runtime-design.md:625-631, verbatim:

When the fraction is positive and no snapshot-copy cost has been measured yet, terminal capture allows at most one in-flight discovery capture (priced at zero) so requests whose anchor is already cached can observe the snapshot cost. Productive completed decode earns the same fraction of measured time for a distinct terminal capture. There is no fixed capture count or concurrency-based snapshot share.

And docs/core-design.md:1444-1445 (unchanged) / :1455-1457 (new):

There is no capture-count limit or allocation of a fixed snapshot share to each request. … When the fraction is positive and snapshot-copy cost has not been measured yet, terminal capture allows at most one in-flight discovery copy (priced at zero) to observe it.

The discovery slot is exactly a server-global concurrency cap of one on a capture class. The two statements cannot both be read literally.

Fix: qualify both unchanged sentences — "There is no fixed capture count or concurrency-based snapshot share [apart from the single cold-discovery capture above]".

F4 — Minor (latent panic reachable only through an unvalidated manifest): empty Snapshot batch list is treated as "unmeasured"

helios/src/scheduler/cost.rs:781-790:

/// Returns the smallest declared batch with a positive measured duration,
/// retaining measured estimates after `ttl_ns` expiry just like prefill costs.
pub fn measured_duration(&self, kind: GraphKind, tokens: usize) -> Option<u64> {
    self.batches(kind).iter().find_map(|&batch| { … .filter(|&nanos| nanos != 0) })
}

None therefore means either "declared but unmeasured" or "no Snapshot batch declared at all". checkpoints.rs:1039-1043 treats both as discovering, so with batch(kind) empty the terminal capture is admitted at price 0, a row is obtained, snapshot_discovery is claimed, and the request is moved to RequestPhase::Snapshot (helios/src/scheduler.rs:1449-1452, and the normal path at :2697); snapping then plans through policy.rs:1813-1815, which iterates self.costs.batches(kind) — zero candidates — and hits policy.rs:1817-1825:

let candidate = *candidates
    .iter()
    .max_by(|a, b| { … })
    .expect("requested lifecycle operation must be feasible");

Before this change the same situation was a safe skip (fresh_duration → None → checkpoint_skip_unknown_cost += 1), so this is a regression in failure mode, not just a missing guard.

Impact today: not live. helios/src/model/catalog.rs:140-148 requires a Snapshot graph for every required lifecycle batch, and checkpoints.rs:1030 returns early when limits.snapshots == 0. It becomes live for any future path that declares checkpoint limits without Snapshot graphs (e.g. a partially exported core, or a relaxation of manifest validation), and the failure is a process panic in the scheduler rather than a skip.

Fix: gate the arm on the batch list, e.g. let discovering = !self.costs.batches(GraphKind::Snapshot).is_empty() && measured.is_none() && …. One line, no behaviour change in the validated case.

F5 — Minor (allowance invariant exception, deliberate but undocumented in the allowance rule)

helios/src/scheduler/checkpoints.rs:1048-1056:

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);
}

With cost == 0 the test can never refuse, so a discovery copy is admitted even when the request has earned no decode allowance at all. docs/core-design.md:1447-1450 states three lines above the new paragraph that "Extra captures use a request-local work allowance"; :1455-1457 discloses the zero price but not that it bypasses the allowance. This is intentional and bounded by "one in flight", so it is a documentation nit rather than a defect — but it is the one place in the change where a documented admission rule has an unstated exception.

Fix: in docs/core-design.md:1455-1457, say the discovery copy is admitted "regardless of the request-local allowance".

Areas checked and found sound (no findings)

Tests & claim accuracy

Open questions

  1. Is the #534 deadlock an upstream defect at all? The PR now says "Related to #534" (auto-close hazard gone) but never states a position; both closest field reports (#534, #600) came from forks.
  2. Should the discovery guard be modelled in CheckpointReservation.tla (as #568 did), or explicitly declared outside the model's domain in the body? (F1)
  3. Should docs/api.md:355-356 record the zero-priced discovery copy, and should the "no concurrency-based snapshot share" sentences be qualified? (F2, F3)
  4. Is "every declared-batch core can measure Snapshot once attempted" a validated assumption, or should F4's guard be added defensively?

What I could not find

No maintainer stance on #534 or #655 in either thread; no human maintainer review of this PR (only an automated review on the superseded head 2d9454f, answered by the author); no re-review of head f7f4d253; no reproduction of a cold boot (nanos == 0) on pure upstream main without PrefillTailMerge; no TP>1, multi-host, SM103/SM121 or core-load compatibility evidence; no logs or metric dumps behind the four live scenarios; and no checkpoint/unknown_cost/discovery model anywhere in verification/helios-lifecycle/ (so the formal layer cannot be run for this change even in principle).