Key findings
Two should-fix items, both duplication/precedent departures, no blocking issues.
pin_request/unpin_requestre-implement the body ofpin/unpinaround it (helios/src/cache.rs:551-580). They call the existing method and then walk the checkpoint chain a second time, so one logical operation is now split across two functions that must agree, instead of extending the function that already owns the invariant. Fix: a privatefn pin_with(&mut self, id, request: bool)that computesself.chain(id)?once and does both counter sets, withpin/pin_request/unpin/unpin_requestas thin wrappers.- The "which counter" branch is copied three times in
admit_planned_with_checkpoint_accounting(helios/src/scheduler.rs:1643-1649, 1657-1669, 1683-1692). The file already encodes exactly this kind of pairing once, inpin_checkpoint/unpin_checkpoint(scheduler.rs:2038-2044), so the reviewer's expectation is set by the repo's own convention. - Nit: the two new gauges are documented only in
docs/api.mdprose plus HELP strings; the existing page gauge also has a design-document home (docs/runtime-core-design.md:873).
I read every changed file in context (cache.rs, scheduler.rs, server/metrics.rs, docs/api.md, plus the two test files' assertions via the diff) and checked the rules in AGENTS.md and the charter. Nothing in the diff is a duplicated helper that already exists elsewhere (no existing "pages held by live requests" helper — search_code for held_pages|live_pages|pages_held|request_pages returns only the new items), so the duplication findings are about shape, not about reinventing a mechanism.
Should fix 1 — pin_request/unpin_request shell out to pin/unpin and walk the chain a second time
Where: helios/src/cache.rs:551-563 and 565-580; precedents at cache.rs:519-534 (pin) and 536-546 (unpin).
pin computes the chain once and runs the readiness and refcount guards against it:
// cache.rs:519-534
pub fn pin(&mut self, id: CheckpointId) -> 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 { self.nodes.get_mut(&ancestor).unwrap().pins += 1; }
Ok(())
}
The new method repeats that walk instead of participating in it:
// cache.rs:551-563
pub fn pin_request(&mut self, id: CheckpointId) -> Result<()> {
self.pin(id)?; // walks chain, checks chain
self.nodes.get_mut(&id).unwrap().direct_request_pins += 1;
let chain = self.chain(id)?; // walks chain again
for ancestor in chain { /* request_pins += 1, request_pinned_pages += tail_pages */ }
Ok(())
}
unpin_request (cache.rs:565-580) has the same shape: self.unpin(id)? then a second self.chain(id)? to decrement request_pins.
Why it matters. Two chains per pin means two Vec<CheckpointId> allocations and two root-to-leaf walks on a path that runs per admission, per pool-ticket hand-off (scheduler.rs:1897), per boundary publication (scheduler.rs:2968, 2988) and per retirement (scheduler.rs:3156). More importantly for this lens, the invariant "request_pins is a subset of pins and both move together along the same chain" is now enforced by two separate loops in two functions that can drift; the only detector of drift is the test-only assertion in Cache::stats (cache.rs:819-837), which does not exist in a release build, and compact_ancestor's debug_assert_eq!(node.request_pins, child.request_pins) (cache.rs:627) which is also debug-only.
Fix. One private worker, one walk:
fn pin_with(&mut self, id: CheckpointId, request: bool) -> Result<()> { /* existing pin body + request accounting in the same loop */ }
pub fn pin(&mut self, id) -> Result<()> { self.pin_with(id, false) }
pub fn pin_request(&mut self, id) -> Result<()> { self.pin_with(id, true) }
and the mirror for unpin. This also gives the request_pins == 1 / == 0 transitions a single site, which is where request_pinned_pages must be updated.
Secondary point on the same lines, stated honestly. The new counters use bare += 1 / -= 1 with no u64::MAX guard, unlike direct_pins/pins. In practice this cannot overflow: request_pins is documented and implemented as a subset of pins (cache.rs:82-85 fields, cache.rs:555-557 increment), and pin rejects at u64::MAX before the request count grows. So the missing guard is defence-in-depth, not a live defect — I flag it only as the reason to merge the two loops rather than as an independent bug. The request_pinned_pages -= node.tail_pages.len() at cache.rs:576 is usize subtraction guarded only by the direct_request_pins == 0 early-out at cache.rs:566 plus the subset invariant; if a test-only assertion ever fires there, a release build would wrap instead of erroring. Folding into one loop does not by itself fix that; a saturating_sub or a debug assert on the transition would. I did not find a path that reaches it with the invariant intact.
Should fix 2 — three copies of the request-pin-vs-plain-pin branch in admit_planned_with_checkpoint_accounting
Where: helios/src/scheduler.rs:1643-1649 (take), 1657-1669 (context-limit rollback), 1683-1692 (resource rollback).
Before the change the function had one pinned binding and each rollback site called self.cache.unpin(id)? (see the diff hunk at scheduler.rs:1638-1669 in pr_diff). The change replaces those single calls with the same two-branch conditional three times:
if let Some(id) = pinned {
if inbound.is_none() { self.cache.pin_request(id)?; } else { self.cache.pin(id)?; }
}
...
if let Some(id) = pinned {
if inbound.is_none() { self.cache.unpin_request(id)?; } else { self.cache.unpin(id)?; }
}
return Err(...Context...);
...
if let Some(id) = pinned {
if inbound.is_none() { self.cache.unpin_request(id)?; } else { self.cache.unpin(id)?; }
}
return Err(error);
Why it matters. inbound is moved-in and immutable for the whole function, so all three sites are deterministically the same branch; the repetition buys nothing and creates three places that must agree. A later edit that changes one of them (say, adding a third pin kind, or pinning the ticket parent on the creating path too) produces a pin and an unpin on different counters, which is invisible in release builds — the only detector is the test-only full-scan assertion in Cache::stats (cache.rs:819-837). The repository's own precedent is to bind the choice once: pin_checkpoint/unpin_checkpoint (scheduler.rs:2038-2044) exist precisely so call sites cannot mismatch, and the pinned binding itself (scheduler.rs:1638-1642) was already the "decide once, use everywhere" shape that the change then undid at the call sites.
Fix. Carry the kind in the binding that already exists:
#[derive(Clone, Copy)] enum PinKind { Request, Admission }
let pin = pinned.map(|id| (id, if inbound.is_none() { PinKind::Request } else { PinKind::Admission }));
then one self.cache.pin_as(kind, id) at scheduler.rs:1643 and one unpin_as(kind, id) at each of 1657-1669 and 1683-1692 — or simply a local closure let release = |cache: &mut PrefixCheckpointCache, id| ... used at both rollback sites. Either restores one visible pairing.
Note for the author: the sites at scheduler.rs:1897 (pin_request for pool-ticket waiters), 2968/2988 (boundary publications, which correctly pair pin_request with unpin_request(parent)) and 3156 (retirement unpin_request) are not part of this finding — each is a single unconditional call, and they are internally consistent with each other. The plain-API pins left alone for host-store copy-out/export (pin_checkpoint/unpin_checkpoint, scheduler.rs:2036-2044) match the PR description and are the right call.
Nit 3 — the new gauges have no docs/runtime-core-design.md entry
Where: docs/api.md:298-305 and helios/src/server/metrics.rs:1306-1318 (HELP strings).
The precedent for a scheduler page-count gauge is flare_snapshot_backing_pages, which is specified in the design document at docs/runtime-core-design.md:873-876 ("counts page ids excluded by owned snapshots ... It counts overlapping exclusions once"). flare_request_kv_pages and flare_reserved_kv_pages get an api.md paragraph and exposition HELP text and nothing in the design document, even though their semantics — "each page counted once even when several requests reference it" (docs/api.md:300) and "neither free, cached, nor written yet" (docs/api.md:301-302) — are exactly the kind of durable invariant that document carries.
Fix: one or two sentences next to docs/runtime-core-design.md:873 for the request-pin counting rule and the reservation rule. Only worth doing if the semantics need a specification beyond the exposition help; the PR description already states them.
Explicitly NOT a finding (checked and dropped):
- Missing rows in the docs/api.md field table (docs/api.md:325-355;
cached_pages→flare_cached_kv_pagesat 345,free_pages346,total_pages347). The table maps JSON fields to Prometheus names, and docs/api.md:292-296 already introduces metrics "beyond the JSON fields below". The PR deliberately keeps both gauges out of the JSON snapshot (pr_difffor metrics.rs shows no JSON/snapshot change), so prose is the correct home and the table omission is consistent, not a departure. SchedulerStats::statsiteratingself.slots(scheduler.rs:1216-1228) matches the established pattern in the same function —active_requests(1203-1207),retiring_slots(1209) andcheckpoint_anchor_guards(1212) all scanslotsper call. The "at most one slot per active request" claim in the PR description holds becauseslotsholds one request each; I found no per-slot duplication.Metricsstoring two moreAtomicU64fields (helios/src/server/metrics.rs:265-266, stored in the existing bulkfor (target, value) in [ ... ]list at 514-518) follows the existingcached_pages/snapshot_backing_pagespattern exactly; no new mechanism introduced. The test fixture (metrics.rs:1787-1791) and the expected-exposition table (metrics.rs:1832-1833) were both extended, which is the existing convention.- No duplicated helper found. Nothing in the tree already computed "pages held by live requests";
Cache::statsavoids scanningnodesby design (cache.rs:816-837 comment and structure), so maintainingrequest_pinned_pagesincrementally is the same shape as the existingready_checkpoints/unready_checkpoints/tail_pagescounters (cache.rs:219-222). The approach is in keeping, only its implementation shape (findings 1-2) departs.
Open questions / not settled
- Prose review. AGENTS.md:43-50 requires the repo prose skill (
.agents/skills/repo-prose/SKILL.md(not opened)) to be applied to documentation, code comments, docstrings, HELP strings and the PR description. I reviewed the new text for accuracy against the code (the "each page counted once" and "idle cached prefixes ... outside that share" claims both hold:request_pinned_pagesadds a checkpoint'stail_pagesonly on therequest_pins == 0 -> 1transition, cache.rs:557-560, and the drift scan uses the samerequest_pins > 0predicate, cache.rs:830-834), but I could not apply the style skill itself; an owner should. - Whether the double chain walk is measurable. I can show the second walk exists from the code; I cannot show it costs anything at the observed rates (admissions and publications per second). A micro-benchmark of
pin_requestvspinwould settle whether it merits a perf argument on top of the structural one. - Inbound-request accounting (scheduler.rs:1638-1649 vs 1216-1228): an
Inboundrequest pins through the plain API and its pages sit in the ticket'sticket.pages, so they appear in no gauge, althoughSchedulerStats::inbound_waiting(scheduler.rs:137-138) documents such requests as active.docs/api.md:298-300says the gauge counts pages "active requests reference"; if an Inbound request counts as active, the docs or the accounting should say which. Outside my lens (semantics, not convention), so I did not record it as a finding; it needs the author's intent. - Not verified: CI status (the orientation packet says no checks on 5ed7af8) and the Windows build the description calls out as unrun.