Key findings
Reviewing PR #549 through the simplicity lens ("what can be deleted?") against the charter (line 12: keep the runtime small and model-agnostic; line 35: what gets merged) and AGENTS.md's review rules ("Reject unsupported abstractions and churn", "Require focused, meaningful validation"). The short version: this change does not add a parallel mechanism — the two gauges ride the existing gauge renderer, the existing update table and the existing drift assertion, and the two new counters both have real consumers. So the answer to "what can be deleted" is within the diff, not the diff itself.
Two should-fix items, both local to Cache's pin API, and three nits. Nothing blocking.
- should fix —
helios/src/cache.rs:551-580:pin_request/unpin_requestwalk the ancestor chain twice and duplicate the guard code, because they are built on top ofpin/unpininstead of inlining the request-pin bookkeeping. On every admission, ticket waiter, boundary publication and retirement. - should fix —
helios/src/cache.rs:548-550: the new doc comment claims the cache tracks a request's private pages. It does not, and a reader cannot tell from the comment where private pages are added. - nit —
helios/src/scheduler.rs:1216-1228: three scans ofself.slotsinstats()where one fold gives both new totals. - nit —
helios/src/cache/tests.rs:335: one assertion checks a generic guard already covered elsewhere, not the request-pin behaviour the test's comment implies. - nit —
docs/api.md:298-305: the new paragraph both duplicates the metric table and narrates implementation.
should fix
1. helios/src/cache.rs:551-563 and :565-580 — the two new entry points walk the ancestor chain twice and repeat the guard code
pin_request is self.pin(id)? followed by a second self.chain(id)?:
551 pub fn pin_request(&mut self, id: CheckpointId) -> Result<()> {
552 self.pin(id)?; // -> self.chain(id)? at 523
553 self.nodes.get_mut(&id).unwrap().direct_request_pins += 1;
554 let chain = self.chain(id)?; // second traversal, second Vec
pin itself (cache.rs:519-534) already computes self.chain(id)? at line 523 and walks it at 530-532. unpin_request has the identical shape (guard at 566, self.unpin(id)? at 569 which chains again at 540, then self.chain(id)? at 571). So every request pin costs two chain walks and two Vec<CheckpointId> allocations; every unpin the same.
Why it matters: these are not cold paths. pin_request is called on every admission (scheduler.rs:1645), for every pool-ticket waiter (1900), for every boundary publication (2971/2991), and unpin_request on every retirement (3159) plus the two error-path releases at 1660/1686. The chains are short but the allocation is per-pin per-request, and the duplicated guard suite (ready check, u64::MAX saturation check, direct_pins guard) now exists in two places that must stay in step.
Smaller version — one traversal, one guard site, 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 mirror for unpin/unpin_request. That deletes roughly 30 lines and one whole chain traversal per call. The request_pins-is-a-subset-of-pins invariant and the "count returns to zero" property are preserved exactly, so request_pins_count_each_shared_page_once and the stats drift assertion at cache.rs:817-837 keep passing unchanged.
2. helios/src/cache.rs:548-550 — the doc comment describes page bookkeeping the cache does not do
/// 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 notion of a request's private pages. request_pinned_pages is only ever changed at cache.rs:558-560 and 575-577, from node.tail_pages.len() of checkpoints whose request_pins crosses one or zero — which is exactly what the test-only full-scan check recomputes at cache.rs:830-834. The private pages are added by the scheduler, separately, at scheduler.rs:1216-1222 (request.private_pages.len() summed over slots) and only surface as SchedulerStats::request_pages. A reader of pin_request is therefore told the counter covers more than it does, and cannot tell whether adding the scheduler's private pages double counts.
Fix — state only the cache's half and point at the consumer:
/// Pins a checkpoint on behalf of an active request, adding 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.
(Rule cited: .agents/skills/repo-prose/SKILL.md (not opened) — comments state the invariant, not commentary about it; docs/design-review.md principle 16, write without hidden context.)
nits
3. helios/src/scheduler.rs:1216-1228 — three passes over the slot array where one suffices
stats() now walks self.slots once for active_requests (1203-1207), once for private_pages (1216-1222) and once for reserved_pages (1223-1228) — plus the pre-existing scans at 1209 and 1212. stats() is called from the runtime loop whenever anything progressed (server/runtime.rs:1148-1149).
One pass gives both new fields:
let (request_pages, reserved_pages) = self
.slots
.iter()
.filter_map(|slot| slot.request.as_ref())
.fold((cache.request_pinned_pages, 0), |(pages, reserved), request| {
(pages + request.private_pages.len(), reserved + request.reserved_pages.len())
});
That also makes the two fields read as the pair docs/api.md describes (private plus cache-pinned pages vs. reserved pages) instead of two independently written sums. Fold of three scans into one; no behaviour change.
4. helios/src/cache/tests.rs:335 — an assertion that does not prove a request-pin behaviour
In request_pins_count_each_shared_page_once, line 335 (assert!(cache.unpin_request(parent).is_err())) only shows that unpin_request rejects a checkpoint whose direct_request_pins == 0 — the same guard shape already asserted for the plain API at tests.rs:358 (assert!(cache.unpin(parent).is_err())). It happens to use parent only because that checkpoint has no direct request pin (it has transitive ones), so it is not evidence about the shared-page accounting the test is named for, and the surrounding comments present it as if it were.
The real evidence in this test is lines 331-334 and 336-341 (3 not 4; plain pins leave the count unchanged), which are good. Either drop line 335 or move it to a guard-specific test with a comment saying what it covers. Not a behaviour bug.
Related, minor: in helios/src/scheduler/tests.rs:1024, stats.request_pages == shared + first_private + second_private has two halves of unequal strength. The shared half is genuine evidence (both requests carry the same shared_pages, so a double count would give 2 * shared); the first_private/second_private half is read from the same LiveRequests the implementation sums, so it can only fail if stats() misreads the field. Worth a half-sentence in the comment saying which half is the claim; nothing to delete.
5. docs/api.md:298-305 — the new paragraph duplicates the metric table and narrates implementation
Two trims:
- "Both are gauges read from scheduler state on each scrape." The gauge half is already established for the page metrics by the convention at api.md:287-296 and by every page row of the table; "read from scheduler state on each scrape" is implementation narration a dashboard author cannot act on. Delete the sentence.
- The numerator definition ("their private pages plus the tail pages of the prefix checkpoints they pin, each page counted once") is stated at 298-300 and then partly restated by the "idle cached prefixes and snapshot backing pages are outside that share" clause at 304-305. Keep the ratio sentence — it answers #537 directly — and drop one of the two enumerations.
Separately: the page keeps a metric table (api.md:325-349) that lists cached_pages (345), free_pages (346) and total_pages (347), but the two new gauges appear only in prose. A reader who scans the table for page metrics will not find them. One home for the content is enough: either add request_pages/reserved_pages rows with the Prometheus names, or keep the prose and let the table stay the JSON-mirroring table it already is. Both is duplication.
Examined and deliberately kept (no finding)
Checkpoint::direct_request_pins(cache.rs:82-83, 461, 553, 566, 570). Its only consumer is theunpin_requestguard at 566, which looks like dead weight until you note that a checkpoint can be pinned both by a request and for host-store copy-out (pin_checkpoint, scheduler.rs:2038): without the direct counter a duplicated request unpin would silently driverequest_pinsbelow its true value instead of erroring. Eight bytes and one fixture line is the price of the guard. Keep.CacheStats::request_pinned_pagesas its own field rather than folded intocached_pages: both the drift assertion (cache.rs:817-837) and the scheduler sum need it separated. Keep.- The two Prometheus-only atomics (server/metrics.rs:265-266) with no JSON
Snapshotfield: api.md states the Prometheus-only contract, and the additions reuse the existing(name, help, value)gauge array (metrics.rs:1309-1318), the existing update table (517-518) and the existing test tuple array (1835-1836). No second representation, no parallel path. #548/#549 touch different regions of the same file and merge either order, so there is no rebase simplification to make either. - The plain-pin path for inbound admissions (scheduler.rs:1643-1689): those requests are not live yet (they wait on a host-store ticket) and are re-pinned through
pin_requestat 1900, so the split is not two ways to do one thing. - Struct-literal plumbing in heilos/src/cache/lifecycle_tests.rs:77-78 (not opened) and :95 is forced by the two new fields; without it the fixture's projection would drop the request-pin state.
- Invariants checked clean:
request_pinsstays a subset ofpins;request_pinned_pagesreturns to zero after all request pins are released; compaction carries the count correctly (debug_assert_eq!(node.request_pins, child.request_pins)at cache.rs:627 together with the heir inheritingnode.tail_pagesat 629-631);eviction_candidatesstill gates onpins/child_count(cache.rs:658-663), so no request-pinned node can leavenodes.
Open questions / could not be verified from here
- The live scrape numbers (399/402 request pages, 3/2 reserved, ratio 0.0186/0.0187 on the two-GPU DeepSeek-V4.1-Flash instance) cannot be reproduced in this review; they are the author's own measurement of their own instance, and the report says so. The claim I can check in code is that
request_kv_pages + reserved_kv_pagesshould not exceedtotal - free - cached, and nothing in the implementation violates it, but whether the remainder identities hold exactly depends on whether free/cached counts include pages in editing state — not answerable from the diff. Settling it needs a scrape with a request held mid-prefill, not a unit test. - No Windows or full-suite run was done by the author; CI has no checks on 5ed7af8 yet. Nothing in this diff platform-specific, so this is not a simplicity concern.
- GPU kernel code: none in this PR, so the charter's defects-only rule for kernels did not apply.