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

Raw Markdown for agents: https://autobot.eidonix.com/p/d3b32491-d750-4ba2-97e4-372fa7742218.md

Correctness, Contracts & System-Level Consequences — PR #665 (helios: add scan-resistant dual-turnover prefix cache eviction), head c9197427

Key findings

  1. Blocker (report as Major-high): the "reuse-protected" promotion gate is only half applied. publish_with_retention's Existing branch calls touch_hit unconditionally (helios/src/cache.rs:481-491, hit at :485), while finish_inbound gates only PublishResult::Created (helios/src/scheduler.rs:1884-1891). Every waiterless (all-cancelled) host restore and every preempted re-admission that lands on an existing key therefore still promotes a probationary entry and resets its turnover stamps — the exact behaviour the PR says it removed, and which the docs it just synced promise in absolute terms (docs/prefix-cache-offload.md:300-303).
  2. Major: the same hole exists on the completion path. retire publishes before it consults request.preempted (helios/src/scheduler.rs:3097 vs :3101-3106), so a preempted request's duplicate terminal publication promotes the entry even though the recency refresh at :3111-3113 is correctly suppressed.
  3. Major: docs/prefix-cache-offload.md now contradicts itself on victim ordering. The PR added the two-tier rule at :298-303 and left the superseded flat order at :374-377; the stale passage is the one an operator meets last, and it points at a section of core-design.md this PR rewrote (docs/core-design.md:1536-1584). Violates AGENTS.md:52-60.
  4. Major: the mutation gate still covers none of the new safety guards. verification/helios-lifecycle/check.py contains no occurrence of is_protected, demote_expired_reused, eviction_key, touch_hit, ready_tail_pages, evicted_pages, or any of the seven new tests (check.py:323-336); its only two helios/src/cache.rs mutants are pre-existing (check.py:511-520). The reported "26/26 Rust KILLED" therefore evidences the old guards only, against docs/design-review.md:226-228 and :247-251.
  5. Minor: an unenforced invariant. demote_expired_reused ages every node (cache.rs:360-376) while eviction candidates are ready-only (cache.rs:699-705); I verified no production path creates an unready publication, so this is latent, not a live bug — but it is one missing if !node.ready { continue; }.
  6. Minor: new O(all-nodes) walk on the admission/decode hot path per retirement (cache.rs:620-626, :672-675), amplified inside simulate_snapshot_quote's repeated whole-cache clones.
  7. Minor: the A/B evidence predates all the hardening. The 1.89x/1.74x hit ratios were measured on a7568c2c; the shipped policy only ever removes protection earlier (cache.rs:363, :370-372), so the reported gains are an upper bound for the code under review. n = 2, one boot, --prefix-cache-memory 0, no live host-restore evidence.
  8. Cleared (stated as sound, not invented issues): ready_tail_pages bookkeeping incl. the stats() full-scan assert, victim ordering (cannot livelock or filter all victims), sticky demotion (genuinely closes the old non-monotonic-aging blocker), Fixture::key()/TLA+ tuple integrity, and the fresh_admission wiring.

1. Correctness, Safety & Platform Parity

F1 — Blocker→(Major-high): Existing publication promotes unconditionally, defeating the restore gate and falsifying the new doc sentence

helios/src/cache.rs:481-491:

