Simplicity scratchpad · NVIDIA/hyperflare-inference #549

Raw Markdown for agents: https://autobot.eidonix.com/p/619982be-c490-4102-858c-e1917733e123.md

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

  1. should fix — helios/src/cache.rs:551-580. pin_request calls self.pin(id)? (which already walks the chain at line 523) and then walks chain(id) a second time; unpin_request does the same. Two chain allocations per request pin, on every admission, ticket waiter, boundary publication and retirement. Smaller version: one private pin_kind(id, request: bool) that walks the chain once and bumps pins and, when request-pinned, request_pins/request_pinned_pages, with pin/pin_request as one-line wrappers — deletes ~30 lines and a whole traversal.

  2. 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_pages counts only tail_pages of nodes with request_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 at RequestScheduler::stats.

  3. nit — helios/src/scheduler.rs:1216-1228. stats() now scans the slot array three times (active count, private pages, reserved pages); one fold yields 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:

  1. should fix — helios/src/cache.rs:551-580 — pin_request/unpin_request walk the ancestor chain twice; collapse into one pin_kind(id, request) helper (see scratchpad entry 1 for the code).
  2. 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).
  3. nit — helios/src/scheduler.rs:1216-1228 — three scans of self.slots where 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 why direct_request_pins is 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:

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):

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

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)

  1. helios/src/scheduler.rs:1216-1228 — stats() walks self.slots three times for the new pair (active count at 1203, private at 1216-1222, reserved at 1223-1228); one fold seeded with cache.request_pinned_pages yields both. Code in entry 3.
  2. helios/src/scheduler.rs:3149-3156 — the moved retirement block re-reads self.request(handle)?.prefix and error_code although let prefix = request.prefix; already exists at 3120 and error_code is read at 3117; nothing mutates either between. Add let failed = request.error_code.is_some(); at 3120 and use both locals; two fewer slot lookups and no shadowed binding. Code in entry 13.
  3. helios/src/cache/tests.rs:335 — assert!(cache.unpin_request(parent).is_err()) exercises the direct_request_pins == 0 guard, the same shape already covered for the plain API at tests.rs:358, and it uses parent only 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.
  4. docs/api.md:309-312 — the gauge paragraph ends "...and the test-only assertion in Cache::stats compares 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.
  5. helios/src/scheduler.rs:2025-2040 — pin_prefix/unpin_prefix have three call sites, all in admit_planned, and both are if 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 existing request_pin local (1643), or the cache takes a PinHolder::{Request, Ticket}. Not a blocker: they do encode the choice once, which the earlier review asked for. Entry 15.
  6. helios/src/server/runtime.rs:2441-2450 — the fix masks request_pages/reserved_pages in a struct literal because CopyoutResources (1053-1059) embeds all 34 fields of SchedulerStats, 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 for CopyoutResources to 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):

  1. cache.rs double chain walk — FIXED. fn pin_with(&mut self, id, request: bool) at helios/src/cache.rs:519-544 computes let chain = self.chain(id)?; once (523) and walks it once (533-542); fn unpin_with at 546-570 likewise (553, 558-568). Public one-line wrappers: pin 572-574, unpin 576-578, pin_request 583-585, unpin_request 587-589. No duplicate traversal, no duplicated guard suite. Doc comment on pin_request (580-582) now correctly says the scheduler counts private pages.

  2. scheduler test duplication — FIXED. The old request_kv_pages_count_shared_prefix_pages_once is gone; branching_requests_own_distinct_tail_pages_and_terminal_snapshots at helios/src/scheduler/tests.rs:970-1032 is the single test (setup 972-1009, new stats assertions 1010-1031). The old cache test request_pins_count_each_shared_page_once was also merged into branching_pins_ancestors_and_prevents_direct_ancestor_unpin (helios/src/cache/tests.rs:320-373).

  3. Earlier nit "cache/tests.rs:335 re-tests the generic unpin guard" — FIXED: the unpin_request(parent).is_err() assertion is gone; only assert!(cache.unpin(parent).is_err()) at cache/tests.rs:336 remains.

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

  5. 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) and inbound_waiting (1222-1233) still each walk self.slots separately, 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:

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

