Recommendation: Ready To Merge
Rebased onto main (1fbcc3c9) at head c5b39236, PR #665 resolves every blocker, should-fix, subtraction, and nit from the prior review and closes the residual Existing-restore and documentation issues found on intermediate head c919742. The policy remains lean, zero-knob, and model-agnostic (135 net production LOC across cache.rs and scheduler.rs; no flags, floats, unsafe, or core-format changes), with sticky dual-turnover + compaction aging, per-waiter host-restore freshness gating across both Created and Existing matches, synced design docs, and full check.py --mutations plus unit/policy coverage reported on the pushed tree.
Merge Risk
Level: Medium
- Eviction-path blast radius:
eviction_key(helios/src/cache.rs:378-380, applied at:777) changes victim ordering for both mandatory reclamation (evict) and optional budgeted captures (eviction_candidate_within_budget, re-simulated inhelios/src/scheduler/cache_memory.rs:337-371). Protection only orders victims (never filters them), so mandatory eviction cannot livelock,#568's retention-rank and marginal-gain filters still execute before tier ordering, andPrefixCheckpointCache::clonepreserves quote re-simulation determinism. - Default-on workload trade-off: The policy is always on with no opt-out; on an abrupt cold workload shift, stale reuse-protected entries survive until either full dual turnover (
ready_tail_pages.max(1)pages andready_checkpoints.max(1)checkpoints) or2xready_checkpoints.max(1)retirements under snapshot-bound pressure (cache.rs:360-376), evicting newly created probationary entries first during the transition window. - Concurrency, compatibility, and rebase surface: All new state lives inside single-owner
&mutPrefixCheckpointCacheandRequestSchedulerstructures with saturating integer arithmetic and no locks, external inputs, or core-format changes. Expected textual merge conflict with open PR #549 onCheckpoint/PrefixCheckpointCachefields (cache.rs:84-86, :219-224) andFixture::fork/Fixture::key(helios/src/cache/lifecycle_tests.rs:79-98, :499-526), with no semantic overlap.
Walkthrough
helios/src/cache.rs(+138/−22): Addsreused,reused_at_evicted_pages,reused_at_evicted_nodestoCheckpoint(:84-86) andready_tail_pages,evicted_pages,evicted_checkpointstoPrefixCheckpointCache(:219-224), maintainingready_tail_pagesacrosscount/uncount(:263, :274),compact_ancestor(:684-686), andadvance_completed(:905) with a#[cfg(test)]full-scan assertion instats()(:928-947). Adds sticky demotion viademote_expired_reused(:360-376, invoked fromretire_leafat:631-641andcompact_ancestorat:659-690),eviction_key(:378-380, used at:777),touch_hit(:400-404),publish_with_retention_with_hit(:423-550) for gatedExistingpromotion, and>= 33%continuation inheritance (:507-510).helios/src/scheduler.rs(+32/−13): ReplacesTicket.waiters: Vec<RequestHandle>withVec<(RequestHandle, bool)>(:631, :1699, :1714, :3105) to track per-waiterfresh_admission = accounting.is_none()(:1682). Gates GPU hit promotion onfresh_admission(:1739-1745) and gates host-restore promotion infinish_inboundonhas_fresh_waiter = ticket.waiters.iter().any(|&(_, fresh)| fresh)(:1863) across bothPublishResult::Existing(:1864-1870) andPublishResult::Created(:1896-1903). Completion refresh inretire(:3138-3155) stays on plaintouch.helios/src/cache/lifecycle_tests.rs(+29/−3): Copies new cache/checkpoint fields inFixture::fork(:79-81, :96-98) and appendseviction_key-ordered semantic IDs,reusedflags, and elapsed page/node turnovers toFixture::key()(:499-526) while keepingprojection()aligned withCacheOwnership.tla.- Unit & policy tests (
helios/src/cache/tests.rs+319,helios/src/scheduler/tests.rs+264,helios/src/scheduler/policy_tests.rs+53): Adds 5 isolated cache tests (scan resistance,>= 33%inheritance, dual-turnover aging, sticky demotion, snapshot-only compaction aging), 4 real-schedulerfinish_inbound_*tests covering fresh/cancelled/preempted/mixed waiters on bothCreatedandExistingmatches, and a reused-document regime-shift workload test. - Docs (
docs/core-design.md,docs/prefix-cache-offload.md,docs/scheduling-runtime-design.md,helios/README.md): Reconciles all four normative specs to the two-tier(is_protected, RetentionRank, id)ordering,>= 33%continuation inheritance, sticky dual-turnover /2xcompaction demotion, and live-fresh-waiter host-restore promotion (including both Sections 2.2 and 2.3 ofdocs/prefix-cache-offload.md:298-306, :377-381).
Pre-merge Checks
- [PASS] Security / malicious screen: Pure in-memory cache/scheduler integer bookkeeping; no external input parsing,
unsafe, or new attack surface. - [PASS] Charter & value fit: Right Helios runtime layer, zero flags/knobs/model branches/core changes, four-part PR description citing
#568/#298/#416with served A/B benchmarks and synced docs. - [WARN] Related / duplicate / conflict check: Genuinely additive and cleanly rebased on
1fbcc3c9, but has a guaranteed textual conflict with open PR #549 inhelios/src/cache.rsandhelios/src/cache/lifecycle_tests.rs(no semantic conflict). - [WARN] Tests & verification evidence: Full clean-archive CPU test suites and
check.py --mutations(10/10TLC,8/8observed,12/12aux,39/39+1/1bad-edge KILLED) are reported for pushed tree402aa479(c5b39236), though CI results are not visible in this environment and the served GPU A/B (n = 2trials/arm,--prefix-cache-memory 0) was measured on pre-hardening heada7568c2c(disclosed in the PR body).
Blockers
None.
Should Fix
None.
Subtract / Simplify
- Factor duplicate retirement turnover accounting in
helios/src/cache.rs:630-641, :658-690:retire_leafandcompact_ancestorrepeat the same pre-uncounthorizon capture (ready_tail_pages.max(1),ready_checkpoints.max(1)),if node.readyguard, counter updates, anddemote_expired_reusedcall. Folding them into onenote_ready_retirement(&mut self, node: &Checkpoint, pages: u64)helper called right afterself.nodes.remove(&id)and beforeself.uncount(&node)(passingnode.tail_pages.len() as u64vs0) removes ~14 lines and enforces the pre-uncountordering in one place. - Collapse one-line
is_protectedwrapper and narroweviction_keyvisibility (helios/src/cache.rs:353-355, :378-380):is_protected(&self, node: &Checkpoint)reads onlynode.reusedwithout touchingself, andeviction_keyis only called fromcache.rs:777and child test modulecache::lifecycle_tests(lifecycle_tests.rs:504). Replacing both with a private associated functionfn eviction_key(node: &Checkpoint) -> (bool, RetentionRank, CheckpointId)deletes 6 lines and removes the receiver indirection. - Inline single-caller
mark_reusedand align field naming (helios/src/cache.rs:86, :382-404):mark_reusedhas only one caller (touch_hitat:402) and performs a secondself.nodes.get_mut(&id)lookup right afterself.touchalready probed the map. Inlining the three field assignments intotouch_hitavoids the duplicate hash lookup per hit; renamingreused_at_evicted_nodes(:86) toreused_at_evicted_checkpointsmatchesevicted_checkpoints(:224). - Deduplicate shared setup in new cache and policy tests (
helios/src/cache/tests.rs:1396-1567,helios/src/scheduler/policy_tests.rs:6380-6480):sticky_demotion_does_not_reprotect_after_fresh_publicationsrepeats the first 56 lines ofdual_turnover_aging_demotes_stale_reused_entry_after_page_and_node_turnover, andpolicy_regime_shift_ages_out_reused_old_large_documents_for_newer_chat_workloadduplicatespolicy_regime_shift_ages_out_old_large_documents_for_newer_chat_workloadexcept for the second turn in Phase 1. Extracting two small test helpers removes ~80 lines while keeping all test names unchanged.
Nits
- Unready guard symmetry (
helios/src/cache.rs:364-375):demote_expired_reusediterates all nodes without checkingif !node.ready { continue; }. Every production publication creates ready checkpoints (scheduler.rs:1861, :2981-2983, :3072), so this is unreachable today, but adding the guard aligns demotion witheviction_candidates()(cache.rs:716) if a future caller publishes ahead ofcompleted. - A/B head freshness: The PR body clearly discloses that the GPU A/B ran on
a7568c2cwith--prefix-cache-memory 0; because the hardened policy only demotes earlier (2xcompaction turnover, sticky demotion) and restricts restore promotion, re-running onc5b39236(ideally with host offload enabled) would tighten the performance record if GPU capacity is free.
Dropped on verification
- Upstream Correctness F1 ("
Existingpublication promotes unconditionally on host restore"): Dropped — already fixed on current headc5b39236viapublish_with_retention_with_hit(..., has_fresh_waiter)(helios/src/cache.rs:423-506,helios/src/scheduler.rs:1863-1870), per-waiterVec<(RequestHandle, bool)>tracking (scheduler.rs:631, :3105), and verified byfinish_inbound_existing_checkpoint_requires_live_fresh_waiter_for_promotionandfinish_inbound_cancelling_fresh_waiter_leaves_preempted_waiter_probationary(helios/src/scheduler/tests.rs:3325-3471). - Upstream Correctness F2 ("Preempted completion retirement still promotes via
Existing"): Dropped — false premise. A preempted request cannot republish its admitted prefix (finish_earlyreturns early unlessconsumed_tokens > prefix_tokensathelios/src/scheduler.rs:1438, andpublish_with_retention_with_hitrejectstail_tokens == 0athelios/src/cache.rs:465). HittingExistinginretire(scheduler.rs:3132) requires a distinct request to have concurrently published the same newly computed continuation, which is genuine cross-request duplicate capture publication (docs/core-design.md:1544-1545), whilerefresh_recency(scheduler.rs:3124-3127) properly suppresses minting a new completion epoch whenrequest.preemptedis true. - Upstream Correctness F6 & Subtraction #5 ("
docs/prefix-cache-offload.md:374-376self-contradiction andhelios/README.md:713-715stale 'Leaf LRU' wording"): Dropped — both were already fixed on current headc5b39236(docs/prefix-cache-offload.md:377-381,helios/README.md:714-718). - Upstream Correctness F8 & Discovery #3 ("Require new policy-ordering mutants in
verification/helios-lifecycle/check.pyas a blocker"): Dropped as a blocker —check.pyvalidates TLA+ ownership/fence/reservation safety guards (check.py:511-520), whereasCacheOwnership.tlaexplicitly abstracts victim ordering (verification/helios-lifecycle/README.md:240-241). The author ran the fullcheck.py --mutationssuite requested in Round 1 (39/39+1/1bad-edge KILLED) and pinned every new policy branch with 9 dedicated Rust unit/scheduler/policy tests. - Upstream Correctness F4 ("O(all-nodes)
demote_expired_reusedwalk causes hot-path regression"): Dropped — overstated.demote_expired_reusedruns only during actual eviction/compaction, whereeviction_candidates()(cache.rs:715),evict_checkpoint()(cache.rs:791),compact_ancestor()(cache.rs:668), andsimulate_snapshot_quote()(cache_memory.rs:337) already perform multiple fullself.nodesscans per victim, bounded bysnapshot_capacity.