Subtraction / Simplicity / Conventions review — PR #665 (helios: add scan-resistant dual-turnover prefix cache eviction)
Key findings
- 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. - One dead duplicate write was left behind by the diff itself.
helios/src/cache.rs:466-471now writesaccessedtwice for the same node: the pre-existingexisting.accessed = ...and the newself.touch_hit(...), which does exactly the same assignment. Delete the pre-existing line (net −1 line, one mutation path removed). - 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. - Written-convention item:
docs/core-design.md:1536-1542and:1565still specify victim order as strictly(demand epoch, role, consumed tokens, identity)/ "strictly by demand-recency order", whilecache.rs:363-365now sortsis_protectedfirst.AGENTS.md:52-60requires 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.) - Rejected false positives (do not "simplify" these): the
fresh_admissionif/else atscheduler.rs:1734-1739cannot collapse to a plaintouch_hit; thecache.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:
- Order cannot matter to the assertion.
evicted_after_pin(tests.rs:1026-1038) evicts withpages: usize::MAX, snapshots: usize::MAX, soevict(cache.rs:759-775) drains every candidate; the only thingeviction_keychanges is victim order, and the test compares sorted sets (sorted,tests.rs:1020-1023). - The subject never reads the new state.
reclaimable(cache.rs:785-843) is a pin/child-count fixpoint overpins,direct_pins,child_count,ready,tail_pages,snapshot; it reads none ofreused,reused_at_evicted_pages,reused_at_evicted_nodes,evicted_pages,evicted_checkpoints,is_protectedoreviction_key. The PR description itself listsreclaimable_if_pinnedamong the unchanged invariants.
It is also the third copy of the same projection/eviction parity property, already covered by:
tests.rs:1040-1080projection_matches_eviction_for_chains_branches_and_compaction— same fixed-id sweep, plus branch, unready leaf and compaction cases (strictly more structure than the new test's linear chain), andcache/lifecycle_tests.rs:640-703reclaimable_projection_matches_eviction_with_pins— exhaustive fixture sweep over parent/pending/pin withassert!(cases >= 30).
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
-
No subtraction targets in the policy. No CLI flags, no config, no env vars, no floats (integer-only,
saturating_*throughout), nounsafe, no per-model or per-hardware branch — satisfies the charter's "no per-model special cases or flags" anddocs/design-review.md:50. -
No dead state. Each new field is read:
reused/reused_at_evicted_pages/reused_at_evicted_nodes(cache.rs:84-86) written inmark_reused(:367-374) and at birth (:503-505), read inis_protected(:349-361);evicted_pages/evicted_checkpoints(cache.rs:221-222) incremented on exactly one path,retire_leaf(:604-609), and read inis_protectedand at birth. No speculative abstraction, no wrapper type, no fallback branch. -
eviction_keyis a de-duplication, not a complication. One sort key shared bymin_by_key(cache.rs:732) and the lifecycle projectionkey()(cache/lifecycle_tests.rs:502) replaces the tuple literal that previously appeared in both places. Keeping itpub(crate)is the minimum visibility needed for the lifecycle fixture. -
touch_hitas a two-line composition overtouch+mark_reusedis the right shape — no duplicated recency logic. -
False positive rejected —
scheduler.rs:1734-1739must keep its branch:if let Some(id) = lookup.checkpoint { if fresh_admission { self.cache.touch_hit(id, demand_epoch)?; } else { self.cache.touch(id, demand_epoch)?; } }It cannot collapse into an unconditional
touch_hit: preemption re-admissions carrySome(accounting)and must not promote; and host restores do not reach this branch at all — they pass through the!readyearly return atscheduler.rs:1876-1883before the newtouch_hitat:1884-1887. Factoring the two arms into helpers would add indirection and duplicate?handling for zero line saving. -
False positive rejected —
cache.advance_completed(Fence(0)).unwrap();attests.rs:1434and:1451is load-bearing. It flushes the retirement queue soowned_pages/owned_snapshotsare released (cache.rs:865-876); without it the later re-publish of the samePageIds fails the ownership check atcache.rs:449-465. Do not delete as test noise. -
Test-helper non-reuse is justified. The new tests hand-roll
publish_with_retention(...).unwrap().id()instead of thecreated()helper (tests.rs:45-54) becausecreatedforcesRetentionRole::Endpointat epoch 0, which is precisely the variable these tests need to control. The existingproposal/history/sorted/evicted_after_pinhelpers are reused wherever applicable. -
Only cosmetic residue, not worth a finding: a doubled blank line at
cache/tests.rs:1313-1314where the new test block was appended.
Open questions
- 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 aggregatescheduler:: 408 (4 ign)and does not name them. Not opened in this review. - Whether
finish_inbound's newtouch_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.) - Whether
docs/scheduling-runtime-design.md(not opened) anddocs/prefix-cache-offload.md(not opened) contain the same now-stale victim-order statement ascore-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.