#1 [high] Subtraction/Simplicity review of PR #665 — five findings
PR #665 (helios scan-resistant dual-turnover prefix cache), head c9197427. Lens: Subtraction, Simplicity & Conventions. Read: helios/src/cache.rs, scheduler.rs, cache/tests.rs, cache/lifecycle_tests.rs, scheduler/tests.rs, scheduler/policy_tests.rs, three docs, AGENTS.md, helios/README.md, .agents/skills/repo-prose/SKILL.md.
Verdict: core implementation is lean — no flags/env knobs/config, no floats/unsafe, no fallbacks, no dead code left behind (the existing.accessed write was removed, correct since touch_hit→touch sets accessed). Findings are about a needless wrapper, duplicated bookkeeping at two retire paths, and test/doc duplication.
-
is_protectedis a one-line wrapper over the field, and it forceseviction_keyto take&selfneedlessly. cache.rs:351-355 /// Whether a checkpoint retains reuse protection over un-reused entries. /// Demotion is sticky once turnover expires and only a new reuse hit restores it. fn is_protected(&self, node: &Checkpoint) -> bool { node.reused } cache.rs:378-380 pub(crate) fn eviction_key(&self, node: &Checkpoint) -> (bool, RetentionRank, CheckpointId) { (self.is_protected(node), node.retention_rank(), node.id) } Uses: cache.rs:494 (self.is_protected(parent) && parent_len.saturating_mul(2) >= tail_tokens), cache.rs:762 (self.eviction_key(node)), cache/lifecycle_tests.rs:504. Replace withfn eviction_key(node: &Checkpoint) -> (bool, RetentionRank, CheckpointId) { (node.reused, node.retention_rank(), node.id) }(associated fn, no&self),node.reusedat :494,Self::eviction_key(node)at :762. Deletes 6 lines + one indirection. Alsopub(crate)is over-wide:cache::tests/cache::lifecycle_testsare child modules and can read private items, so plainfnsuffices. -
Retire/compact duplicate the same horizon capture + eviction counting + demotion (14 lines). cache.rs:615-626 (retire_leaf) and cache.rs:643-645, :669-675 (compact_ancestor) each open with let page_horizon = self.ready_tail_pages.max(1) as u64; let node_horizon = self.ready_checkpoints.max(1) as u64; and then repeat if node_ready { self.evicted_pages = self.evicted_pages.saturating_add(...); self.evicted_checkpoints = self.evicted_checkpoints.saturating_add(1); self.demote_expired_reused(page_horizon, node_horizon); } (compact_ancestor adds no pages, so its page add is absent — the only difference.) Replace both with one helper called immediately after
self.nodes.remove(&id).unwrap()and beforeuncount(this ordering preserves today's semantics exactly: horizons pre-uncount, retired node already out ofnodes): fn note_ready_retirement(&mut self, node: &Checkpoint, pages: u64) { if !node.ready { return; } let page_horizon = self.ready_tail_pages.max(1) as u64; let node_horizon = self.ready_checkpoints.max(1) as u64; self.evicted_pages = self.evicted_pages.saturating_add(pages); self.evicted_checkpoints = self.evicted_checkpoints.saturating_add(1); self.demote_expired_reused(page_horizon, node_horizon); } Call sites:self.note_ready_retirement(&node, node.tail_pages.len() as u64);andself.note_ready_retirement(&node, 0);. -
mark_reusedexists only fortouch_hitand adds a secondnodeslookup. cache.rs:382-389 + :399-404 fn mark_reused(&mut self, id: CheckpointId) { let evicted_pages = self.evicted_pages; let evicted_checkpoints = self.evicted_checkpoints; let node = self.nodes.get_mut(&id).unwrap(); ... pub fn touch_hit(&mut self, id: CheckpointId, use_epoch: u64) -> Result<()> { self.touch(id, use_epoch)?; self.mark_reused(id); Ok(()) } Merge intotouch_hit(field-disjoint borrows allownode.reused_at_evicted_pages = self.evicted_pages;directly). Removes one function and one map probe per hit. Naming nit while there:reused_at_evicted_nodesvs the counter it compares to,evicted_checkpoints— pick one word. -
Test scaffolding duplicate. a) scheduler/policy_tests.rs:6429-6480
policy_regime_shift_ages_out_reused_old_large_documents_...is the previous test (:6379-6427) plus 3 lines: per-doc it adds a second turn (second = doc.clone(); second.extend(vec![350+i;32]); run_turn...; assert_eq!(reused_second, 1_536)). Everything fromfor i in 0..16u32to the end is verbatim identical. Collapse to one test loopingfor reuse in [false, true], or a helperfn regime_shift_reaps_old_documents(reuse_each_doc: bool). b) cache/tests.rs:1471-1567sticky_demotion_does_not_reprotect_after_fresh_publicationsrepeats cache/tests.rs:1398-1451 verbatim (samestale/keptpublication +touch_hit, samebig_scaneviction, samefor (offset, epoch) in [(2000,6),(2500,7)]loop). Extractfn aged_out_pair(cache: &mut PrefixCheckpointCache) -> (CheckpointId, CheckpointId); each test then asserts its own tail. ~45 duplicated lines. -
Doc duplication / stale spec (repo-prose: "Replace stale claims instead of layering history"). docs/prefix-cache-offload.md:374-376 still states the pre-PR flat order, contradicting the tiered statement the same PR added at :298-303: GPU eviction ranks eligible checkpoints by logical-request demand epoch, retention role, consumed-token count, and identity, as specified in checkpoint lifetime. Delete/replace with a pointer to the two-tier rule. helios/README.md:713-715 (module spec, AGENTS.md line 227 names it required reading for cache changes) still says: logical pins does not imply completion of that use. Leaf LRU eviction accepts separate page and snapshot pressure targets and produces
RetiredResources, "LRU" no longer describes the victim order; the PR synced three docs but not this one.
Non-findings checked and deliberately not raised: no new flags/env/config (AGENTS.md 450-460 respected); the #[cfg(test)] full-scan assert in stats() (cache.rs:913-932) is guarded and cheap; ready_tail_pages/evicted_* counters are needed (deriving them would mean scanning per retirement); the scheduler's two if hit { touch_hit } else { touch } sites (scheduler.rs:1734-1740, :1884-1891) are 3 lines each and folding them into a cache method would re-introduce a boolean parameter.
Related-but-not-mine (Correctness lens): Ticket.fresh_admission is OR'ed on waiter join (scheduler.rs:1709) but never cleared when a waiter is removed in retire (scheduler.rs:3076-3080), so fresh_admission && !waiters.is_empty() can hold with only preempted waiters left.
#2 [high] Research summary
Reviewed the nine changed files (plus AGENTS.md, helios/README.md, the prose skill, and existing helpers such as engram/cache.rs) through the subtraction/simplicity/conventions lens.
Verdict: the production diff is genuinely lean — no new flags, environment knobs, config switches, fallback branches, floats, or unsafe, and nothing dead was left behind (the old existing.accessed write was correctly deleted now that touch_hit refreshes accessed). The five findings are a needless one-line wrapper, bookkeeping duplicated across the two retirement paths, a redundant helper, duplicated test scaffolding, and two doc passages that a simplicity reader trips over.
Findings, each with a concrete replacement:
is_protected(cache.rs:351-355) is a wrapper overnode.reusedand forceseviction_keyto take&self; fold to an associatedfn eviction_key(node) -> (node.reused, …)and droppub(crate)(test modules are children).retire_leaf(cache.rs:615-626) andcompact_ancestor(cache.rs:643-675) repeat the horizon capture plusevicted_pages/evicted_checkpointsaccounting plusdemote_expired_reused; onenote_ready_retirement(&node, pages)helper collapses ~14 duplicated lines, called right afternodes.remove.mark_reused(cache.rs:382-389) is used only bytouch_hit(cache.rs:399-404) and costs a second map probe; merge. Also unifyreused_at_evicted_nodeswith theevicted_checkpointscounter it compares against.- Test duplication:
policy_regime_shift_ages_out_reused_old_large_documents_…(policy_tests.rs:6429-6480) is the preceding test plus two lines;sticky_demotion_does_not_reprotect_after_fresh_publications(cache/tests.rs:1471-1567) repeats cache/tests.rs:1398-1451 verbatim. Extract shared setup in both. - Docs: prefix-cache-offload.md:374-376 still specifies the old flat eviction order, contradicting the tiered rule added at :298-303; helios/README.md:713-715 still calls it "Leaf LRU eviction" although AGENTS.md line 227 names that file required reading for cache changes.
I explicitly did not raise: the #[cfg(test)] count assert, the new counters (deriving them would require scanning per retirement), or the scheduler's two 3-line touch_hit/touch branches (folding them into a cache method would reintroduce a boolean parameter). One cross-lens note left to the Correctness reviewer: Ticket.fresh_admission is OR'ed on waiter join (scheduler.rs:1709) and never cleared when a waiter is removed in retire (scheduler.rs:3076-3080).
#3 [medium] Review limitations and non-findings (report footer)
Companion to scratchpad entry 1 (PR #665 subtraction review, head c9197427).
Limitations of this review:
- Read-only inspection. No cargo build/test run and no mutation or boundary run in this environment, so every suggestion is source-level; none of them change asserted behaviour, but suggestions 1-3 must be re-tested with
cargo test --manifest-path helios/Cargo.toml --features runtime-core,server. - Only the nine changed files plus AGENTS.md, helios/README.md, .agents/skills/repo-prose/SKILL.md, docs/README-adjacent sections, and helios/src/engram/cache.rs (as the repo's other cache-policy precedent) were read.
verification/helios-lifecycle/check.pywas not opened in this pass (the dossier's finding that it has no mutation target for the new code stands as reported there). - No unused-code finding for
is_protected/eviction_key/touch_hit: all three have live call sites (cache.rs:494, cache.rs:762, cache/lifecycle_tests.rs:504, scheduler.rs:1736/1887, cache.rs:485). Nothing was added speculatively: no config, no feature flag, no trait, no extension point.
Simplifications considered and rejected (recorded so the report does not re-litigate them):
- Do not delete
ready_tail_pages/evicted_pages/evicted_checkpointsin favour of deriving them fromnodes: derivation happens on every retirement and would put an extra full scan on the eviction path the PR is trying to make cheap. - Do not collapse the two scheduler call sites (scheduler.rs:1734-1740, :1884-1891) into one cache method taking a
protect: bool: AGENTS.md 450-460 and the "no flags/optional paths" rule make a boolean mode parameter worse than the duplication, which is three lines each. - Do not remove the
#[cfg(test)]full-scan assert (cache.rs:913-932) for the new counter: it is free in production and is the only drift check onready_tail_pages(maintained at cache.rs:263, :274, :670, :890). demote_expired_reused'ssaturating_mul(2)snapshot-bound branch and theparent_len * 2 >= tail_tokensinheritance rule are policy the PR's evidence argues for, not speculative generality; subtraction lens has no basis to cut them.