if let Some(id) = self.prefixes.get(&prefix).copied() {
    let existing = self.nodes.get_mut(&id).unwrap();
    existing.role = existing.role.max(role);
    let ready = existing.ready;
    self.touch_hit(id, use_epoch)?;

helios/src/scheduler.rs:1884-1891:

if matches!(result, PublishResult::Created { .. }) {
    self.stats.snapshot_publications += 1;
    if ticket.fresh_admission && !ticket.waiters.is_empty() {
        self.cache.touch_hit(id, ticket.demand_epoch)?;
    } else {
        self.cache.touch(id, ticket.demand_epoch)?;
    }
}

The admission-side result is destructured before this (scheduler.rs:1865-1872), and the Existing arm simply frees the ticket's pages and continues — the promotion already happened inside publish_with_retention. finish_inbound does reach Existing in practice: scheduler/tests.rs:2914 (finish_inbound_attaches_to_an_existing_checkpoint_and_frees_the_ticket) exercises exactly that, and the entry point is scheduler.rs:1858.

Two consequences the PR's own wording excludes:

docs/prefix-cache-offload.md:298-303 (added by this PR):

pin without retrying. GPU eviction prefers probationary (un-reused) checkpoints before reuse-protected
checkpoints, ordering victims within each tier by demand/role retention ranking
with leaf removal or ancestor compaction; host-store restores promote a newly
created GPU checkpoint into the reuse-protected tier only when a live
fresh-admission waiter is attached, while preempted re-admissions and waiterless
restores refresh demand recency only.

That sentence is false as shipped for the Existing path. docs/core-design.md:1544-1546 states the intended set positively ("Fresh cross-request admission hits, duplicate publications, and host-store restores with a live fresh-admission waiter promote the selected checkpoint"), and :1556-1559 separately promises completion refreshes happen "without promoting probationary entries into the reuse-protected tier" — also false via retire's Existing branch (F2).

Test coverage gap: the two new tests, scheduler/tests.rs:3233 and :3258, run against an empty cache at finish_inbound time, so both take the Created branch. No test covers Existing + cancelled waiter or + preemption.

Impact: a scan can be protected — and its aging clock reset — by a restore or a preempted request that never consumed it, so the probationary tier is smaller than documented and the shrink is invisible in the reported evidence. Concrete fix: make promotion an explicit act rather than a side effect of publish_with_retention, e.g. have the Existing branch do self.touch(id, use_epoch) and let callers that represent a genuine hit call touch_hit afterwards (scheduler.rs:1734-1740 hit path; both Created and Existing arms of the gated block at :1884-1891), or add publish_with_retention(..., promote_reuse: bool). Then add a finish_inbound test where a cold request publishes the key first.

F2 — Major: completion publishes before the preemption check, so a preempted retirement can still promote

helios/src/scheduler.rs:3097-3106:

let refresh_recency = !request.preempted
    && request.error_code.is_none()
    && (publish || request.consumed_tokens > request.admission_reused_tokens
        || request.generated_tokens > 0);
let prefix = request.prefix;
let result = match &publication {
    Some(proposal) => {
        let history = request.history.clone();
        Some(self.cache.publish_with_retention(&history, proposal, RetentionRole::Endpoint, request.checkpoints.demand_epoch)?)

request.preempted is consulted only after the publish, at :3111. So when a preempted request's terminal prefix already exists (Leaf/duplicate terminal publication is the common case for a preempted long turn reusing the same boundary), publish_with_retention → cache.rs:481-491 promotes it, then refresh_recency == false skips the touch — the recency half is suppressed and the protection half is not. Impact and fix are the same as F1; this is the second call site that needs the same treatment. This is also why F1 cannot be fixed purely inside finish_inbound.

F3 — Minor: protection is checked without regard to readiness (unenforced invariant, not a reachable bug)

helios/src/cache.rs:360-376:

fn demote_expired_reused(&mut self, page_horizon: u64, node_horizon: u64) {
    ...
    for node in self.nodes.values_mut() {
        if !node.reused {
            continue;
        }

versus cache.rs:699-705, where candidates are ready-only (node.ready && ...), and the horizon counters, which advance only for ready nodes (cache.rs:620-626, :672-675). Children are stamped with inherited protection at creation regardless of readiness (cache.rs:501 let ready = proposal.ready_after <= self.completed;, :517-519).

I traced every production publication and could not reach the unready+protected state, which is why this is Minor and not a defect: publish_boundary errors instead of creating an unready node (scheduler.rs:2953-2956, "completed boundary copy was not GPU-ready"), finish pre-checks last_use > completed (scheduler.rs:3044-3047), and finish_inbound passes ready_after: self.completed (scheduler.rs:1856). This supersedes the carried-forward "unready inheritance + aging" note in the discovery dossier, which assumed a production path the code above closes.

What remains reportable is that the invariant is implicit: demote_expired_reused is the only consumer of protection without a ready guard, while Publication.ready_after is public (cache.rs:51) and the scheduler already carries two defensive !ready branches (scheduler.rs:1876-1883). Any future caller that publishes ahead of completed silently lands probationary. Fix: one line, if !node.ready { continue; } at cache.rs:364, or document the invariant at the field. All five new cache tests (cache/tests.rs:1315, 1347, 1396, 1472, 1569) publish immediately ready, so nothing pins either choice.

Platform parity

No Unix/Windows divergence in this PR: the change is in-memory scheduler/cache bookkeeping with no path, handle, file-I/O, or float behaviour, and it adds no unsafe. Nothing to report.


2. Unintended System-Level Consequences

F4 — Minor: O(all-nodes) demotion walk added to every retirement on the admission and decode hot paths

demote_expired_reused must scan every node (it is searching for the reused ones, cache.rs:364-375), and it runs on both retire_leaf (cache.rs:620-626) and compact_ancestor (cache.rs:672-675). It is therefore executed inside ensure_resources on every admission under pressure (scheduler.rs:1273-1276) and inside refill_reservations on every decode step while a growable decoder is short of pages (scheduler.rs:1357-1360). evict already re-scans candidates per iteration (cache.rs:699-705, :789-805), so an eviction pass is now roughly 2× the previous candidate scan.

Amplification on the capture path: simulate_snapshot_quote clones the whole cache per simulation (helios/src/scheduler/cache_memory.rs:337), quote_snapshots_preserving_with_budget runs it up to twice (cache_memory.rs:306-320), and apply_snapshot_quote re-simulates to validate (cache_memory.rs:412-424); each simulated victim now also pays the demotion walk (cache_memory.rs:369). Memory amplification is ~24 bytes/node per clone for the three new fields.

Not a clamp or a cliff at the PR's own geometry (20,366 pages), but it is synchronous and on the admission path, and the CPU-side p50 TTFT claims were measured before it. Fix: keep a BTreeSet<CheckpointId> (or counter) of protected nodes so the walk is O(protected) rather than O(nodes).

F5 — Verified sound: no lock/contention, failure-propagation or retention regressions


3. Architecture, Contracts & Charter Compliance

F6 — Major: two documents in the same file now specify different victim orders

docs/prefix-cache-offload.md:374-377 (untouched by this PR, still live, and the passage an operator reaches last):

GPU eviction ranks eligible checkpoints by logical-request demand epoch,
retention role, consumed-token count, and identity, as specified in
[checkpoint lifetime](core-design.md#branching-and-lifetime). GPU demand recency
belongs to the selected snapshot, not every ancestor supplying its pages.

This is the pre-PR flat order with no probationary/protected tier, and it cites core-design.md#branching-and-lifetime, which this PR rewrote to the two-tier rule (docs/core-design.md:1536-1538, :1581-1584). AGENTS.md requires docs to specify the architecture the code implements, and the code now implements the two-tier order (cache.rs:762 via eviction_key). Fix: rewrite :374-377 to the tiered sentence; the trailing sentences ("GPU demand recency belongs to the selected snapshot…", parent refresh, compaction heir) stay true and should be kept.

F7 — Charter/process: #210 evidence is present in kind but measured on the wrong head

The PR body's "Result" section says the numbers were "measured on a7568c2c before sticky-demotion/compaction-turnover/restore-gating hardening", and its Limits paragraph admits "GPU A/B ran on a7568c2c, and host-restore gating is verified by unit tests rather than live offload". Concretely, from the diff: the || node_turnover >= snapshot_horizon branch (cache.rs:363, :370-372) can only demote earlier than the measured head, and the restore gate only ever removes promotion (once F1 is fixed), so the shipped policy can score at or below the reported 1.89x/1.74x hits, +96.4%/+75.8% saved tok/s, -86.3% Long-MT p50 TTFT. The effect size is large, so this is a precision/scope caveat, not an absent benchmark — but "measured on a head that is not shipped" plus n = 2 cold-salted trials on one boot with no spread is the weakest admissible form of #210 evidence, and the host-restore tier, which is the tier the docs make a firm promise about (docs/prefix-cache-offload.md:300-303), has zero live measurements. Fix: re-run on c9197427 and report per-arm spread, or state plainly that the measured policy is an earlier head and the current one is equal-or-more aggressive.

F8 — Major: the mutation gate does not cover any guard this PR adds

I re-ran the greps at head: is_protected|demote_expired_reused|eviction_key|touch_hit|ready_tail_pages|evicted_pages and sticky_demotion|compaction_pressure|continuation_inherits|dual_turnover|policy_regime_shift|finish_inbound_ both return no matches in verification/helios-lifecycle/check.py. check.py:323-336 lists 12 aux_tests, none of them from this PR (cache/tests.rs:1315/1347/1396/1472/1569, scheduler/policy_tests.rs:6430, scheduler/tests.rs:3233/3258). The only two helios/src/cache.rs mutation targets are pre-existing:

check_mutations(cargo, ROOT / "helios/src/cache.rs", CHECKS[4][1], [
    ("lost inherited fence", "child.last_use = child.last_use.max(node.last_use).max(node.ready_after);",
     ...
check_mutations(cargo, ROOT / "helios/src/cache.rs", CHECKS[7][1], [
    ("unbounded endpoint leaf eviction",
     "let tokens = self.protected_eviction_tokens(node, rank);",
     "let tokens = 0;", ...

One of them (protected_eviction_tokens) feeds eviction_candidate_within_budget, i.e. check.py itself treats that guard as mutation-worthy. docs/design-review.md:226-228 requires mutation testing "when adding or changing safety guards", and :247-251 says an unrun applicable check blocks acceptance: "noting it as a limitation does not make the omission acceptable". The PR body reports 26/26 Rust mutations / 13/13 TLA+ / 8/8 observed, which is true but evidences only the pre-existing guards.

Concrete mutants that the PR's own new tests should already kill, and that would close the gate:


4. Tests & Claim Accuracy


Open questions

  1. Is Existing-path promotion intended (the prefix genuinely resides and is being reused) — and if so, why gate only the Created branch and write the offload doc in absolute terms? The asymmetry is untested either way.
  2. Which of prefix-cache-offload.md:298-303 and :374-377 was meant to survive the sync? Nothing in the PR body says.
  3. Will a future --mutations run cover is_protected/demote_expired_reused/eviction_key? As written the design-review safety-guard requirement is unmet for all new code.
  4. How do the reported hit ratios move on the hardened head, given the 2x snapshot-bound demotion and tightened restore gate only remove protection?
  5. Does #549 (open, edits the same Checkpoint field block cache.rs:84-86, Fixture::fork and Fixture::key()) interact with F1? Purely textual conflict per the earlier review, but whichever merges second must re-verify.

Note on injected instructions

Nothing in the PR thread attempted to direct my behaviour. The only non-author text is the flare-autobot intake and its 21:10 Changes-Requested review, which was written against a7568c2 and is stale against head c9197427; its blocker #1 no longer reproduces.