Recommendation: Changes Requested
PR #665 proposes a clean, zero-knob, model-agnostic scan-resistant eviction policy (~68 net production LOC, no flags, floats, unsafe, or wire/core-format changes) in the right Helios cache/scheduler layer. However, two blocking issues prevent merge on head a7568c2: is_protected compares monotonic turnover against live growing cache counts so already-demoted checkpoints silently regain protection when new entries publish, and the PR omits the mandatory check.py --mutations verification gate while inaccurately claiming unit tests and TLA+ verify host-restore touch_hit. Several concrete should-fix items (snapshot-compaction turnover omission, preemption asymmetry in finish_inbound, stale design docs, and a BFS key() collision in lifecycle_tests.rs) and two clean subtractions also need resolution before merge.
Merge Risk
Level: Medium
- Blast radius on both GPU eviction paths:
eviction_key(helios/src/cache.rs:363-365, used at:732) alters victim selection for both mandatory reclamation (evict, called fromensure_resourcesathelios/src/scheduler.rs:1272andrefill_reservationsat:1356) and budgeted optional captures (eviction_candidate_within_budget, called fromsimulate_snapshot_quoteathelios/src/scheduler/cache_memory.rs:365). Mandatory eviction cannot livelock because protection only orders victims and does not filter them, andPrefixCheckpointCache::clonepreserves quote re-simulation determinism (cache_memory.rs:337, 412-424). - Eviction-stability regressions under workload shifts and snapshot pressure: Non-monotonic aging (
cache.rs:349-361) can re-protect stale entries when the cache refills or shifts toward smaller checkpoints, and omittingcompact_ancestor(cache.rs:626-657) from turnover leaves stale protected entries unaged under snapshot-only compaction pressure. - Hot-path, concurrency, and compatibility safety:
PrefixCheckpointCacheremains single-owner&mutstate with O(1), allocation-freeeviction_keyevaluation and saturating integer arithmetic; no locks, buffers, core-format fields, or exported-core compatibility changes are introduced.
Walkthrough
helios/src/cache.rs(+64/−4): Addsreused,reused_at_evicted_pages, andreused_at_evicted_nodestoCheckpoint(:84-86) and cumulativeevicted_pages/evicted_checkpointscounters toPrefixCheckpointCache(:221-222), incremented only for ready leaves inretire_leaf(:604-609). Addsis_protected,eviction_key,mark_reused, andtouch_hit(:349-389); promotes duplicate publications (PublishResult::Existing) viatouch_hit(:471); inheritsreusedwhen the parent is protected andparent_len * 2 >= tail_tokens(:478-481, :503-505); and orderseviction_candidate_within_budgetbyeviction_key((is_protected, retention_rank, id)) at:732.helios/src/scheduler.rs(+9/−1): Gates admission reuse promotion inadmit_planned_with_checkpoint_accountingonfresh_admission = accounting.is_none()(:1727-1740) so first-time GPU hits calltouch_hitwhile preemption re-admissions call plaintouch; addsself.cache.touch_hit(id, ticket.demand_epoch)?onPublishResult::Createdinfinish_inbound(:1884-1887). Completion recency refresh inretire(:3107-3118) stays on plaintouch.helios/src/cache/lifecycle_tests.rs(+6/−1): Copies the new fields inFixture::fork(:79-81, :96-97) and switchesFixture::key()'s relative-order sort toself.cache.eviction_key(node)(:502).helios/src/cache/tests.rs(+192/−0): Adds four isolated cache-level unit tests covering scan-vs-reused eviction (:1315-1345), inheritance ratio (:1347-1394), dual-turnover demotion (:1396-1470), andreclaimable_if_pinnedparity (:1472-1504).
Pre-merge Checks
- [PASS] Security / malicious screen: Pure in-memory cache victim-ordering logic with saturating integer arithmetic; no external input parsing,
unsafe, or privilege surface added. - [PASS] Charter & value fit: Right Helios runtime layer, zero flags/knobs, zero per-model branches, no core-format changes, and four-part PR description with served A/B benchmarks against
5d53040e; documentation updates are missing (tracked in Should Fix). - [WARN] Related / duplicate / conflict check: Genuinely additive over #568, but revises #568's strict demand-recency ordering and #298/#416's completion refresh without citing them; guaranteed textual conflict with open PR #549 in
helios/src/cache.rs:81-87, 216-223andhelios/src/cache/lifecycle_tests.rs:76-98(no semantic conflict). - [WARN] Tests & verification evidence: Mandatory
check.py --mutationswas not run (docs/design-review.md:226-228, 247-251), the claim that unit tests and TLA+ verify Selene/host-restoretouch_hitis inaccurate, CI status is not visible in this environment, and A/B benchmarks aren = 2trials/arm on one boot with--prefix-cache-memory 0and no variance reported.
Blockers
- Non-monotonic
is_protectedaging re-protects stale demoted checkpoints without a new hit (helios/src/cache.rs:346-361,:257-274,:604-609).is_protectedchecks!(page_turnover >= self.tail_pages.max(1) as u64 && node_turnover >= self.ready_checkpoints.max(1) as u64)against liveself.tail_pagesandself.ready_checkpoints, both of which grow on every publication (count()at:257-264). Once a stale checkpoint demotes (is_protected == false), any subsequent publication that raisestail_pagesorready_checkpointsabove the node's turnover flipsis_protectedback totruewithout a second reuse hit.- Concrete proof in the PR's own test geometry (
helios/src/cache/tests.rs:1447-1467): after the 3rd leaf eviction (evicted_pages = 6,evicted_checkpoints = 3,tail_pages = 2,ready_checkpoints = 2),staleis demoted. If two fresh 1-page checkpoints publish before the next eviction instead of one (tail_pages = 4,ready_checkpoints = 4),node_turnover = 3 < 4silently re-promotesstaleto protected soevictdrops fresh work instead. The same dynamic inflates the aging horizon during a workload shift from a few large sessions to many small checkpoints. (Secondary asymmetry:self.tail_pagescounts both ready and unready checkpoints at:263, whereasevicted_pagescounts onlynode.readyleaves at:604-609.) - Fix: Make demotion sticky once reached — e.g., clear
node.reused = falseon any expired nodes when turnover advances inretire_leaf(or evaluate against a monotonic bound that cannot re-enable already-demoted nodes, taking care not to freeze a near-empty warmup count atmark_reusedtime). Add a regression test inhelios/src/cache/tests.rsthat publishes multiple fresh checkpoints after demotion and asserts the demoted entry stays probationary.
- Missing blocking
check.py --mutationsrun and inaccurate verification claim for host restore (docs/design-review.md:226-228, 247-251,helios/src/scheduler.rs:1884-1887,verification/helios-lifecycle/check.py:515-520).docs/design-review.md:226-228and:247-251require runningpython3 verification/helios-lifecycle/check.py --mutations(orcargo-mutants) whenever adding or changing safety/eviction guards, and explicitly state that leaving an applicable CPU check unrun blocks PR acceptance.check.py:515-520directly guardseviction_candidate_within_budget, whose victim ordering this PR modifies, yet onlycheck.py --jobs 4is reported.- Additionally, the PR description claims "Selene restore
touch_hitis verified by unit tests and TLA+, not live offload", which is unsupported: none of the four added tests (helios/src/cache/tests.rs:1315-1504) invokesfinish_inbound, none of the existingfinish_inboundtests (helios/src/scheduler/tests.rs:2914-3208) asserts reuse protection or eviction ordering after restore, andCacheOwnership.tla(verification/helios-lifecycle/README.md:240-241) models neither host restore nor retention/eviction ranking. - Fix: Run
python3 verification/helios-lifecycle/check.py --mutationsand report its result; add a unit test inhelios/src/scheduler/tests.rsexercisingfinish_inboundand asserting protection/eviction order against an un-reused scan; and update the PR description so its evidence claims accurately reflect what was tested.
Should Fix
compact_ancestornever advances turnover counters, preventing aging under snapshot-only compaction pressure (helios/src/cache.rs:626-657vs:601-609,:749-753).- Under snapshot-row pressure (when KV pages are not exhausted),
evict_checkpointretires single-child interior ancestors viacompact_ancestor(freeing 1 snapshot and 0 pages) without incrementing eitherevicted_checkpointsorevicted_pages. Stale protected entries therefore never age out when eviction pressure is absorbed by ancestor compaction, and even alongside leaf evictions compacted checkpoints never advancenode_turnover. - Fix: Count compacted ready snapshots in turnover (and ensure snapshot-pressure turnover can age out stale protected entries rather than stalling indefinitely on
page_turnover == 0), and add a compaction-aging test inhelios/src/cache/tests.rs(plus a regime-shift check with reused Phase-1 documents inhelios/src/scheduler/policy_tests.rs).
- Under snapshot-row pressure (when KV pages are not exhausted),
- Preemption and cancelled-waiter asymmetry on host restore (
helios/src/scheduler.rs:1884-1887vs:1727-1739).- For GPU hits,
admit_planned_with_checkpoint_accountinggatestouch_hitonfresh_admission = accounting.is_none()(scheduler.rs:1727, 1735) so preempted re-admissions refresh recency only. Infinish_inbound(scheduler.rs:1884-1887),PublishResult::Createdunconditionally callsself.cache.touch_hit(id, ticket.demand_epoch)?even when the ticket's only waiter was a preempted re-admission (helios/src/server/runtime.rs:3158passesaccounting.clone()) or all waiters were cancelled before transfer completion (ticket.waiters.is_empty(), as inscheduler/tests.rs:2976, 3152). - Fix: Record
fresh_admission: boolonTicket(set/ORed atscheduler.rs:1686-1709) and calltouch_hitinfinish_inboundonly whenticket.fresh_admission && !ticket.waiters.is_empty()(otherwise plaintouch), covered by a test inhelios/src/scheduler/tests.rs.
- For GPU hits,
- Design documents contradict the new victim ordering (
docs/core-design.md:1536-1567,docs/scheduling-runtime-design.md:643-645,docs/prefix-cache-offload.md:298,AGENTS.md:52-60).helios/src/cache.rs:363-365, :732placesis_protectedahead ofRetentionRank, displacing #568's documented invariant ("OptionalAnchorandMessagecaptures reclaim lower-rank victims strictly by demand-recency order",docs/core-design.md:1565-1566) and changing #298/#416's completion refresh (scheduler.rs:3107-3118) so it refreshes recency only within the unprotected tier. All three design docs still state strict demand-recency/role ordering, violatingAGENTS.md:52-60.- Fix: Update
docs/core-design.md:1536-1567,docs/scheduling-runtime-design.md:643-645, anddocs/prefix-cache-offload.md:298to specify the two-tier protection ordering, inheritance rule, and dual-turnover aging, and cite #568 and #298/#416 in the PR description.
- BFS deduplication key in
helios/src/cache/lifecycle_tests.rs:498-505collides distinctreusedstates.Fixture::key()appends theeviction_key-sorted semantic node IDs toself.projection(), which intentionally omitsreusedand turnover counters so it stays aligned withCacheOwnership.tla's 29-integer state tuple (verification/helios-lifecycle/README.md:230-234). Because Action8(duplicate publication,lifecycle_tests.rs:293-296) now mutatesnode.reused = trueviatouch_hit, two states with identicalprojection()— e.g.,reused = [false, false, false]vsreused = [false, false, true]— both sort to[1, 2, 3]and produce identicalkey()values, causingvisited.insert(next.key())(:617) to prune downstream branches where subsequent duplicate publications yield distinct eviction orders.- Fix: Append each live node's protection/reuse state (and relevant turnover state) to
Fixture::key()— leavingFixture::projection()unchanged soCacheOwnership.tlastays valid — and re-runcheck.py.
Subtract / Simplify
- Delete dead duplicate write of
existing.accessed(helios/src/cache.rs:468).- In
publish_with_retention'sExistingbranch (cache.rs:466-471), line 468 writesexisting.accessed = existing.accessed.max(use_epoch);, and line 471 immediately callsself.touch_hit(id, use_epoch)?, whoseself.touch(id, use_epoch)?(:377-382) performs the exact same assignment. Delete line 468 (−1 LOC, eliminates duplicate field writer).
- In
- Delete inert 33-line duplicate test (
helios/src/cache/tests.rs:1472-1504).reclaimable_if_pinned_matches_evict_with_mixed_protected_and_probationary_nodescallsevicted_after_pin(tests.rs:1026-1038), which evicts withpages: usize::MAX, snapshots: usize::MAXand comparessorted(...)sets; victim order cannot alter the drained fixpoint, andreclaimable()(cache.rs:785-843) reads none of the new fields. The same parity invariant is already tested on strictly richer topologies byprojection_matches_eviction_for_chains_branches_and_compaction(tests.rs:1041-1080) andreclaimable_projection_matches_eviction_with_pins(lifecycle_tests.rs:641-703). Delete:1472-1504(−33 LOC).
Nits
- A/B benchmark clarity: The served A/B numbers use
n = 2cold-salted trials per arm on a single boot with no variance reported, and the −86.3% Long-MT p50 TTFT drop (against a 1.74× hit-rate increase) is unexplained in the description (plausibly queueing/prefill-stall avoidance when 127K turns remain resident). Adding variance or a brief causal note, and explicitly confirming #568'spolicy_*tests inhelios/src/scheduler/policy_tests.rs:6301-6485passed, would strengthen the evidence. - Formatting: Remove the doubled blank line at
helios/src/cache/tests.rs:1313-1314.
Dropped on verification
- Upstream F3 ("
finish_inboundPublishResult::Createdtreats a cold scan as a reuse hit, contradictingtests.rs:1337-1338"): Dropped as a misread execution phase. A prefix can only exist in the host/Selene store if a prior request already published and offloaded it (docs/prefix-cache-offload.md:286-290);finish_inboundcreating it back on GPU is a host-tier cache hit (scheduler.rs:1901incrementsstats.host_hits), not a cold scan. Replaced with the verified narrow defect (missingfresh_admission/ empty-waiters gate onTicketin Should Fix #2). - Upstream F4 ("
PublishResult::Existinginpublish_with_retentionlets a single request self-promote inretireorpublish_boundary"): Dropped as false. Verified inhelios/src/cache.rs:435-443andhelios/src/scheduler.rs:2949-2965, 3078-3104thatpublish_with_retentionrejectstail_tokens == 0before checkingself.prefixes, andpublish_boundaryadvancesrequest.prefix_tokens = capture.consumed_tokensonCreated. A request cannot re-publish its own prompt-end or prior boundary checkpoint;PublishResult::ExistinginRequestScheduleronly occurs when two distinct requests (or an inbound restore + live request) collide on the samePrefixKey, which is genuine cross-request reuse. - Upstream Discovery Dossier ("missing Kani sequential proofs"): Dropped as N/A. Per
docs/design-review.md:221-225, Kani covers completion-vector validation, prepared completion contracts, and state-view extent arithmetic, none of which this PR touches (consistent with #568). - Upstream F5 overclaim ("violates
AGENTS.md:204-206architectural-invariant maintainer-decision rule"): Dropped as overstated for a cache victim-ordering policy change; retained the concreteAGENTS.md:52-60design-doc contradiction in Should Fix #3. - Upstream F6 suggested fix ("add
reusedand turnover counters toFixture::projection()"): Dropped because modifyingprojection()would breakCacheOwnership.tla's 29-integerAllowedEdgetuple (verification/helios-lifecycle/README.md:230-234); narrowed the fix toFixture::key()only. - Upstream F8 ("add protected/reused observability fields to
CacheStats"): Dropped as unrequested scope creep that would widen the diff and add conflicts with #549. - Upstream F9 ("33% token-ratio inheritance leaks protection onto scan endpoints"): Dropped as low-signal design preference; ratio-based inheritance (
cache.rs:478-481, tested atcache/tests.rs:1347-1394) is the PR's stated zero-knob heuristic, not a correctness bug. - Upstream Discovery Dossier ("unchecked
self.nodes.get_mut(&id).unwrap()inmark_reused"): Dropped as provably unreachable;mark_reused(cache.rs:367-374) is only called fromtouch_hit(:385-389) immediately afterself.touch(id, use_epoch)?validatesidviaself.checkpoint(id)?(:378).