#1 [high] should fix: cache pin_request/unpin_request walk the chain twice
helios/src/cache.rs:519-580. pin_request calls self.pin(id)? (which itself computes self.chain(id)? at line 523) and then computes self.chain(id)? again at line 554 to bump request_pins. unpin_request does the same at 569/571. So every request pin and unpin walks the ancestor chain twice and allocates two Vec. Call sites on the hot path: scheduler.rs:1645 (every admission), 1900 (every ticket waiter), 2971/2991 (every boundary publication), 3159 (every retirement), plus the two error-path unpins at 1660/1686.
Smaller version (one traversal, one code path, no new public API):
fn pin_kind(&mut self, id: CheckpointId, request: bool) -> Result<()> {
if !self.checkpoint(id)?.ready { return Err("cannot pin a checkpoint before GPU readiness".into()); }
let chain = self.chain(id)?;
if self.nodes[&id].direct_pins == u64::MAX || chain.iter().any(|id| self.nodes[id].pins == u64::MAX) {
return Err("checkpoint reference count exhausted".into());
}
self.nodes.get_mut(&id).unwrap().direct_pins += 1;
for ancestor in chain {
let node = self.nodes.get_mut(&ancestor).unwrap();
node.pins += 1;
if request {
node.request_pins += 1;
if node.request_pins == 1 { self.request_pinned_pages += node.tail_pages.len(); }
}
}
if request { self.nodes.get_mut(&id).unwrap().direct_request_pins += 1; }
Ok(())
}
pub fn pin(&mut self, id: CheckpointId) -> Result<()> { self.pin_kind(id, false) }
pub fn pin_request(&mut self, id: CheckpointId) -> Result<()> { self.pin_kind(id, true) }
and the same for unpin. This deletes ~30 lines and one whole traversal per call.
#2 [high] should fix: pin_request doc comment claims it counts private pages
helios/src/cache.rs:548-550:
"/// Pins a checkpoint on behalf of an active request. Request pins also track the /// pages the request keeps referenced: its private pages plus the pinned /// ancestors' pages, each page counted once."
The cache has no knowledge of a request's private pages; request_pinned_pages only counts node.tail_pages of nodes with request_pins > 0 (cache.rs:558-560, verified against the full scan at 830-834). Private pages are added by the scheduler at helios/src/scheduler.rs:1216-1222 (request.private_pages.len() summed over slots). A reader of pin_request cannot tell whether double counting is possible.
Fix: state only what the cache does, e.g. "Pins a checkpoint on behalf of an active request and adds the tail pages of every checkpoint on its chain to request_pinned_pages while at least one request pin remains. A request's private pages are not cache pages; the scheduler adds them (see RequestScheduler::stats)."
#8 [high] Research summary
Reviewed PR #549 through the simplicity lens (what can be deleted), against the charter, AGENTS.md's rejection criteria ("Reject unsupported abstractions and churn", "Require focused, meaningful validation") and the repo-prose skill.
Three findings worth fixing, none blocking:
-
should fix — helios/src/cache.rs:551-580.
pin_requestcallsself.pin(id)?(which already walks the chain at line 523) and then walkschain(id)a second time;unpin_requestdoes the same. Two chain allocations per request pin, on every admission, ticket waiter, boundary publication and retirement. Smaller version: one privatepin_kind(id, request: bool)that walks the chain once and bumpspinsand, when request-pinned,request_pins/request_pinned_pages, withpin/pin_requestas one-line wrappers — deletes ~30 lines and a whole traversal. -
should fix — helios/src/cache.rs:548-550. The doc comment says request pins track "its private pages plus the pinned ancestors' pages", but the cache never sees private pages;
request_pinned_pagescounts onlytail_pagesof nodes withrequest_pins > 0(verified against the full scan at 830-834), and the scheduler adds private pages at scheduler.rs:1216-1222. The comment should state only the cache's part and point atRequestScheduler::stats. -
nit — helios/src/scheduler.rs:1216-1228.
stats()now scans the slot array three times (active count, private pages, reserved pages); onefoldyields both new totals. Also nipped: two of the new test assertions do not prove what their comments imply (cache/tests.rs:335 rejects a plain guard case already covered at tests.rs:358; the private-page half of scheduler/tests.rs:1024 is tautological, though the shared-page half is real evidence), and the docs/api.md:298-305 paragraph duplicates the metric table at api.md:325-346 and narrates implementation ("read from scheduler state on each scrape", "Both are gauges") where one home for the content would do.
Examined and deliberately kept: direct_request_pins (its only consumer is the unpin_request guard, but without it a duplicate request unpin would silently corrupt the count when the same node is also pinned for host-store copy-out), the separate request_pinned_pages field, the two Prometheus-only metrics atomics, and the plain-pin path for inbound admissions (those requests are not live yet; they are re-pinned at finish_inbound). The compaction and eviction invariants for the new counters check out.
#9 [high] report outline: verdict, ordering, rule citations
Report structure and verdict for the simplicity lens (PR #549, head 5ed7af8):
Verdict: three findings, none blocking; the change reuses existing mechanisms rather than adding parallel paths, so nothing needs to be deleted outright. Ordered by importance:
- should fix — helios/src/cache.rs:551-580 —
pin_request/unpin_requestwalk the ancestor chain twice; collapse into onepin_kind(id, request)helper (see scratchpad entry 1 for the code). - should fix — helios/src/cache.rs:548-550 — doc comment claims the cache tracks a request's private pages; it does not (see entry 2).
- nit — helios/src/scheduler.rs:1216-1228 — three scans of
self.slotswhere one fold suffices (entry 3). Supporting nits in the same report: two test assertions that do not prove the named behaviour (cache/tests.rs:335; scheduler/tests.rs:1024 private half) and the docs/api.md:298-305 paragraph duplicating the metric table (entries 5 and 6 respectively). "Examined and kept" paragraph from entry 7, including whydirect_request_pinsis not dead weight.
Rules cited when judging: charter line 12 (keep the runtime small), line 35 (what gets merged), line 44 (GPU kernel defects only — not applicable, this PR has no kernel code); AGENTS.md lines 188-199 "Reject unsupported abstractions and churn" and "Require focused, meaningful validation"; docs/design-review.md principle 1 (keep Helios as simple as possible) and principle 16 (write without hidden context, via the repo-prose skill); .agents/skills/repo-prose/SKILL.md lines 38-39 (comments explain invariants, never history) and 44-46 (state the fact, not commentary about it).
Struct-field plumbing forced by the new fields, not findings: helios/src/cache/lifecycle_tests.rs:77-78 and :95 copy the two new counts in the lifecycle fixture's fork(); without them the fixture's projection would silently drop the request-pin state.
#11 [high] should fix: new scheduler test duplicates an existing test's setup line for line
helios/src/scheduler/tests.rs:970-1034 request_kv_pages_count_shared_prefix_pages_once duplicates branching_requests_own_distinct_tail_pages_and_terminal_snapshots (1036-1081) step for step: identical scheduler(2, 8, 5), seed admit spec(64,1), init(1), plan/commit(Fence(2)), complete(records(seed,2,64,1,77,2)), freeze(seed,3), finish(seed), two admits of spec(65,4), init(4), commit(5), complete(records(first,5,65,1,88,1)), retain_prompt(6), prefill of second, commit(7), complete(records(second,7,65,1,90,1)). Lines 972-1009 == 1038-1075.
Only 1010-1033 is new: the five lengths read off the two LiveRequests, the two stats assertions (request_pages == shared + first_private + second_private, reserved_pages == first_reserved + second_reserved), the two cancels, and the zero/cached_pages > 0 checks after retirement.
Smaller version: append 1010-1033 to the branching test (it ends at 1076-1080 by borrowing first/second; the stats assertions can precede those borrows and the cancels follow them), or extract fn shared_prefix_pair(&mut RequestScheduler) -> (RequestHandle, RequestHandle) used by both. Deletes ~38 lines of setup, or the whole 66-line test if merged.
Rule: AGENTS.md:188-199 "Reject unsupported abstractions and churn"/"Require focused, meaningful validation"; charter "smallest footprint".
Verified the two blocks are character-identical in steps (read 960-1140).
#12 [high] should fix (unchanged): cache pin_request/unpin_request walk the chain twice
Re-checked at head 9cca87a: unchanged from the previous report. helios/src/cache.rs:551-563 pin_request calls self.pin(id)? (which computes self.chain(id)? at 523 and walks it at 530-532) and then computes self.chain(id)? again at 554; unpin_request (565-580) does the same at 569 (unpin chains at 540) and 571. Two chain walks and two Vec<CheckpointId> allocations per request pin/unpin, and the ready/u64::MAX guard suite duplicated.
Call sites: scheduler.rs:1889 (ticket waiters), 2977/2979 and 2997/2998 (boundary publications), 3155 (retirement), plus the admission paths through pin_prefix/unpin_prefix (scheduler.rs:2025-2040, used at 1645/1656/1678).
Fix: one private fn pin_kind(&mut self, id, request: bool) that walks the chain once and bumps pins always plus request_pins/request_pinned_pages when request; pin/pin_request become one-line wrappers (unpin/unpin_request the mirror). Deletes ~30 lines and one traversal per call; the request_pins ⊆ pins invariant and the stats drift assertion (cache.rs:817-837) stay intact.
#17 [high] Report of 2026-11-27, run 2 (head 9cca87a)
Head 9cca87a (new commit "Keep page gauges out of the copy-out retry key"). Verdict: should-fix only, nothing blocking.
Fixed by 9cca87a, drop from the previous report: the copy-out key leak (blocker) — runtime.rs:2446-2450 now zeroes request_pages/reserved_pages; cache.rs:548-550 doc comment now says the cache counts only tail pages and the scheduler counts private pages; the retirement-block ordering (previous should-fix about request.take() before a fallible unpin) — scheduler.rs:3149-3156 now releases the pin before take().
Still open:
- should fix: cache.rs:551-580 double chain walk (entry 12).
- should fix (new): scheduler/tests.rs:970-1034 duplicates 1036-1081 (entry 11).
Nits (all present at 9cca87a): scheduler.rs:1216-1228 three scans (entry 3); scheduler.rs:3149-3156 re-derives locals already at 3116-3120 (entry 13); cache/tests.rs:335 redundant guard, already at 358 (entry 5); docs/api.md:309-312 test scaffolding in the API reference (entry 14); scheduler.rs:2025-2040 pass-through pin_prefix/unpin_prefix (entry 15); runtime.rs:2441-2450 field-masking literal because CopyoutResources embeds all of SchedulerStats (entry 16).
Withdrawn from the previous report: the "api.md prose duplicates the metric table" nit — api.md:332-355 is the JSON-snapshot-to-Prometheus-name table, and these two gauges have no JSON field, so the prose is their only home.
Increased: scheduler/tests.rs:970-1034 is now the single largest deletable block (~38 lines if merged into 1036-1081), bigger than the pin helper.
Evidence still unverifiable here: the live two-GPU scrape numbers. Rules cited: charter "smallest footprint in shared code"; AGENTS.md:188-193 (churn) and 194-199 (meaningful validation); docs/design-review.md principle 1 and 16; repo-prose SKILL.md 13-14, 26-29, 44-46.
#18 [high] Research summary
Verdict: should-fix issues only, nothing blocking.
Head 9cca87a ("Keep page gauges out of the copy-out retry key") fixed the previous round's blocker and two of its should-fix items: the copy-out retry key now masks the two new gauges (runtime.rs:2446-2450), the pin_request doc comment no longer claims the cache counts private pages (cache.rs:548-550), and retire releases the request pin before request.take() (scheduler.rs:3149-3156).
Should fix (2):
helios/src/scheduler/tests.rs:970-1034—request_kv_pages_count_shared_prefix_pages_oncerepeatsbranching_requests_own_distinct_tail_pages_and_terminal_snapshots(1036-1081) step for step; lines 972-1009 are identical to 1038-1075. Only the stats/cancel assertions at 1010-1033 are new. Merge them into the existing test (~38 lines deleted) or extract a shared setup helper.helios/src/cache.rs:551-580—pin_request/unpin_requeststill walk the ancestor chain twice (ping at 523 then 554; 540 then 571) and duplicate the guard code. One privatepin_kind(id, request: bool)with one-line wrappers deletes ~30 lines and a traversal per admission, ticket waiter, boundary publication and retirement.
Nits (6): three passes over self.slots in SchedulerStats::stats (scheduler.rs:1216-1228) where one fold serves; the retirement block re-reads prefix/error_code that already exist as locals at 3116-3120 (scheduler.rs:3149-3156); cache/tests.rs:335 re-tests the generic unpin guard already at tests.rs:358; docs/api.md:309-312 ends the gauge paragraph with test scaffolding that belongs in the PR description; pin_prefix/unpin_prefix (scheduler.rs:2025-2040) are pass-throughs that cost more lines than the conditionals they replaced; runtime.rs:2441-2450 now carries a masking literal because CopyoutResources embeds all of SchedulerStats.
Withdrawn: the earlier "api.md prose duplicates the metric table" nit — the table is JSON-snapshot fields, and these gauges have no JSON field, so the prose is their only home. The live two-GPU scrape numbers remain unverifiable from here. Full detail is in scratchpad entries 11-17.
#19 [high] Final report inputs at head 9cca87a: all findings with citations
Final report inputs for head 9cca87a ("Keep page gauges out of the copy-out retry key"). Everything below was re-read in the code at that commit.
RULES CITED
- Charter, "How We Work": "Solve the right problem in the right place … Look for the smallest footprint in shared code" (also line 12 "Keep the runtime small and model-agnostic").
- AGENTS.md:188-193 "Reject unsupported abstractions and churn" — "Refactoring must directly support the requested behavior or remove a demonstrated source of defects or cost."
- AGENTS.md:194-199 "Require focused, meaningful validation" — "Tests must exercise the affected behavior or contract".
- docs/design-review.md principle 1 ("Keep Helios as simple as possible") and principle 16 ("Write without hidden context", points at the prose skill).
- .agents/skills/repo-prose/SKILL.md:13-14 (describe the system as it exists; do not narrate the journey), :26-29 (documentation is a present-state specification, not a changelog or run journal), :38-39 and :44-46 (comments state invariants, not commentary).
SHOULD FIX 1 — helios/src/scheduler/tests.rs:970-1034
request_kv_pages_count_shared_prefix_pages_once reproduces branching_requests_own_distinct_tail_pages_and_terminal_snapshots (1036-1081) instruction for instruction: scheduler(2,8,5); admit spec(64,1); init(1); plan/commit(Fence(2)); complete(records(seed,2,64,1,77,2)); freeze(seed,3); finish(seed); admit spec(65,4) twice; init(4); commit(5); complete(records(first,5,65,1,88,1)); retain_prompt(6); assert prefill lane is second; commit(7); complete(records(second,7,65,1,90,1)). Lines 972-1009 == 1038-1075 verbatim.
Only 1010-1033 is new: the five lengths read from the two LiveRequests, the two stats assertions, the two cancels, and the (0,0)/cached_pages>0 checks.
Fix: append 1010-1033 to the branching test (its trailing borrows at 1076-1080 can follow the stats assertions), or extract fn shared_prefix_pair(&mut RequestScheduler) -> (RequestHandle, RequestHandle) from 972-1009 and call it from both. Either removes ~38 lines of duplicated setup; merging removes the whole 66-line test. The stats assertions are the only new evidence and they survive unchanged.
SHOULD FIX 2 — helios/src/cache.rs:551-563 and 565-580
pin_request calls self.pin(id)?, which computes self.chain(id)? at 523 and walks it at 530-532, then computes self.chain(id)? again at 554 and walks it again. unpin_request repeats the shape: self.unpin(id)? (chains at 540) then self.chain(id)? at 571. Two chain walks and two Vec<CheckpointId> allocations per request pin and per release, plus a second copy of the ready/u64::MAX guard suite.
Call sites: scheduler.rs:1889 (ticket waiters), 2977/2979 and 2997/2998 (boundary publications), 3155 (retirement), and the admission paths via pin_prefix/unpin_prefix at 1645/1656/1678.
Fix (code in entry 1): one private fn pin_kind(&mut self, id: CheckpointId, request: bool) -> Result<()> that validates once, walks the chain once, bumps pins always and, when request, also request_pins and request_pinned_pages; pin/pin_request become one-line wrappers, unpin/unpin_request the mirror. Deletes ~30 lines, one traversal per call. request_pins ⊆ pins and the drift assertion at cache.rs:817-837 are preserved, so request_pins_count_each_shared_page_once and every scheduler test keep passing unchanged.
NITS (all still present at 9cca87a)
- helios/src/scheduler.rs:1216-1228 —
stats()walksself.slotsthree times for the new pair (active count at 1203, private at 1216-1222, reserved at 1223-1228); onefoldseeded withcache.request_pinned_pagesyields both. Code in entry 3. - helios/src/scheduler.rs:3149-3156 — the moved retirement block re-reads
self.request(handle)?.prefixanderror_codealthoughlet prefix = request.prefix;already exists at 3120 anderror_codeis read at 3117; nothing mutates either between. Addlet failed = request.error_code.is_some();at 3120 and use both locals; two fewer slot lookups and no shadowed binding. Code in entry 13. - helios/src/cache/tests.rs:335 —
assert!(cache.unpin_request(parent).is_err())exercises thedirect_request_pins == 0guard, the same shape already covered for the plain API at tests.rs:358, and it usesparentonly because that node has no direct request pin. Drop it or move it to a guard test. The real evidence in the test is 331-334 and 336-341. Detail in entry 5. - docs/api.md:309-312 — the gauge paragraph ends "...and the test-only assertion in
Cache::statscompares the maintained request-pinned count with a full scan of every checkpoint on each read", documenting#[cfg(test)]scaffolding in the API reference; the PR description already carries that evidence. End the paragraph at "...excludes idle cached prefixes and snapshot backing pages." Entry 14. - helios/src/scheduler.rs:2025-2040 —
pin_prefix/unpin_prefixhave three call sites, all inadmit_planned, and both areif request { .. } else { .. }pass-throughs; they replaced 12 inline lines with 16. Once the cache has one entry point per direction (should-fix 2) they disappear and the three sites call the cache with the existingrequest_pinlocal (1643), or the cache takes aPinHolder::{Request, Ticket}. Not a blocker: they do encode the choice once, which the earlier review asked for. Entry 15. - helios/src/server/runtime.rs:2441-2450 — the fix masks
request_pages/reserved_pagesin a struct literal becauseCopyoutResources(1053-1059) embeds all 34 fields ofSchedulerStats, so every future gauge joins the comparison key by default and needs a second edit here. Correct as written; the smaller long-term version is forCopyoutResourcesto hold the cache-side values copy-out actually keys on. That changes which movements re-offer deferred copy-outs and needs its own justification — note it, do not demand it. Entry 16.
FIXED BY 9cca87a (do not re-report): copy-out retry-key leak (runtime.rs:2446-2450); pin_request doc comment (cache.rs:548-550 now correct — "the tail pages of the pinned checkpoints … private pages are counted by the scheduler"); retire ordering (pin released at 3151-3156 before request.take() at 3157).
WITHDRAWN: the previous "docs/api.md:298-305 duplicates the metric table" nit. The table at api.md:332-355 maps JSON Snapshot fields to Prometheus names; request_pages/reserved_pages have no JSON field (metrics.rs:1309-1318 only), so the prose paragraph is their only home.
VERIFIED AND KEPT (from entry 7, still true at 9cca87a): direct_request_pins (guard at 566); separate CacheStats::request_pinned_pages field (needed by both the drift assert at 824 and scheduler.rs:1222); the two Prometheus-only atomics reusing the existing gauge array, update table (metrics.rs:517-518) and test tuple array (1835-1836); the plain-pin path for inbound admissions (not live yet, re-pinned through pin_request at 1889); lifecycle_tests.rs:77-78/95 plumbing forced by the new fields. Invariants clean: compaction carries request pins (cache.rs:627 assert plus heir inherits tail pages), eviction still gates on pins/child_count.
UNVERIFIABLE HERE: the live two-GPU DeepSeek-V4.1-Flash scrape numbers (399/402, 3/2, ratios 0.0186/0.0187) — author's measurement of their own instance; settling it needs a scrape with a request held mid-prefill, not a unit test. No GPU kernel code in this PR, so the charter's defects-only kernel rule does not apply.
#21 [high] Head bca7358: previous two should-fix items are fixed
Verified at head bca7358 (re-read the code, not just the diff):
-
cache.rs double chain walk — FIXED.
fn pin_with(&mut self, id, request: bool)at helios/src/cache.rs:519-544 computeslet chain = self.chain(id)?;once (523) and walks it once (533-542);fn unpin_withat 546-570 likewise (553, 558-568). Public one-line wrappers:pin572-574,unpin576-578,pin_request583-585,unpin_request587-589. No duplicate traversal, no duplicated guard suite. Doc comment on pin_request (580-582) now correctly says the scheduler counts private pages. -
scheduler test duplication — FIXED. The old
request_kv_pages_count_shared_prefix_pages_onceis gone;branching_requests_own_distinct_tail_pages_and_terminal_snapshotsat helios/src/scheduler/tests.rs:970-1032 is the single test (setup 972-1009, new stats assertions 1010-1031). The old cache testrequest_pins_count_each_shared_page_oncewas also merged intobranching_pins_ancestors_and_prevents_direct_ancestor_unpin(helios/src/cache/tests.rs:320-373). -
Earlier nit "cache/tests.rs:335 re-tests the generic unpin guard" — FIXED: the
unpin_request(parent).is_err()assertion is gone; onlyassert!(cache.unpin(parent).is_err())at cache/tests.rs:336 remains. -
Earlier nit "docs/api.md ends the gauge paragraph with #[cfg(test)] scaffolding" — FIXED: docs/api.md:298-310 no longer mentions the Cache::stats assertion. The docs ratio claim was also corrected to (request + reserved) / total.
-
stats() single-pass fold — PARTIALLY FIXED: the two private/reserved scans are now one loop (scheduler.rs:1202-1209), but
retiring_slots(1213),checkpoint_anchor_guards(1216) andinbound_waiting(1222-1233) still each walkself.slotsseparately, and all three could be folded into the new loop.
#22 [high] Nits at head bca7358 (lens D)
All verified by reading the code at head bca7358.
N1 (nit) helios/src/cache.rs:529-532 — two self.nodes.get_mut(&id) lookups back to back in pin_with; same shape at 554-557 in unpin_with, and unpin_with reads self.checkpoint(id)? twice (547 and 550). Smaller: bind once.
let node = self.nodes.get_mut(&id).unwrap(); node.direct_pins += 1; if request { node.direct_request_pins += 1; }
unpin: let (request_pins, direct_pins) = { let n = self.checkpoint(id)?; (n.direct_request_pins, n.direct_pins) }; then the two guards, then one get_mut. Deletes ~4 lines and 2 hashes per pin/release. Note chain includes id itself (chain() at 312-321 starts at id), so this is the only place direct pins are bumped — do not try to fold them into the loop without changing what the loop iterates.
N2 (nit) helios/src/scheduler.rs:1202-1218 — the new loop counts active/private/reserved, but retiring_slots (1213), checkpoint_anchor_guards (1216) and inbound_waiting (1222-1233) still scan self.slots separately; stats() runs from the worker loop on every progress (server/runtime.rs:2441-2450 calls self.scheduler.stats()). Fold all three into the one loop:
for slot in &self.slots { retiring += slot.retiring as usize; if let Some(r) = &slot.request { active += 1; pages += r.private_pages.len(); reserved += r.reserved_pages.len(); guards += r.anchor_guard.is_some() as usize; inbound += (r.phase == RequestPhase::Inbound) as usize; } }
then inbound_waiting: if self.tickets.is_empty() { 0 } else { inbound }. Deletes three passes and ~14 lines.
N3 (nit) helios/src/scheduler.rs:3144-3148 — the moved retirement block re-reads the slot: if let Some(prefix) = self.request(handle)?.prefix { if !publish || self.request(handle)?.error_code.is_some() { although let prefix = request.prefix; exists at 3113 and request.error_code is read at 3110 in refresh_recency; nothing mutates either in between. Add let failed = request.error_code.is_some(); beside 3113 and use prefix / failed. Removes two self.request(handle)? lookups and a shadowed binding.
N4 (nit, opinion) helios/src/scheduler.rs:2018-2033 vs helios/src/cache.rs:519-589 — pin_prefix/unpin_prefix take the same request: bool the cache's private pin_with/unpin_with take, so the "is this a request pin?" decision is dispatched twice; the helpers have exactly three call sites, all in admit_planned (1638, 1649, 1671). Smaller: drop the pair and, since the cache already has the bool implementation, make it the single entry point the scheduler calls (e.g. pub(crate) pin_for/unpin_for(id, request)), or keep the four named public methods and inline the two-branch choice at those three sites. Either way one layer goes; ~14 lines stay or go depending on which.
N5 (nit) docs/api.md:298-310 — 13 lines / ~120 words for two gauges, where the other page gauges get one table row each. It carries five separable facts (definitions, overlap with cached, exclusions, publication timing, comparable share). Trim/reshape to: definition sentence per gauge; one sentence on the cached-gauge overlap and the excluded pages; one on publication timing; one on the comparable share. ~7 lines. Cite .agents/skills/repo-prose/SKILL.md:26-29 (present-state spec, no run journal) — nothing incorrect remains, only density.
NOTE (not a request) helios/src/server/runtime.rs:2441-2450 — the mask (request_pages: 0, reserved_pages: 0, ..self.scheduler.stats()) exists only because CopyoutResources embeds the whole SchedulerStats (fields at 1053-1059 area), so every future field silently joins the deferred-copy-out comparison key. Correct today; the smaller form is a dedicated CopyoutResources key struct, which changes what re-offers deferred copy-outs and needs its own justification.
Kept (checked, no finding): direct_request_pins (guard at cache.rs:547, not derivable from pins); transitive request_pins (needed: a shared ancestor has 0 direct request pins but 2 descendant ones); separate CacheStats::request_pinned_pages field (cache.rs:189/851 read by scheduler.rs:1220 and by the drift assert at cache.rs:825-845); request/plain pin split at the admission sites (inbound ticket parents keep plain pins, re-pinned as request pins in resolve_tickets at scheduler.rs:1882); compaction assert + heir inheritance (cache.rs:636-641) which keeps the count without a re-scan; lifecycle_tests.rs:77-78/95 plumbing forced by the new fields; the two Prometheus-only atomics (metrics.rs:265-266) reusing the existing gauge table (1309-1318) and test tuple array (1835-1836).
#23 [high] Nit at bca7358: request-pin guard has no test; field exists only for it
New at head bca7358, verified by grep + reading:
Checkpoint::direct_request_pins(cache.rs:83) has exactly one consumer: theunpin_requestguard at cache.rs:547-549 (if request && self.checkpoint(id)?.direct_request_pins == 0 { return Err("checkpoint has no request pin to release") }). It is written at 531 and 556 only.- bca7358 deleted the only test that exercised that branch: the merged cache test now has just
assert!(cache.unpin(parent).is_err())at cache/tests.rs:336 (plainunpin, i.e. thedirect_pins == 0guard).unpin_requestis called only at cache/tests.rs:338 and 359, both on checkpoints that hold a request pin. No scheduler test reaches the branch either (scheduler.rs:2972, 2991, 3148 all unpin a request-pinned prefix). - So a field (2 lines incl. doc comment), an increment, a decrement and an error string now exist for a branch no test reaches.
- Either: restore one line to the cache test (
assert!(cache.unpin_request(parent).is_err())before 338, whereparentholds only descendant request pins) — cheapest; or drop the guard anddirect_request_pinsentirely (deletes ~8 lines across cache.rs:83, 461, 531, 547-549, 556, lifecycle_tests.rs:77), accepting that a double release silently decrementsrequest_pinsinto the drift assertion instead of erroring. - Semi-corrects my earlier "keep
direct_request_pins" note (entry 19/22): the field is still not derivable frompins, but its justification is now only the untested guard. - Minor:
debug_assert!(node.request_pins > 0)at cache.rs:562 restates an invariant the drift assertion at 826-846 already enforces on every stats read; can go with N1 if the guard stays.
#25 [high] Report of 2026-11-28 (head bca7358)
Simplicity review of PR #549 "Report KV pages held by active requests" (head bca7358)
Verdict
Nits only; nothing blocking, nothing should-fix. Both should-fix items from the 9cca87a round are fixed at bca7358, and so are three of the six nits. What remains is five small reductions, worth ~30 lines plus two hash lookups per pin, none of which changes a gauge value.
This round's commit (bca7358, "Fix KV-page docs ratio and fold duplicated page tests") is exactly the kind of change the previous round asked for: it folded request_pins_count_each_shared_page_once into branching_pins_ancestors_and_prevents_direct_ancestor_unpin (cache/tests.rs:320-373), folded request_kv_pages_count_shared_prefix_pages_once into branching_requests_own_distinct_tail_pages_and_terminal_snapshots (scheduler/tests.rs:970-1032), collapsed pin_request/unpin_request onto one pin_with/unpin_with that walks the chain once (cache.rs:519-589), removed the #[cfg(test)] sentence from the API doc (api.md:298-310), and corrected the comparable share to (request + reserved) / total. Net −34 lines while adding the docs correction.
Fixed since the last review (do not re-report)
- cache.rs double chain walk → single
pin_with/unpin_with(cache.rs:519-570), wrappers at 572-589. - scheduler test duplication → one test (scheduler/tests.rs:970-1032).
- cache/tests.rs:335 generic-guard re-test → gone (only
unpin(parent)at 336 remains). - docs/api.md test-scaffolding clause → gone.
- stats() private/reserved two scans → one loop (scheduler.rs:1202-1209).
Nits (all verified in the code at bca7358)
- cache.rs:529-532 / 554-557, and 547+550 — two
nodes.get_mutlookups back to back; bind the node once.unpin_withalso readsself.checkpoint(id)?twice (547, 550). ~4 lines and 2 lookups per pin/release. (chain() at 312-321 starts atid, so this is the only place direct pins are bumped — do not fold them into the loop.) - scheduler.rs:1202-1218 — the new loop counts active/private/reserved, but
retiring_slots(1213),checkpoint_anchor_guards(1216) andinbound_waiting(1222-1233) each still scanself.slots;stats()runs from the worker loop on every progress (runtime.rs:1148-1149, 722, 745). Fold all three into the one loop: ~14 lines and three passes. - scheduler.rs:3144-3148 — the moved retirement block re-reads the slot twice although
let prefix = request.prefix;(3113) andrequest.error_code(3110) are already in hand; nothing mutates either in between. Addlet failed = request.error_code.is_some();at 3113 and use both locals. - scheduler.rs:2018-2033 vs cache.rs:519-589 —
pin_prefix/unpin_prefixare 16 lines ofif request {…} else {…}dispatching a bool the cache already dispatches. Makepin_with/unpin_withpub(crate)(aspin_for/unpin_for) and delete the pair; the three call sites (1638, 1649, 1671) passrequest_pin. Answers round 1's "same conditional three times" without a second layer. ~16 lines. - cache.rs:83 + 547-549 / cache/tests.rs:336 —
direct_request_pinsnow exists only for theunpin_requestguard, and bca7358 deleted the only test that reached it (theunpin_request(parent).is_err()assertion). Either restore that one line before cache/tests.rs:338 (whereparentholds only descendant request pins) or drop field+guard (~8 lines across 83, 461, 531, 547-549, 556, lifecycle_tests.rs:77), letting the drift assertion catch a double release. Minor:debug_assert!(node.request_pins > 0)at 562 restates an invariant the drift assertion (826-846) already enforces on every stats read. - docs/api.md:298-310 — 13 lines / ~120 words for two gauges where every other page gauge gets one table row; five separable facts. Nothing incorrect remains (the ratio and the overlap are now right); trim to ~7 lines: definition per gauge, overlap+exclusions, publication timing, comparable share.
Not a request, note only: runtime.rs:2441-2450 — the ..self.scheduler.stats() mask exists because CopyoutResources (1053-1059) embeds the whole SchedulerStats, so each future field silently joins the deferred-copy-out key. A dedicated key struct is smaller long-term but changes which movements re-offer copy-outs; needs its own justification.
Examined and kept
direct_request_pins's non-derivability (a node can be pinned by both a request and copy-out) — though see nit 5; transitive request_pins (a shared ancestor has 0 direct request pins but 2 descendant ones); separate CacheStats::request_pinned_pages (read by scheduler.rs:1220 and by the drift assert at cache.rs:825-845); the request/plain pin split at admission (inbound ticket parents keep plain pins and are re-pinned as request pins at 1882); compaction's assert plus heir inheritance (cache.rs:636-641) keeping the count without a re-scan; eviction gating on pins/child_count (668-672) so a request-pinned node cannot be removed; lifecycle_tests.rs:77-78, 95 plumbing forced by the new fields; the two Prometheus-only atomics (metrics.rs:265-266) reusing the existing gauge table (1309-1318) and test tuple array (1835-1836); the #[cfg(test)] drift assertion itself (826-846) — it is the only thing checking request_pins ⊆ pins and its cost is confined to tests.
Not verifiable from here
The live two-GPU DeepSeek-V4.1-Flash scrape numbers (399/402 request pages, 3/2 reserved, 0.0186-0.0188) are the author's own instance measurement; settling them needs a scrape with a request held mid-prefill, not a unit test. Outside this lens. No CUDA or low-level GPU kernel code in the PR, so the charter's defects-only kernel rule does not apply.
Rules cited
Charter "How We Work": "Look for the smallest footprint in shared code" and "Keep the runtime small and model-agnostic". AGENTS.md:188-193 "Reject unsupported abstractions and churn" (refactoring must remove a demonstrated cost); AGENTS.md:194-199 "Require focused, meaningful validation" (tests must exercise the contract they name — the basis for nit 5). docs/design-review.md principle 1 (keep Helios as simple as possible) and principle 16 (write without hidden context), pointing at .agents/skills/repo-prose/SKILL.md:26-29 (documentation is a present-state specification) for nit 6.
#27 [high] Research summary
Reviewed PR #549 at head bca7358 through the simplicity lens. Verdict: nits only — nothing blocking, nothing should-fix. Both should-fix findings from the previous round are fixed by this commit: pin_request/unpin_request now collapse onto a single pin_with/unpin_with that walks the checkpoint chain once (cache.rs:519-589), and the duplicated scheduler test was folded into branching_requests_own_distinct_tail_pages_and_terminal_snapshots (scheduler/tests.rs:970-1032). Three earlier nits are also gone (the generic-guard re-test, the #[cfg(test)] clause in the API doc, and one of the slots scans), and the comparable-share sentence in docs/api.md was corrected.
Five remaining reductions, all verified in the code, none changing a gauge value: (1) pin_with/unpin_with take two nodes.get_mut lookups per call and unpin_with reads the checkpoint twice; (2) SchedulerStats::stats still walks self.slots for retiring_slots, checkpoint_anchor_guards and inbound_waiting separately instead of folding them into the new loop, and stats() runs from the worker loop on every progress; (3) the moved retirement block re-reads prefix/error_code it already holds as locals; (4) pin_prefix/unpin_prefix are 16 lines of bool dispatch on top of a cache that dispatches the same bool — make the cache entry point pub(crate) and delete them; (5) Checkpoint::direct_request_pins now exists only for the unpin_request guard, and this commit deleted the one assertion that reached it, so restore that line or drop field and guard. Plus one prose-trim nit on the 13-line gauge paragraph, and a note (not a request) that CopyoutResources embedding all of SchedulerStats is what forces the mask in runtime.rs:2441-2450.
Kept with reasons: transitive request_pins, the separate CacheStats::request_pinned_pages field, the request/plain pin split at admission, compaction's assert plus heir inheritance, the #[cfg(test)] drift assertion, and the Prometheus-only atomics that reuse the existing gauge table. No CUDA or low-level GPU code in the PR.
#28 [high] Final report inputs at head bca7358: per-finding citations, severity, fixes
Supersedes entries 19 and 20 (those were head 9cca87a; line numbers there are stale). Everything below was re-read at head bca7358.
VERDICT: nits only. 0 blocking, 0 should-fix, 6 nits.
RULE CITATIONS
- Charter, "How We Work": "Look for the smallest footprint in shared code, or a way to solve it without new code at all"; and "Keep the runtime small and model-agnostic."
- AGENTS.md:188-193 "Reject unsupported abstractions and churn" — refactoring must remove a demonstrated source of defects or cost.
- AGENTS.md:194-199 "Require focused, meaningful validation" — tests must exercise the affected behaviour or contract (basis for nit 5).
- docs/design-review.md principle 1 (keep Helios as simple as possible), principle 16 (write without hidden context) → .agents/skills/repo-prose/SKILL.md:26-29 (documentation is a present-state specification, not a run journal) for nit 6.
- No CUDA / low-level GPU kernel code in this PR, so the charter's kernels-defects-only rule does not apply.
NIT 1 — helios/src/cache.rs:529-532 (pin) and 554-557 (unpin), plus 547 + 550.
Two self.nodes.get_mut(&id).unwrap() lookups in a row; unpin_with also calls self.checkpoint(id)? twice (guard at 547, second guard at 550).
Fix: let node = self.nodes.get_mut(&id).unwrap(); node.direct_pins += 1; if request { node.direct_request_pins += 1; }. For unpin bind let (request_pins, direct_pins) = { let n = self.checkpoint(id)?; (n.direct_request_pins, n.direct_pins) };, run both guards, then one get_mut. ~4 lines and 2 hash lookups per pin and per release on the admission, ticket-waiter, boundary-publication and retirement paths.
Caution for the fixer: chain() (cache.rs:312-321) starts at id itself, so this is the only place direct pins are bumped — do not fold them into the ancestor loop.
NIT 2 — helios/src/scheduler.rs:1202-1218 (and 1222-1233).
The commit merged the private/reserved scans into one loop, but retiring_slots (1213), checkpoint_anchor_guards (1216) and inbound_waiting (1222-1233) each still walk self.slots separately. stats() is called from the worker loop on every progress pass (helios/src/server/runtime.rs:1148-1149), at startup (722) and after the shutdown drain (745).
Fix: fold all three into the existing loop —
for slot in &self.slots { retiring += slot.retiring as usize; if let Some(r) = &slot.request { active += 1; pages += r.private_pages.len(); reserved += r.reserved_pages.len(); guards += r.anchor_guard.is_some() as usize; inbound += (r.phase == RequestPhase::Inbound) as usize; } }
then inbound_waiting: if self.tickets.is_empty() { 0 } else { inbound }. ~14 lines and three passes.
NIT 3 — helios/src/scheduler.rs:3144-3148.
The retirement block calls self.request(handle)? twice to re-read prefix and error_code, although let prefix = request.prefix; is at 3113 and request.error_code is already read at 3110 (refresh_recency). Nothing mutates either between (writers are in complete).
Fix: add let failed = request.error_code.is_some(); beside 3113 and use prefix / failed; two fewer slot lookups and no shadowed binding. This block is the commit's own move (it now runs before request.take() at 3150), so the re-read is newly introduced.
NIT 4 — helios/src/scheduler.rs:2018-2033 versus helios/src/cache.rs:519-589.
pin_prefix/unpin_prefix are 16 lines of if request { cache.pin_request } else { cache.pin }, i.e. a second dispatch of the same bool the cache already dispatches in pin_with/unpin_with. Three call sites, all in admit_planned (1638, 1649, 1671), passing request_pin from 1636.
Fix: make the cache entry points pub(crate) (e.g. pin_for/unpin_for) and delete the pair; sites read self.cache.pin_for(id, request_pin)?. Net −16 lines and one layer, and it still answers round 1's "same if inbound.is_none() conditional three times". Do not instead inline the conditional at the sites — that adds lines.
Related, pre-existing (not introduced here): pin_checkpoint/unpin_checkpoint (2035-2043) are the same shape; out of scope.
NIT 5 — helios/src/cache.rs:83, 461, 531, 547-549, 556 and helios/src/cache/tests.rs:336.
Checkpoint::direct_request_pins now has exactly one consumer, the unpin_request guard at 547-549 ("checkpoint has no request pin to release"). bca7358 deleted the only assertion that reached it (the old assert!(cache.unpin_request(parent).is_err())); what remains at cache/tests.rs:336 is the plain-unpin guard, and both surviving unpin_request calls (338, 359) follow a pin_request on the same id. Scheduler call sites 2972, 2991, 3148 likewise.
Why it matters: AGENTS.md:194-199 — a field, an increment, a decrement and an error string whose only branch no test reaches; a double release would otherwise trip the drift assertion rather than error.
Fix (cheapest): restore one line before cache/tests.rs:338 — assert!(cache.unpin_request(parent).is_err());, valid because parent holds only descendant request pins. Alternative: drop the guard and the field (~8 lines across 83, 461, 531, 547-549, 556, lifecycle_tests.rs:77) and let the drift assertion catch a double release.
Also: debug_assert!(node.request_pins > 0) at cache.rs:562 restates an invariant the drift assertion (826-846) already enforces on every stats read; it can go with nit 1.
NIT 6 — docs/api.md:298-310.
13 lines / ~120 words for two gauges, where every other page gauge gets one table row (cached_pages, free_pages, total_pages at api.md:350-352). Nothing incorrect remains — the "not disjoint from flare_cached_kv_pages" sentence, the exclusions and the (request + reserved) / total share are all right, and "publishes both when a scheduler pass makes progress, and again at startup and after the shutdown drain" matches runtime.rs:722, 1148-1149, 743-745.
Fix (density only, per repo-prose 26-29): one definition sentence per gauge, one sentence on the cached-gauge overlap plus the excluded pages (draining after retirement, a restore ticket's in-flight pages), one on publication timing, one on the comparable share. ~7 lines.
NOTE, not a request — helios/src/server/runtime.rs:2441-2450.
The mask SchedulerStats { request_pages: 0, reserved_pages: 0, ..self.scheduler.stats() } exists only because CopyoutResources (1053-1059) embeds all of SchedulerStats, so every future field joins the deferred-copy-out comparison key by default and needs a second edit here. Correct as written; a dedicated key struct is smaller long-term but changes which movements re-offer deferred copy-outs and needs its own justification.
FIXED BY bca7358 (do not re-report)
- Double chain walk:
pin_with/unpin_withcomputechain(id)once (cache.rs:523, 553) and walk it once (533-542, 558-568); public wrappers at 572-578 and 583-589; thepin_requestdoc comment at 580-582 is now correct about private pages. - Scheduler test duplication: single test
branching_requests_own_distinct_tail_pages_and_terminal_snapshotsat scheduler/tests.rs:970-1032 (setup 972-1009, new assertions 1010-1031);request_kv_pages_count_shared_prefix_pages_onceis gone. - cache/tests.rs generic-guard re-test: only
assert!(cache.unpin(parent).is_err())at 336 remains (see nit 5 for what this cost). - docs/api.md
#[cfg(test)]sentence removed; ratio corrected to (request + reserved) / total. - One of the two extra
slotsscans merged (see nit 2 for the three that remain).
KEPT, with reasons
- Transitive
request_pins: a shared ancestor has 0 direct request pins but 2 descendant ones, so it cannot be derived fromdirect_request_pins. - Separate
CacheStats::request_pinned_pages(cache.rs:189, 851): read by scheduler.rs:1220 and by the drift assertion at cache.rs:825-845; folding it intocached_pageswould lose the distinction the docs depend on. - The request/plain pin split at admission (cache.rs:1636-1671 logic): inbound ticket parents keep plain pins and are re-pinned as request pins at resolve_tickets (scheduler.rs:1882), so the distinction is real, not an option.
- Compaction:
debug_assert_eq!(node.request_pins, child.request_pins)(cache.rs:636) plus heir inheriting the ancestor's tail pages (638-641) keeps the count correct with no re-scan; eviction still gates onpins/child_count(668-672) so a request-pinned node can't be removed. - The
#[cfg(test)]drift assertion (cache.rs:826-846) is the only check ofrequest_pins ⊆ pins; cost confined to tests. - lifecycle_tests.rs:77-78, 95 plumbing is forced by the new fields (the fixture's
fork()would otherwise drop request-pin state). - The two Prometheus-only atomics (metrics.rs:265-266) reuse the existing gauge table (1309-1318), update tuple table (517-518) and test expectation array (1835-1836); no JSON
Snapshotfield, which docs/api.md states explicitly. flare_reserved_kv_pagesitself is in scope: #537 asks for pages held by active requests, and the reserve is the non-free/non-cached/non-written share the docs define.
NOT VERIFIABLE FROM HERE The live two-GPU DeepSeek-V4.1-Flash scrape numbers (request 399/402, reserved 3/2, cached 2037/2043, ratio 0.0186-0.0188, bound request+reserved ≤ total−free) are the author's own instance measurement; settling them needs a scrape with a request held mid-prefill, not a unit test. Outside this lens and it does not change the verdict.
#3 [medium] nit: SchedulerStats::stats scans slots three times
helios/src/scheduler.rs:1216-1228. stats() is called from the runtime loop whenever anything progressed (server/runtime.rs:1148-1149) and now iterates self.slots twice more (once for private_pages, once for reserved_pages) after the existing active_requests scan.
Smaller version: one pass.
let (private, reserved) = self
.slots
.iter()
.filter_map(|slot| slot.request.as_ref())
.fold((0, 0), |(private, reserved), request| {
(private + request.private_pages.len(), reserved + request.reserved_pages.len())
});
then request_pages: private + cache.request_pinned_pages, reserved_pages: reserved. Three scans of the slot array become one, and the two new fields read as the pair that docs/api.md describes.
Also: LiveRequest::pages() (scheduler.rs:385-387) already exists as the per-request iterator for shared_pages.chain(&private_pages); it is unused by metrics, so no change needed there, but the new code should not invent a second notion of "the pages a request holds".
#5 [medium] nit: two assertions do not prove the behaviour they are named for
Two tests in the diff that do not prove what their names claim:
-
helios/src/cache/tests.rs:317-341,
request_pins_count_each_shared_page_once. Aftercache.pin(right_id)(line 333) the comment on the next line says the plain pin must leave the count alone (334), which is the one behaviour the extra plain pin exists to show — fine. But line 335assert!(cache.unpin_request(parent).is_err())checks only that a checkpoint withdirect_request_pins == 0is rejected; that behaviour is already covered generically byunpin_request's guard and by the pre-existingassert!(cache.unpin(parent).is_err())pattern at tests.rs:358. It is not evidence about request pins, and it usesparentonly because it happens to have no direct request pin. Keep it or drop it, but it is not one of the "3 rather than 4"/"plain pins leave it unchanged" claims and the comment should not present it as such. -
helios/src/scheduler/tests.rs:1024-1025.
assert_eq!(stats.request_pages, shared + first_private + second_private)recomputes the expectation withshared_pages.len()taken from the sameLiveRequestthe implementation sums. It does show the shared pages are added once (both requests carry the sameshared_pagesvector of lengthshared, and the sum isshared, not2 * shared), which is the point; that part is real evidence. Butfirst_private/second_privateare read from the requests and added directly, so that half of the assertion can only fail ifstats()misreadsprivate_pages. Acceptable, worth one sentence in the comment saying which half is the real claim.
The stronger check that the diff does add is the #[cfg(test)] drift assertion at cache.rs:817-837, which recomputes request_pinned_pages from a full scan on every stats() call; it covers every cache and scheduler test. Keep it. Note it is #[cfg(test)] only, so a debug build without cfg(test) does not check the maintained count; that is the same treatment the pre-existing counts get, so no change requested.
#6 [medium] nit: docs/api.md gauge paragraph duplicates the metric table and narrates implementation
docs/api.md:298-305 adds a paragraph defining the two gauges. Two things a simplicity reviewer can trim:
- "Both are gauges read from scheduler state on each scrape." The first half is already implied by the metric-type convention stated earlier in the page (
flare_counters and gauges, api.md:287-296) and every metric in the gauge table; "read from scheduler state on each scrape" is implementation narration a dashboard author cannot use. Delete the sentence. - "Dividing
flare_request_kv_pagesbyflare_total_kv_pagesgives the KV share held by live requests; idle cached prefixes and snapshot backing pages are outside that share." This is the useful part (it answers #537 directly) and should stay. The trailing clause is a fact about what the numerator excludes; keep it, but it repeats the numerator definition in the previous sentence ("their private pages plus the tail pages of the prefix checkpoints they pin"). One of the two enumerations can go.
Also note the page keeps a metric table (api.md:325-346) with cached_pages/free_pages rows; the two new gauges are documented in prose but not added to that table, so a reader who scans the table cannot find them. Same content, one home: either add request_pages/reserved_pages rows with Prometheus names flare_request_kv_pages/flare_reserved_kv_pages, or keep the prose. Both is duplication.
#7 [medium] checked and kept: direct_request_pins, separate CacheStats field, metrics atomics
Considered and kept (no finding):
Checkpoint::direct_request_pins(cache.rs:82-83, 461, 553, 566, 570). It has no consumer other than theunpin_requestguard at 566. It cannot be derived frompins, because a node can be pinned both by a request and by host-store copy-out (pin_checkpoint, scheduler.rs:2038), and without it a double request unpin would driverequest_pinsbelow its true value instead of erroring. Eight bytes per checkpoint and one line in the lifecycle fixture (cache/lifecycle_tests.rs:77) is the price of the guard. Keep.CacheStats::request_pinned_pagesas a separate field rather than folding it intocached_pages: the drift assertion and the scheduler sum both need the separated value. Keep.- The two new
Metricsatomics (metrics.rs:265-266) with no JSONSnapshotfield: docs/api.md explicitly states the Prometheus-only contract, and #548/#549 merging in the same file in different regions is confirmed by the diff (page gauges besidecached_pagesonly). No rebase simplification available.
Verified defect-free in this lens: pin_request/unpin_request keep request_pins a subset of pins and restore request_pinned_pages to zero; compaction moves the count through debug_assert_eq!(node.request_pins, child.request_pins) (cache.rs:627) combined with the heir inheriting node.tail_pages at 629-631, so the request_pinned_pages total is unchanged across compaction; retire_leaf/uncount cannot remove a node with request pins because eviction_candidates still gates on pins/child_count (cache.rs:658-663).
#13 [medium] nit: retirement block re-derives values it already holds
Head 9cca87a. helios/src/scheduler.rs:3120 already has let prefix = request.prefix; and 3116-3119 already read request.error_code.is_none() while request is borrowed. The moved retirement block (3149-3156) re-reads both through two extra self.request(handle)? calls and shadows the outer prefix:
if let Some(prefix) = self.request(handle)?.prefix {
if !publish || self.request(handle)?.error_code.is_some() { self.record_publication(prefix); }
self.cache.unpin_request(prefix)?;
}
Same values (nothing between 3120 and 3149 mutates request.prefix or error_code; 2716/2779 are the only writers and they run in complete). Smaller version: add let failed = request.error_code.is_some(); beside let prefix = request.prefix; at 3120, then
if let Some(prefix) = prefix {
if !publish || failed { self.record_publication(prefix); }
self.cache.unpin_request(prefix)?;
}
Two fewer slot lookups and one less shadowed binding per retirement. No behaviour change.
#14 [medium] nit: api.md ends its gauge paragraph with test scaffolding
Head 9cca87a, docs/api.md:309-312: "...and the test-only assertion in Cache::stats compares the maintained request-pinned count with a full scan of every checkpoint on each read."
This documents test scaffolding inside the API reference (a #[cfg(test)] assert at cache.rs:817-837). Under .agents/skills/repo-prose/SKILL.md:13-14 and :26-29 (documentation is a present-state specification, not a changelog or validation journal) and docs/design-review.md principle 16, evidence belongs in the PR description, which already states it. Also note the sentence sits inside the paragraph that also carries the ratio claim, so deleting the clause keeps that claim.
Smaller version: end the paragraph at "...excludes idle cached prefixes and snapshot backing pages."
Remaining 298-308 content (definitions, staleness of the published values, overlap with flare_cached_kv_pages, exclusions) is fine and is the right home for these two gauges, because the table at api.md:332-355 lists JSON snapshot fields plus their Prometheus names and these two gauges have no JSON field. So the earlier "table vs prose duplication" nit is withdrawn.
#15 [medium] nit: pin_prefix/unpin_prefix are pass-throughs worth collapsible with the cache API
New in 9cca87a. scheduler.rs:2025-2040 add pin_prefix/unpin_prefix (16 lines incl. a 2-line doc). They replaced three inline if inbound.is_none() { pin_request } else { pin } blocks at 1645 (pin) and 1656/1678 (unpin) — 12 lines of removed diff — so the net is about +6 lines and two more private functions with three call sites, all inside admit_planned.
pin_prefix has exactly one call site (1645). Smaller version once the cache exposes one entry point for both pin kinds (see entry 12's pin_kind): delete both helpers and call the cache directly at the three sites with the existing request_pin local (1643). If the positional bool is considered opaque, give the cache pin(id, holder: PinHolder) with PinHolder::{Request, Ticket}, still one function per direction instead of four.
Do not file as a blocker: the helpers do encode the choice once, which is what the earlier review asked for; the point is only that the line count grew and the wrappers are pass-throughs.
Rule: AGENTS.md:188-193 "Reject unsupported abstractions and churn … Refactoring must directly support the requested behavior".
#16 [medium] nit: the copy-out key masks gauge fields because it embeds the whole stats struct
New in 9cca87a, runtime.rs:2441-2455. CopyoutResources (1053-1059) embeds the whole SchedulerStats, which now carries two per-scrape gauges, so the memo key churned during decode (private_pages/reserved_pages move at scheduler.rs:2442-2444 without any cache movement). The fix zeroes them in a struct literal:
scheduler: crate::scheduler::SchedulerStats {
request_pages: 0, reserved_pages: 0, ..self.scheduler.stats()
},
Correct, and the only place copy-out state is keyed. Simplicity point: this is a 3-line comment plus a field-masking literal compensating for embedding a 34-field stats struct in a comparison key; every future gauge joins the key by default and needs a second edit here. Smaller version: have CopyoutResources hold the cache-side values copy-out actually depends on (free_pages, free_snapshots, cached_pages, cached_checkpoints, snapshot_backing_pages) rather than the whole struct. That changes which movements re-offer deferred copy-outs, so it needs its own justification and is not required for this PR; record as a nit, not a blocker, and do not claim the current form is wrong.
#24 [medium] Nit N4 corrected: make cache pin_for pub(crate) and delete the scheduler pass-throughs
Refinement of N4 (verified): do not inline the two-branch choice at the sites — that would add lines. The reduction is the other direction: make the cache's pin_with/unpin_with (helios/src/cache.rs:519, 546) pub(crate) (or rename to pin_for/unpin_for) and delete pin_prefix/unpin_prefix (helios/src/scheduler.rs:2018-2033, 16 lines). The three call sites (1638, 1649, 1671) then read self.cache.pin_for(id, request_pin)? / self.cache.unpin_for(id, request_pin)?, which answers the round-1 review comment ("the same if inbound.is_none() conditional three times") at least as well, since the kind is now an argument rather than a second dispatch layer. Net −16 lines, −1 abstraction.
Also present and pre-existing (do not report as introduced by this PR, but relevant to N4): pin_checkpoint/unpin_checkpoint (scheduler.rs:2035-2043) are the same shape of pass-through onto self.cache.pin/unpin; with pin_for in place, pin_checkpoint(id) becomes self.cache.pin_for(id, false) and could be deleted too, but its callers are in server/runtime.rs (2396 etc.), so it is a separate, larger change.
#26 [medium] Pre-finish cross-checks at bca7358
Cross-check done before finishing at head bca7358:
- docs/api.md:305-310 ("publishes both when a scheduler pass makes progress, and again at startup and after the shutdown drain") matches the code: runtime.rs:722 (startup), 1148-1149 (progress), 743-745 (after the shutdown drain, guarded by
shutdown.drained). Accurate; no finding. - SchedulerStats::stats() call sites that pay the extra passes: runtime.rs:722, 745, 1149; tests and dashboard. Supports nit 2 cost claim.
- Only consumer of
CacheStats::request_pinned_pagesoutside tests is scheduler.rs:1220; no other field/plumbing is redundant. unpin_requestcall sites (cache/tests.rs:338, 359; scheduler.rs:2972, 2991, 3148) all follow apin_requeston the same id, so thedirect_request_pins == 0guard at cache.rs:547-549 is unreached by any test after bca7358 removed the assertion — nit 5 stands; nothing suggests the guard is reachable in production code, so it is a test-coverage nit, not a defect.
#4 [low] no finding: metrics.rs plumbing and the inbound pin split
helios/src/server/metrics.rs:1309-1318 add two more (name, help, value) triples to the existing array-based gauge renderer; helios/src/server/metrics.rs:517-518 add two rows to the existing for (target, value) array; the test at 1835-1836 adds two entries to the existing (name, value) array. Nothing here is a parallel path or a new mechanism — the change reuses the established rendering and update tables. JSON Snapshot deliberately omits them (docs/api.md:307-323, ..Snapshot::default() at metrics.rs:384), so no second representation is introduced.
No finding for metrics.rs or for the scheduler call-site split at scheduler.rs:1643-1689 (plain pin for a request that is not yet an active request because it waits on a host-store ticket, request pin otherwise): the inbound case genuinely has no live-request pin until finish_inbound re-pins at 1900, which the test request_kv_pages_count_shared_prefix_pages_once and Cache::stats's drift assertion cover.