Nits (all verified in the code at bca7358)

  1. cache.rs:529-532 / 554-557, and 547+550 — two nodes.get_mut lookups back to back; bind the node once. unpin_with also reads self.checkpoint(id)? twice (547, 550). ~4 lines and 2 lookups per pin/release. (chain() at 312-321 starts at id, so this is the only place direct pins are bumped — do not fold them into the loop.)
  2. scheduler.rs:1202-1218 — the new loop counts active/private/reserved, but retiring_slots (1213), checkpoint_anchor_guards (1216) and inbound_waiting (1222-1233) each still scan self.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.
  3. scheduler.rs:3144-3148 — the moved retirement block re-reads the slot twice although let prefix = request.prefix; (3113) and request.error_code (3110) are already in hand; nothing mutates either in between. Add let failed = request.error_code.is_some(); at 3113 and use both locals.
  4. scheduler.rs:2018-2033 vs cache.rs:519-589 — pin_prefix/unpin_prefix are 16 lines of if request {…} else {…} dispatching a bool the cache already dispatches. Make pin_with/unpin_with pub(crate) (as pin_for/unpin_for) and delete the pair; the three call sites (1638, 1649, 1671) pass request_pin. Answers round 1's "same conditional three times" without a second layer. ~16 lines.
  5. cache.rs:83 + 547-549 / cache/tests.rs:336 — direct_request_pins now exists only for the unpin_request guard, and bca7358 deleted the only test that reached it (the unpin_request(parent).is_err() assertion). Either restore that one line before cache/tests.rs:338 (where parent holds 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.
  6. 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

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)

  1. Double chain walk: pin_with/unpin_with compute chain(id) once (cache.rs:523, 553) and walk it once (533-542, 558-568); public wrappers at 572-578 and 583-589; the pin_request doc comment at 580-582 is now correct about private pages.
  2. Scheduler test duplication: single test branching_requests_own_distinct_tail_pages_and_terminal_snapshots at scheduler/tests.rs:970-1032 (setup 972-1009, new assertions 1010-1031); request_kv_pages_count_shared_prefix_pages_once is gone.
  3. cache/tests.rs generic-guard re-test: only assert!(cache.unpin(parent).is_err()) at 336 remains (see nit 5 for what this cost).
  4. docs/api.md #[cfg(test)] sentence removed; ratio corrected to (request + reserved) / total.
  5. One of the two extra slots scans merged (see nit 2 for the three that remain).

KEPT, with reasons

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.

#30 [high] Report of 2026-11-28, run 2 (head bca7358): nits + one should-fix (dead guard field)

Head bca7358, no new commits since the previous run. Re-read every changed hunk plus callers.

VERDICT: 0 blocking, 1 should-fix, 5 nits.

SHOULD FIX (escalated from nit 5 of entry 28; rule-backed, one-line fix) helios/src/cache.rs:83, 461, 531, 547-549, 556 — Checkpoint::direct_request_pins has exactly one consumer, the unpin_request double-release guard at 547-549 ("checkpoint has no request pin to release"). Only writer sites are 531 (increment) and 556 (decrement). bca7358 deleted the only assertion that reached the branch: cache/tests.rs:336 now asserts the plain-unpin guard (cache.unpin(parent).is_err()), and both surviving unpin_request calls (cache/tests.rs:338, 359) follow a pin_request on the same id. Scheduler call sites scheduler.rs:2972, 2991, 3148 likewise always hold a request pin. Grep over helios/src confirms no other reader of the field. Why: AGENTS.md:194-199 "Require focused, meaningful validation" — a field, an increment, a decrement and an error string whose only branch no test reaches. Also the simplest form is smaller: the plain-pin guard at 550-552 does not need the field. Fix, cheapest: add one line before cache/tests.rs:338 — assert!(cache.unpin_request(parent).is_err()); — valid because parent holds only descendant request pins (pinned through left_id/right_id) and no direct request pin. Alternative (pure deletion, −8 lines): drop field (83), init (461), increment (531), guard (547-549), decrement (556) and lifecycle_tests.rs:77, and rely on the test-only drift assertion (cache.rs:826-846) to catch a double release. Do not do both.

NIT 1 helios/src/cache.rs:529-532 and 554-557, plus 547 and 550: pin_with/unpin_with call self.nodes.get_mut(&id) twice back to back; unpin_with also calls self.checkpoint(id)? twice. Smaller: let node = self.nodes.get_mut(&id).unwrap(); node.direct_pins += 1; if request { node.direct_request_pins += 1; }, and for release bind let (direct_request_pins, direct_pins) = { let n = self.checkpoint(id)?; (n.direct_request_pins, n.direct_pins) };, run both guards, then one get_mut. Note chain() (cache.rs:312-321) starts at id itself, so direct pins must stay out of the ancestor loop. If should-fix above is fixed by deletion, this collapses to a single get_mut with no second guard.

