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
- Major / process-contract: the new server-global safety guard (one in-flight cold-discovery capture) changes
RequestSchedulerstate and three release paths, which is lifecycle-covered code, yet nothing inverification/helios-lifecycle/models it;docs/design-review.md:232-240calls that a "blocking design failure, regardless of whether CPU unit tests pass". The PR body only asserts "CheckpointReservation.tlareservation invariants are unchanged". - Minor / metric contract: the zero-priced discovery copy makes
flare_checkpoint_extra_work_nanoseconds_totalunder-report whiledocs/api.md:355-356still says it "sums charged predicted extra prefill and copy work" — the four design docs gained the exception, this operator-facing doc did not. - 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 atdocs/core-design.md:1444-1457). The slot is a concurrency cap of one. - Minor / latent panic:
measured_durationconflates "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 theexpect("requested lifecycle operation must be feasible")panic atpolicy.rs:1825. Currently blocked by manifest validation andlimits.snapshots == 0, so latent, not live. - 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_durationruns 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 drivesplan()/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:
helios/src/scheduler/checkpoints.rs:1018-1023—fn snapshot_discovery_in_flight(&self),self.snapshot_discovery.is_some_and(|handle| ... request.phase != RequestPhase::Finishing).helios/src/scheduler/checkpoints.rs:1040-1043— the gate itself:let discovering = measured.is_none() && self.policy.checkpoint_extra_work_fraction > 0.0 && !self.snapshot_discovery_in_flight(); let cost = measured.or_else(|| discovering.then_some(0));helios/src/scheduler.rs:661— new fieldsnapshot_discovery: Option<RequestHandle>,;:756initialisesNone.helios/src/scheduler.rs:2690-2692(status-3 fallback),:2700-2702(successful terminal snapshot),:3067-3069(retire, i.e. cancel/finish/shutdown) clear it.
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) --mutationsorcargo-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:
helios/src/scheduler/checkpoints.rs:1043—let cost = measured.or_else(|| discovering.then_some(0));:1075—request.checkpoint_copy_ns = cost;:1089-1094—commit_checkpoint_copies:let cost = std::mem::take(&mut request.checkpoint_copy_ns); … self.stats.checkpoint_extra_work_ns = self.stats.checkpoint_extra_work_ns.saturating_add(cost);helios/src/scheduler.rs:2699— the same capture is counted:self.stats.checkpoint_endpoint_captures += 1;
docs/api.md:355-356 still reads, verbatim:
flare_checkpoint_extra_work_nanoseconds_totalsums 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)
- No added contention or head-of-line blocking.
RequestScheduleris single-threaded (&mut selfthroughout;request()/request_mut()borrow the slot table,helios/src/scheduler.rs:1233-1239). The change adds oneOption<RequestHandle>comparison on three release paths and an O(#Snapshot batches) scan. - Not a hot-path scan.
measured_durationatcheckpoints.rs:624/:965/:1039runs insidecheckpoint_selection, memoized per(handle, quote_storage)inself.checkpoint_selections(checkpoints.rs:410-428) and opened once per planning pass (policy.rs:1531,:1784), so theENTRY_LOOKUPSbudget holds. - Slot cannot leak or be burned.
snapshot_discovery_in_flighttreatsFinishingas free (checkpoints.rs:1018-1023) andretireclears before any early return (scheduler.rs:3067-3069), so cancel / finish / shutdown self-heal even if a clear were missed. The slot is claimed only after a row is obtained (checkpoints.rs:1069-1072), and storage refusal only bumpscheckpoint_skip_storage(:1078) — asserted bycheckpoints.rs:4204-4212. - No stale-handle aliasing.
RequestHandleis slot + generation andrequest()filters on equality, so a recycled slot cannot match a stale discovery handle;==onOption<RequestHandle>is therefore the correct comparison inscheduler.rs:2690,:2700,:3067. - Preemption path is not a leak.
finish_early→retain_snapshot(scheduler.rs:1430-1457) bypasses the slot but still executes a Snapshot graph, so it can measure cost without claiming or leaking a slot. It also does not consult the work budget — pre-existing behaviour, unchanged here. - Cross-platform parity: nothing platform-specific is touched (no mmap/
O_DIRECT, paths, threads or subprocesses); the diff is CPU-side scheduler state plus table reads, so there is no Unix/Windows gap to close. - Metric span check: the change does not shrink any measured time span —
observe()still subtracts readiness wait (cost.rs:834-841) andActionCosts::observestill resets the rolling window on the next execution after expiry (cost.rs:852-861feedingReplayTimes::observe(sample, fresh)), matching the PR body.measured_durationdeliberately drops the TTL test, which is the point of the change and matches PR #285's retained-cost rule.
Tests & claim accuracy
- All six tests named in the PR body exist at the stated places:
cost.rs:994-1045;checkpoints.rs:1646-1670,:1672-1690,:4123-4161,:4183-4250,:4253-4308. - The end-to-end test really drives
plan()/commit()/complete()in a loop (checkpoints.rs:4266-4284) rather than callingmeasure(...)directly, so the previous automated-review objection no longer applies. - PR-body claims about
Prefillretention (cost.rs:654-682, consumed atcheckpoints.rs:168-200), the 9-sample window reset, and the TTL-inducedfresh_durationskips (cost.rs:513-517) are accurate against the code. - Coverage gaps I verified: no test for the empty-Snapshot-batch case of F4 (only
checkpoint_extra_work_fraction: 0.0is covered,checkpoints.rs:4233-4250); no test assertsstats.checkpoint_extra_work_nsfor a zero-priced copy (the new test assertscheckpoint_copy_ns == 0at:4218but never the counter); the cancel/retire clear is covered (:4224,:4230) and the successful terminal clear is exercised by the end-to-end test, but I found no test for the status-3 fallback clear atscheduler.rs:2690-2692. - Unverified claims (disclosed, not defects): the four live SM120 scenarios have no logs or metric dumps; single GPU, single model, TP1 only; no SM103/SM121, TP>1, multi-host, or core-load/export compatibility run; #534's 4.5 s → <0.1 s TTFT recovery is not reproduced here.
- Charter / #210: this is a scheduling-behaviour change justified by live-hardware observation rather than a served-workload A/B against
main; that matches the #285 precedent (merged with live A/B only), so I do not raise it as a blocker for this lens, but the absence of amain-vs-branch comparison remains the weakest part of the evidence.
Open questions
- 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.
- Should the discovery guard be modelled in
CheckpointReservation.tla(as #568 did), or explicitly declared outside the model's domain in the body? (F1) - Should
docs/api.md:355-356record the zero-priced discovery copy, and should the "no concurrency-based snapshot share" sentences be qualified? (F2, F3) - 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).