Correctness, Contracts & System-Level Consequences — PR #665 (helios: add scan-resistant dual-turnover prefix cache eviction), head c9197427
Key findings
- Blocker (report as Major-high): the "reuse-protected" promotion gate is only half applied.
publish_with_retention'sExistingbranch callstouch_hitunconditionally (helios/src/cache.rs:481-491, hit at:485), whilefinish_inboundgates onlyPublishResult::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). - Major: the same hole exists on the completion path.
retirepublishes before it consultsrequest.preempted(helios/src/scheduler.rs:3097vs:3101-3106), so a preempted request's duplicate terminal publication promotes the entry even though the recency refresh at:3111-3113is correctly suppressed. - Major:
docs/prefix-cache-offload.mdnow contradicts itself on victim ordering. The PR added the two-tier rule at:298-303and left the superseded flat order at:374-377; the stale passage is the one an operator meets last, and it points at a section ofcore-design.mdthis PR rewrote (docs/core-design.md:1536-1584). ViolatesAGENTS.md:52-60. - Major: the mutation gate still covers none of the new safety guards.
verification/helios-lifecycle/check.pycontains no occurrence ofis_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 twohelios/src/cache.rsmutants are pre-existing (check.py:511-520). The reported "26/26 Rust KILLED" therefore evidences the old guards only, againstdocs/design-review.md:226-228and:247-251. - Minor: an unenforced invariant.
demote_expired_reusedages 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 missingif !node.ready { continue; }. - Minor: new O(all-nodes) walk on the admission/decode hot path per retirement (
cache.rs:620-626,:672-675), amplified insidesimulate_snapshot_quote's repeated whole-cache clones. - Minor: the A/B evidence predates all the hardening. The
1.89x/1.74xhit ratios were measured ona7568c2c; 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. - Cleared (stated as sound, not invented issues):
ready_tail_pagesbookkeeping incl. thestats()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 thefresh_admissionwiring.
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:
- Waiterless restore.
ticket.fresh_admissioncan be true whileticket.waitersis empty; that case is what:1888-1889'selseis for. On theExistingbranch it is bypassed, so a host-store restore with no living waiter still promotes. - Preempted re-admission. The comment at
scheduler.rs:3109-3111("Preemption and cancellation before inference must not advance cache recency") is honoured fortouchbut not for theExistingpromotion.
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
- No new lock or serialization point: all new state is plain fields on
Cache/Tickettouched under the existing&mut selfscheduler ownership. - No unbounded retention: no new map or vector grows with request count; the new counters are two
u64s (cache.rs:216-223) and per-node stamps. - No failure blast radius:
touch_hitreturnsResultand both new call sites propagate with?(cache.rs:485,scheduler.rs:1887); the failure path infinish_inboundalready funnels throughfail_ticket(scheduler.rs:1860-1863) and no new error can strand a waiter —PublishResult::Existingstill frees pages and releases the snapshot (:1868-1870). - No common-path slowdown from ordering:
is_protectedonly changes the key ofmin_by_key(cache.rs:762), it is not a filter, soevict's loop (:789-805) andeviction_candidate_within_budget's budget filter (:749-761) terminate exactly as before and cannot return "no victim" where they previously found one..unwrap()onevict_checkpoint(cache.rs:796) stays safe for the same reason. ready_tail_pagesbookkeeping is correct: every mutation paired — count (cache.rs:263), uncount (:274), unready→ready inadvance_completed(:890), and compaction transfer ofmoved_pagesinto a ready heir (:669-671);node.readyis only ever assigned once false→true (:889), andtail_pageschanges only at creation (:507) and incompact_ancestor(:663). The horizon is captured beforeuncount(:616-619,:644-646), which is the correct order. The#[cfg(test)]full-scan assertion instats()(cache.rs:913-932) makes any future drift fail the whole suite.- Metric span check: no rate/latency/admission metric's sampled span changed.
snapshot_publications(scheduler.rs:1885) is still incremented only forCreated, so the publish metric does not silently absorb duplicate publications; the new counters are internal horizons, not reported rates.touchusesmax(cache.rs:395) andTicket.demand_epochstarts at 0 (scheduler.rs:1696), sotouch_hit(id, 0)cannot moveaccessedbackwards. Existingis not a self-promotion:publish_with_retentionrejectstail_tokens == 0(cache.rs:454-463) before consultingself.prefixes, andpublish_boundaryadvancesrequest.prefix_tokensonCreated(scheduler.rs:2966-2967), so reachingExistingrequires genuine cross-request reuse. The problem is F1's scope, not a one-request lifecycle.- Sticky demotion genuinely closes the old blocker:
is_protectedreads onlynode.reused(cache.rs:351-355), so growth inready_checkpoints/ready_tail_pagescan no longer re-promote a demoted node;sticky_demotion_does_not_reprotect_after_fresh_publications(cache/tests.rs:1472-1568) proves it, andcompact_ancestoraging with the2xsnapshot-bound branch (cache.rs:363,:370-372) is covered bycompaction_pressure_ages_out_stale_protected_entry_without_page_evictions(cache/tests.rs:1569-1630).
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:
self.touch_hit(id, use_epoch)?→self.touch(id, use_epoch)?atcache.rs:485(F1's guard).self.is_protected(parent) &&removed atcache.rs:494(inheritance).node.reused = false;→()atcache.rs:373(sticky demotion).min_by_key(|(node, _)| self.eviction_key(node))→(node.retention_rank(), node.id)atcache.rs:762(the core ordering).ticket.fresh_admission &&removed atscheduler.rs:1886.
4. Tests & Claim Accuracy
- Coverage of new code paths:
Created-path promotion is covered (scheduler/tests.rs:3233fresh admission protects a restored checkpoint,:3258cancelled/preempted re-admission stays probationary);Existing-path promotion is not (F1), including the completion variant (F2), even thoughscheduler/tests.rs:2914already constructs theExistingsituation forfinish_inbound.policy_regime_shift_ages_out_reused_old_large_documents_for_newer_chat_workload(scheduler/policy_tests.rs:6430) covers the regime-shift case. Demotion under compaction pressure is covered (cache/tests.rs:1569). Nothing covers unready inheritance (F3) — acceptable given it is unreachable, but the invariant is therefore unpinned. Fixture::key(): the BFS dedup collision is genuinely fixed — the new tail (helios/src/cache/lifecycle_tests.rs:499-526) appends per node, ineviction_keyorder, the semantic id, a reused flag and both elapsed turnovers;projection()(:316-353) is untouched soCacheOwnership.tla's 29-integer tuple still matches (check.py:27-28), andFixture::forkcopies the new fields (:76-98). Residual, very low: two states with equal elapsed turnover but different absolute counters still collapse — deliberate, since the policy reads only differences.- Claim accuracy: the doc-sync claim holds for
core-design.md:1536-1600andscheduling-runtime-design.mdbut not forprefix-cache-offload.md(F6), and the "preempted re-admissions and waiterless restores refresh demand recency only" claim is not true of the shipped code (F1/F2). The "zero-knob, no flags/floats/unsafe/model branches" claim checks out: the diff adds nounsafe, no float arithmetic (all horizons are integer/page counts), and no per-model branch. No PR numbers were added into the docs (repo style; not a defect). - Unverifiable in this environment: no CI status is visible for
c9197427, and I could not runcheck.py,cargo test, or any A/B. Every claim above comes from reading the files at headc9197427plus the recorded greps.
Open questions
- Is
Existing-path promotion intended (the prefix genuinely resides and is being reused) — and if so, why gate only theCreatedbranch and write the offload doc in absolute terms? The asymmetry is untested either way. - Which of
prefix-cache-offload.md:298-303and:374-377was meant to survive the sync? Nothing in the PR body says. - Will a future
--mutationsrun coveris_protected/demote_expired_reused/eviction_key? As written the design-review safety-guard requirement is unmet for all new code. - How do the reported hit ratios move on the hardened head, given the
2xsnapshot-bound demotion and tightened restore gate only remove protection? - Does #549 (open, edits the same
Checkpointfield blockcache.rs:84-86,Fixture::forkandFixture::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.