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

Raw Markdown for agents: https://autobot.eidonix.com/p/017ce3a9-c5f5-481a-9026-ce51d09b70c1.md

Subtraction / Simplicity / Conventions review — PR #665 (helios: add scan-resistant dual-turnover prefix cache eviction)

Key findings

  1. The production diff is lean — ~68 net lines, no flags, no env vars, no floats, no unsafe, no per-model branch, no speculative trait or wrapper, and no unread field or counter. This is not a "knobs" PR. Only two genuine subtractions exist, both small but worth taking.
  2. One dead duplicate write was left behind by the diff itself. helios/src/cache.rs:466-471 now writes accessed twice for the same node: the pre-existing existing.accessed = ... and the new self.touch_hit(...), which does exactly the same assignment. Delete the pre-existing line (net −1 line, one mutation path removed).
  3. One new test (33 lines, ~17% of the added test code) cannot fail because of anything this PR changes and is a third copy of an already doubly-covered parity property: helios/src/cache/tests.rs:1472-1504. Delete it.
  4. Written-convention item: docs/core-design.md:1536-1542 and :1565 still specify victim order as strictly (demand epoch, role, consumed tokens, identity) / "strictly by demand-recency order", while cache.rs:363-365 now sorts is_protected first. AGENTS.md:52-60 requires design documents to specify the implemented behaviour, so the file has to be edited rather than left as a stale spec. (Same substance as the docs lens; reported here only because it is the repo's own written rule, not a style preference.)
  5. Rejected false positives (do not "simplify" these): the fresh_admission if/else at scheduler.rs:1734-1739 cannot collapse to a plain touch_hit; the cache.advance_completed(Fence(0)).unwrap() calls in the new aging test are load-bearing, not redundant.

1. Dead duplicate write of accessed on duplicate publication — helios/src/cache.rs:466-471

Verbatim (head a7568c2):

if let Some(id) = self.prefixes.get(&prefix).copied() {
    let existing = self.nodes.get_mut(&id).unwrap();
    existing.accessed = existing.accessed.max(use_epoch);
    existing.role = existing.role.max(role);
    let ready = existing.ready;
    self.touch_hit(id, use_epoch)?;

The diff replaced self.touch(id, use_epoch)?; with self.touch_hit(id, use_epoch)?; but kept the manually inlined recency write above it. touch_hit is defined as (cache.rs:384-389):

pub fn touch_hit(&mut self, id: CheckpointId, use_epoch: u64) -> Result<()> {
    self.touch(id, use_epoch)?;
    self.mark_reused(id);
    Ok(())
}

and touch (cache.rs:376-382) is exactly node.accessed = node.accessed.max(use_epoch). So line 468 is now a no-op that is executed and then immediately repeated by touch_hit.

Remove the single line existing.accessed = existing.accessed.max(use_epoch); (line 468), leaving:

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)?;

The &mut borrow still ends at the ready copy, exactly as before, so the code compiles unchanged in shape. Net −1 line, and the Existing branch no longer has two writers for the same field that can drift apart when the aging rule is next revised. This is the only spot in the diff where the patch added a second writer instead of replacing the first.

2. Inert 33-line test — helios/src/cache/tests.rs:1472-1504

Verbatim (core of reclaimable_if_pinned_matches_evict_with_mixed_protected_and_probationary_nodes):

    for idx in 0..4 {
        let (mut cache, ids) = build();
        let projected = cache.reclaimable_if_pinned(ids[idx]).unwrap();
        let actual = evicted_after_pin(&mut cache, ids[idx]);
        assert_eq!(sorted(projected.pages), sorted(actual.pages));
        assert_eq!(sorted(projected.snapshots), sorted(actual.snapshots));
    }

Two independent reasons it is inert with respect to this diff:

It is also the third copy of the same projection/eviction parity property, already covered by:

Remove the whole test (tests.rs:1472-1504, 33 lines) — title, build closure and loop. No coverage is lost; the "protected vs probationary" mix it constructs is exercised by the other two tests and by the three genuinely new tests above it.

3. Convention: the design document that specifies the changed ordering is left contradicting the code

docs/core-design.md:1536-1542 (unchanged by this PR):

GPU retention orders eligible checkpoints by logical-request demand epoch, then
role, then consumed-token count, then checkpoint identity. ...

and docs/core-design.md:1565-1566:

equal or higher retention rank. Optional `Anchor` and `Message` captures reclaim lower-rank victims strictly by
demand-recency order. Optional `Endpoint` captures (prompt-end and ordinary

The code now sorts protection ahead of rank (cache.rs:363-365):

pub(crate) fn eviction_key(&self, node: &Checkpoint) -> (bool, RetentionRank, CheckpointId) {
    (self.is_protected(node), node.retention_rank(), node.id)
}

AGENTS.md:52-60 states the rule this violates: "Every repository document has one or both of two purposes: it specifies the architecture, or it instructs agents how to work in the repository. State designed behavior that the code does not implement as a specification marked designed, not implemented." A design doc that specifies the displaced ordering is neither. docs/design-review.md aside, every comparable merged policy PR (#298, #416, #567, #568, #582, #655) edited docs/*; #665 touches only four files under helios/src.

Fix: extend the core-design.md:1536-1542 retention paragraph and the :1565 sentence so protection-before-rank, the inheritance rule and the dual-turnover aging appear as the specified behaviour. This is a documentation edit, not code.

Checked and clean — say so plainly, no further nitpicks

Open questions

  1. Whether #568's five end-to-end policy tests in helios/src/scheduler/policy_tests.rs (not opened) still encode assumptions about strict (retention_rank, id) ordering that this PR silently relaxes; the PR reports only aggregate scheduler:: 408 (4 ign) and does not name them. Not opened in this review.
  2. Whether finish_inbound's new touch_hit (scheduler.rs:1886) has any direct test — I found none, and both A/B arms run --prefix-cache-memory 0, so host restore is unexercised end-to-end. (Correctness lens territory; noting it because it bears on whether the scheduler-side call could simply be dropped until measured.)
  3. Whether docs/scheduling-runtime-design.md (not opened) and docs/prefix-cache-offload.md (not opened) contain the same now-stale victim-order statement as core-design.md; only the latter was read here.

I make no correctness claims: the dual-turnover demotion rule, mark_reused's unchecked self.nodes.get_mut(&id).unwrap() (cache.rs:370), the global (rather than per-node) aging horizon, and the compact_ancestor path never touching the turnover counters belong to the Correctness & Contracts lens.