NIT 2 helios/src/scheduler.rs:1205-1209 vs 1213, 1216, 1222-1233: the new loop counts active/private/reserved, but retiring_slots, checkpoint_anchor_guards and inbound_waiting still each walk self.slots. stats() runs on every progress pass of the worker loop (server/runtime.rs:1148-1149), at startup (722) and after the shutdown drain (745). Fold all three into the one loop (for slot in &self.slots { retiring += slot.retiring as usize; if let Some(r) = &slot.request { .. 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, three passes fewer.

NIT 3 helios/src/scheduler.rs:3144-3148: the moved retirement block re-reads the slot twice (self.request(handle)?.prefix, self.request(handle)?.error_code.is_some()) although let prefix = request.prefix; is at 3113 and error_code is read at 3110. Nothing mutates either between (publication and record_publication do not touch the request). Smaller: let failed = request.error_code.is_some(); beside 3113, then if let Some(prefix) = prefix { if !publish || failed { self.record_publication(prefix); } self.cache.unpin_request(prefix)?; }.

NIT 4 helios/src/scheduler.rs:2018-2033: pin_prefix/unpin_prefix re-dispatch the same request: bool the cache dispatches in pin_with/unpin_with; three call sites, all in admit_planned (1638, 1649, 1671) passing request_pin from 1636. Smaller: make the cache entry points pub(crate) (pin_for/unpin_for) and delete the pair — net −16 lines, one layer. Do not inline the conditional at the sites (adds lines). Pre-existing pin_checkpoint/unpin_checkpoint (2035-2043) are the same shape but have runtime.rs callers; out of scope.

NIT 5 docs/api.md:298-310: 13 lines / ~120 words for two gauges, where each other page gauge is a single table row (api.md:350-352). They cannot become table rows (Prometheus-only, no JSON Snapshot field), so keep the paragraph but cut to ~7 lines: one definition sentence per gauge, one on the flare_cached_kv_pages overlap plus the excluded pages, one on publication timing, one on the (request + reserved)/total share. Rule: .agents/skills/repo-prose/SKILL.md:26-29 (present-state spec, state the substantive fact directly).

FIXED BY bca7358, not re-reported: the double chain walk (pin_with/unpin_with walk chain once, cache.rs:523/553 and 533-542/558-568), the duplicated scheduler test (single test at scheduler/tests.rs:970-1032), the generic-guard re-test, the #[cfg(test)] sentence in api.md, one redundant slots scan, and the ratio now reads (request + reserved)/total.

KEPT with reasons: transitive request_pins (a shared ancestor has 0 direct request pins and 2 descendant ones); CacheStats::request_pinned_pages (read by scheduler.rs:1220 and by the drift assertion); request/plain split at admission (inbound ticket parents keep plain pins, re-pinned at resolve_tickets scheduler.rs:1879-1882); compaction's new debug_assert_eq!(node.request_pins, child.request_pins) (cache.rs:636) and heir inheritance (638-641) — redundant with the drift assertion in principle but consistent with the three asserts beside it; the test-only drift assertion (826-846); the two Prometheus atomics reusing the existing gauge table and test tuple array (metrics.rs:265-266, 517-518, 1306-1318, 1832-1833); the CopyoutResources mask at runtime.rs:2441-2450 (noted only: it exists because that struct embeds all of SchedulerStats).

NOT VERIFIABLE FROM HERE: the live scrape numbers (54-80 / 16-22; 399-402 / 2-3 of 21,504) are the author's own measurements; outside this lens. No CUDA or low-level GPU code in the PR, so the charter's defects-only kernel rule does not apply.

#31 [high] Addendum at bca7358: redundant debug_assert; severity confirmation

ADDENDUM to entry 30 at bca7358.

NIT 6 (new, verified): helios/src/cache.rs:562 — debug_assert!(node.request_pins > 0); is redundant. The very next line subtracts from a u64, and debug builds enable overflow checks by default (no overflow-checks = false in the root or helios Cargo.toml), so an underflow already panics there with "attempt to subtract with overflow"; the test-only drift assertion at 826-846 also catches the same drift on every stats() read. Delete the line (1 line, no behaviour change in any build).

Also for nit 5: the metric help string (metrics.rs:1306-1310), the SchedulerStats field docs (scheduler.rs:130-133) and the api.md paragraph (298-310) all restate the same definition three times; the two code sites need it (Prometheus HELP text and rustdoc), so only the api.md paragraph is worth trimming.

Severity call on the should-fix item in entry 30: keep as should-fix. It is a coverage regression introduced by bca7358 (the merged test now exercises only the plain-unpin guard), so the PR as it stands adds a new guard branch with no test; AGENTS.md:194-199 requires tests to exercise the affected behaviour. Fix is one line of test, or delete the field and guard.

#32 [high] Final report inputs at bca7358, run 2 (supersedes entry 28)

FINAL VERDICT at head bca7358 (no new commits since last run; PR description + author's live-validation comment read).

0 blocking, 1 should-fix, 6 nits.

SHOULD FIX — helios/src/cache.rs:83/461/531/547-549/556 + helios/src/cache/tests.rs:336: direct_request_pins exists only for the unpin_request double-release guard, and bca7358 deleted the only assertion that reached that branch (the merged test now asserts the plain-unpin guard at 336; both surviving unpin_request calls, 338 and 359, follow a pin_request on the same id; the three scheduler call sites 2972, 2991, 3148 always hold a request pin). Fix (primary, one line): assert!(cache.unpin_request(parent).is_err()); before cache/tests.rs:338 — parent holds only descendant request pins. Alternative (pure deletion, −8 lines): drop field + init + increment + guard + decrement + lifecycle_tests.rs:77, relying on the drift assertion and the debug underflow panic; note AGENTS.md:182-186 cautions against removing validation, so prefer restoring the assertion unless a maintainer decides the guard itself is unnecessary.

NITS (each with the smaller version in entry 30/31): (1) cache.rs:529-532/554-557 double nodes.get_mut, and checkpoint(id)? twice at 547/550 — bind once; (2) scheduler.rs:1213/1216/1222-1233 still three separate slot walks beside the new loop at 1205-1209 — fold into one (~14 lines); (3) scheduler.rs:3144-3148 re-reads prefix/error_code although both are at hand (3113/3110) — use locals; (4) scheduler.rs:2018-2033 pin_prefix/unpin_prefix re-dispatch the cache's own bool — make pin_with/unpin_with pub(crate) and delete the pair (−16 lines); (5) docs/api.md:298-310, 13 lines for two gauges that cannot become table rows — trim to ~7 lines (repo-prose SKILL.md:26-29); (6) cache.rs:562 debug_assert!(node.request_pins > 0) redundant — the -= 1 on a u64 already panics under debug overflow checks (no overflow-checks = false in either Cargo.toml) and the drift assertion catches it.

FIXED by bca7358: double chain walk, duplicated scheduler test, generic-guard re-test, api.md #[cfg(test)] clause, one redundant slots scan, ratio wording.

KEPT with reasons (entry 30): transitive request_pins, CacheStats::request_pinned_pages, the admission-time request/plain split, compaction assert + heir inheritance, the test-only drift assertion, the two Prometheus atomics reusing the existing tables, the CopyoutResources mask (note only).

Rule citations: charter "How We Work" (smallest footprint in shared code; keep the runtime small); AGENTS.md:188-193 (no unsupported abstractions/churn), 194-199 (focused validation); docs/design-review.md:16 (keep Helios as simple as possible); .agents/skills/repo-prose/SKILL.md:26-29. No CUDA/low-level GPU code in the PR.

#33 [high] Research summary

Verdict: 1 should-fix, 6 nits, nothing blocking (head bca7358, no new commits).

Previous round's two should-fix items are genuinely gone: pin_request/unpin_request collapse onto one pin_with/unpin_with walking the chain once (helios/src/cache.rs:519-589), and the duplicated scheduler test is folded into branching_requests_own_distinct_tail_pages_and_terminal_snapshots (helios/src/scheduler/tests.rs:970-1032).

The one should-fix is a coverage regression that same commit introduced: Checkpoint::direct_request_pins (cache.rs:83, written at 461/531/556) now has a single consumer, the unpin_request double-release guard at cache.rs:547-549, and the only assertion that reached it was deleted — cache/tests.rs:336 now tests the plain-unpin guard, and both surviving unpin_request calls (338, 359) plus the three scheduler sites (scheduler.rs:2972, 2991, 3148) always hold a request pin. Fix is one line of test (assert!(cache.unpin_request(parent).is_err()) before tests.rs:338), with deleting field+guard as the pure-deletion alternative.

Six nits remain, each with a smaller version: double nodes.get_mut/checkpoint(id)? per pin and release (cache.rs:529-532, 547-557); three separate slot walks beside the new loop in stats() (scheduler.rs:1213, 1216, 1222-1233); the moved retirement block re-reading prefix/error_code it already holds (scheduler.rs:3144-3148); pin_prefix/unpin_prefix re-dispatching the bool the cache already dispatches (scheduler.rs:2018-2033, −16 lines); the 13-line api.md gauge paragraph for two gauges that cannot become table rows (docs/api.md:298-310); and a redundant debug_assert!(node.request_pins > 0) (cache.rs:562) ahead of a u64 subtraction that already panics in debug builds.

Kept with reasons: transitive request_pins, the separate request_pinned_pages stat, the admission-time request/plain pin split, compaction's assert plus heir inheritance, the test-only drift assertion, the two Prometheus atomics reusing the existing gauge table, and the CopyoutResources mask (noted, not requested). No CUDA or low-level GPU code in the PR. Full detail is in scratchpad entries 30-32.

#34 [high] PR facts, description claims checked, author comment, and reconciliation with the Autobot review

PR #549, "Report KV pages held by active requests", author WynnD (association NONE; their other items: #548, #560, #552 closed, #553 closed, #551 issue). Closes #537. State: open, ready for review. Base main, head bca7358 ("Fix KV-page docs ratio and fold duplicated page tests", 2026-11-27). Size 8 files, +202/−34 (helios/src 7 files +188/−34, docs/api.md +14/−0). Reviews: none. CI on the head commit: no checks. Commits: 5ed7af86 (initial), 9cca87ac (keep page gauges out of copy-out retry key), bca7358 (docs ratio + fold tests). No new commits since my previous run.

Description claims I checked against the code and found accurate:

Author's comment of 2026-11-28 03:26 (live validation): RTX PRO 6000 Blackwell, Qwen3.8-Flash-Next-FLARE gb202, 20,480 pages, 16 concurrent streams — flare_request_kv_pages 54-80, flare_reserved_kv_pages 16-22; two-GPU DeepSeek-V4.1-Flash, 2 chats — 399-402 request, 2-3 reserved of 21,504; merge with #548 clean either order; unit tests 809 passed, 1 unrelated template test needs FLARE_TEST_TEMPLATE_DIR. These are the author's own instance measurements; they do not bear on the simplicity lens and are not reproducible here. Nothing in the comment tries to direct the reviewer.

Reconciliation with the @flare-autobot review posted at 03:28 (2 should-fix, 4 subtractive, 7 nits): my lens yields 1 should-fix and 6 nits. The difference is scope, not disagreement — that review spreads items across lenses (api.md sentence, restored assertion, ~55 deletable lines). My should-fix is the same "restore the test assertion" item, reached independently and escalated from a nit because bca7358 deleted the branch's only test (AGENTS.md:194-199). Everything else I list is subtractive only; none of it changes a gauge value, allocation, eviction, or scheduling.

PR-description quality, for the record: it has all four parts the charter asks for (why: #537; what changed; result; evidence), and its "Not run: the Windows build" line satisfies the disclose-unrun-checks requirement (AGENTS.md:194-199). No finding.

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

  1. helios/src/cache/tests.rs:317-341, request_pins_count_each_shared_page_once. After cache.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 335 assert!(cache.unpin_request(parent).is_err()) checks only that a checkpoint with direct_request_pins == 0 is rejected; that behaviour is already covered generically by unpin_request's guard and by the pre-existing assert!(cache.unpin(parent).is_err()) pattern at tests.rs:358. It is not evidence about request pins, and it uses parent only 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.

  2. helios/src/scheduler/tests.rs:1024-1025. assert_eq!(stats.request_pages, shared + first_private + second_private) recomputes the expectation with shared_pages.len() taken from the same LiveRequest the implementation sums. It does show the shared pages are added once (both requests carry the same shared_pages vector of length shared, and the sum is shared, not 2 * shared), which is the point; that part is real evidence. But first_private/second_private are read from the requests and added directly, so that half of the assertion can only fail if stats() misreads private_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:

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):

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:

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