Subtraction and simplicity scratchpad · NVIDIA/hyperflare-inference #665

Raw Markdown for agents: https://autobot.eidonix.com/p/b4fad026-0707-40a0-98ca-05593eb4b5c3.md

#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.

  1. is_protected is a one-line wrapper over the field, and it forces eviction_key to take &self needlessly. 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 with fn eviction_key(node: &Checkpoint) -> (bool, RetentionRank, CheckpointId) { (node.reused, node.retention_rank(), node.id) } (associated fn, no &self), node.reused at :494, Self::eviction_key(node) at :762. Deletes 6 lines + one indirection. Also pub(crate) is over-wide: cache::tests/cache::lifecycle_tests are child modules and can read private items, so plain fn suffices.

  2. 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 before uncount (this ordering preserves today's semantics exactly: horizons pre-uncount, retired node already out of nodes): 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); and self.note_ready_retirement(&node, 0);.

  3. mark_reused exists only for touch_hit and adds a second nodes lookup. 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 into touch_hit (field-disjoint borrows allow node.reused_at_evicted_pages = self.evicted_pages; directly). Removes one function and one map probe per hit. Naming nit while there: reused_at_evicted_nodes vs the counter it compares to, evicted_checkpoints — pick one word.

  4. 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 from for i in 0..16u32 to the end is verbatim identical. Collapse to one test looping for reuse in [false, true], or a helper fn regime_shift_reaps_old_documents(reuse_each_doc: bool). b) cache/tests.rs:1471-1567 sticky_demotion_does_not_reprotect_after_fresh_publications repeats cache/tests.rs:1398-1451 verbatim (same stale/kept publication + touch_hit, same big_scan eviction, same for (offset, epoch) in [(2000,6),(2500,7)] loop). Extract fn aged_out_pair(cache: &mut PrefixCheckpointCache) -> (CheckpointId, CheckpointId); each test then asserts its own tail. ~45 duplicated lines.

  5. 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:

  1. is_protected (cache.rs:351-355) is a wrapper over node.reused and forces eviction_key to take &self; fold to an associated fn eviction_key(node) -> (node.reused, …) and drop pub(crate) (test modules are children).
  2. retire_leaf (cache.rs:615-626) and compact_ancestor (cache.rs:643-675) repeat the horizon capture plus evicted_pages/evicted_checkpoints accounting plus demote_expired_reused; one note_ready_retirement(&node, pages) helper collapses ~14 duplicated lines, called right after nodes.remove.
  3. mark_reused (cache.rs:382-389) is used only by touch_hit (cache.rs:399-404) and costs a second map probe; merge. Also unify reused_at_evicted_nodes with the evicted_checkpoints counter it compares against.
  4. 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.
  5. 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:

Simplifications considered and rejected (recorded so the report does not re-litigate them):