Simplicity review of PR #549 "Report KV pages held by active requests" (head 9cca87a)
Key findings
Verdict: should-fix issues only, nothing blocking. The design reuses existing mechanisms (one nodes map, one stats field, the existing Prometheus gauge array and update table) rather than adding parallel paths, so nothing has to be deleted outright. What can be made smaller:
- should fix —
helios/src/cache.rs:551-580:pin_request/unpin_requestwalk the checkpoint chain twice and duplicate the guard code. Onepin_kind(id, request: bool)with one-line wrappers deletes ~30 lines and one traversal per pin and per release. - should fix —
helios/src/scheduler/tests.rs:970-1034: the new scheduler test repeats an existing test's steps verbatim; only 24 of its 65 lines are new evidence. Merge or extract a helper: ~38 lines. - Six nits, listed below, none of which affect behaviour.
Rules applied: charter "How We Work" — "Solve the right problem in the right place … Look for the smallest footprint in shared code" (and 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", pointing at .agents/skills/repo-prose/SKILL.md:13-14 (not opened), 26-29, 38-39, 44-46). The PR contains no CUDA or low-level GPU kernel code, so the charter's kernels-defects-only rule does not apply.
Should fix
1. helios/src/cache.rs:551-580 — request pins walk the ancestor chain twice
pin_request (551-563) calls self.pin(id)?, which validates readiness and computes self.chain(id)? at 523 and walks it at 530-532; it then computes self.chain(id)? again at 554 and walks it again to bump request_pins. unpin_request (565-580) repeats the shape: self.unpin(id)? chains at 540, then 571 chains again. Result: two Vec<CheckpointId> allocations and two walks per request pin and per release, plus a second copy of the ready / direct_pins == u64::MAX / pins == u64::MAX guard suite.
Call sites are all hot paths: every admission through pin_prefix/unpin_prefix (helios/src/scheduler.rs:1645, 1656, 1678), every ticket waiter (scheduler.rs:1889), every boundary publication (scheduler.rs:2977, 2979, 2997, 2998) and every retirement (scheduler.rs:3155).
Smaller version — one private helper, both public pairs become one-line wrappers:
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 (keeping the direct_pins == 0 / direct_request_pins == 0 guards). This preserves every invariant the PR relies on: request_pins ⊆ pins, request_pinned_pages returning to zero, and the test-only drift assertion at cache.rs:817-837. request_pins_count_each_shared_page_once and every scheduler test keep passing unchanged.
2. helios/src/scheduler/tests.rs:970-1034 — the new test duplicates an existing test's setup line for line
request_kv_pages_count_shared_prefix_pages_once (970-1034) duplicates branching_requests_own_distinct_tail_pages_and_terminal_snapshots (1036-1081) step for step: same scheduler(2, 8, 5), same seed admit/init/plan/commit/complete/freeze/finish, same two admits of spec(65, 4), same retain_prompt(6), same prefill-lane assertion, same final complete. Lines 972-1009 are identical to 1038-1075.
Only 1010-1033 is new: the five lengths read off the two LiveRequests, the two stats assertions, the two cancels, and the (0, 0) / cached_pages > 0 checks. The cost is ~38 duplicated lines and a second fixture that will drift from the first; per AGENTS.md:194-199, a test should exercise the contract it names, not re-establish a fixture another test already builds.
Fix: append 1010-1033 to the branching test — its trailing borrows at 1076-1080 can follow the stats assertions and cancels — or extract fn shared_prefix_pair(&mut RequestScheduler) -> (RequestHandle, RequestHandle) from 972-1009 and call it from both. The stats assertions survive unchanged; merging removes the whole second test.
Nits
helios/src/scheduler.rs:1216-1228—SchedulerStats::statsiteratesself.slotstwice more for the new pair (private pages at 1216-1222, reserved pages at 1223-1228) on top of the existing scans;stats()runs from the runtime loop whenever anything progressed (server/runtime.rs:1148-1149). Onefoldseeded overslot.requestyields both values, andrequest_pages: private + cache.request_pinned_pages. Note also thatLiveRequest::pages()(scheduler.rs:385-387) already exists as the notion of "the pages a request holds"; the new code should not invent a second one.helios/src/scheduler.rs:3149-3156— the retirement block callsself.request(handle)?twice to re-readprefixanderror_code, althoughlet prefix = request.prefix;exists at 3120 andrequest.error_codeis read at 3116-3119 with nothing mutating either in between (the only writers, 2716/2779, run incomplete). Addlet failed = request.error_code.is_some();beside 3120 and use both locals: two fewer slot lookups and one less shadowed binding. No behaviour change.helios/src/cache/tests.rs:335—assert!(cache.unpin_request(parent).is_err())exercises only the "checkpoint holds no request pin" guard, the same shape already covered for the plain API attests.rs:358; it is not evidence for the test's named claim (a shared page counted once). Drop it, or move it next to a guard test. The real evidence is 331-334 and 336-341, plus theCache::statsdrift assertion.docs/api.md:309-312— the gauge paragraph ends "…and the test-only assertion inCache::statscompares the maintained request-pinned count with a full scan of every checkpoint on each read." That documents#[cfg(test)]scaffolding (cache.rs:817-837) inside the API reference; per.agents/skills/repo-prose/SKILL.md:13-14 (not opened), 26-29anddocs/design-review.mdprinciple 16, documentation is a present-state specification, not a validation journal, and the PR description already carries this evidence. End the paragraph at "…excludes idle cached prefixes and snapshot backing pages."helios/src/scheduler.rs:2025-2040—pin_prefix/unpin_prefixareif request { … } else { … }pass-throughs with three call sites, all insideadmit_planned(1645, 1656, 1678); they replaced 12 inline lines with 16. Once the cache has one entry point per direction (should fix 1), delete them and call the cache at the three sites with the existingrequest_pinlocal (1643), or give the cachePinHolder::{Request, Ticket}. Not a blocker — they do encode the choice once — but they are net new lines for no new abstraction.helios/src/server/runtime.rs:2441-2450— the fix zeroesrequest_pages/reserved_pagesin a struct literal becauseCopyoutResources(1053-1059) embeds all ofSchedulerStats; every future gauge therefore joins the copy-out retry key by default and needs a second edit here. Correct as written; the smaller long-term form 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, so it is a note, not a request.
Examined and kept (no finding)
Checkpoint::direct_request_pins(cache.rs:82-83, 461, 553, 566, 570) has no consumer besides theunpin_requestguard at 566, but it cannot be derived frompins: a node can be pinned by both a request and host-store copy-out (pin_checkpoint, scheduler.rs:2044), and without it a double request unpin would silently driverequest_pinsnegative in effect instead of erroring. Keep.CacheStats::request_pinned_pagesas its own field rather than folded intocached_pages: the drift assertion (cache.rs:824) and the scheduler sum (scheduler.rs:1222) both need it separated. Keep.- The two new
Metricsatomics (metrics.rs:265-266) with no JSONSnapshotfield:docs/api.mdstates the Prometheus-only contract for these two, and #548 changes a different region of the same file. No simplification available. - Struct-field plumbing forced by the new fields —
cache/lifecycle_tests.rs:77-78, 95— is required, or the lifecycle fixture'sfork()would drop request-pin state. - Invariants verified clean: compaction carries request pins (cache.rs:627 assert plus heir inheriting
tail_pagesat 629-631, sorequest_pinned_pagesis unchanged across it); eviction still gates onpins/child_count(cache.rs:658-663), so a node with request pins cannot be removed. - Withdrawn from an earlier pass: the claim that
docs/api.md:298-305duplicates the metric table. The table at api.md:332-355 maps JSONSnapshotfields to Prometheus names, and these two gauges have no JSON field, so the prose paragraph is their only home.
Not verifiable from here
The live two-GPU DeepSeek-V4.1-Flash scrape numbers (399/402 request pages, 3/2 reserved, ratios 0.0186/0.0187) are the author's measurement of their own instance; confirming them needs a scrape with a request held mid-prefill, not a unit test. That is outside the simplicity lens and does not change the verdict.