Subtraction review — PR #549 "Report KV pages held by active requests"
Verdict: make it smaller first. About 55 of the +202 added lines (~28%) can simply be deleted, in four places. The rest is the irreducible core of a counter that has to stay scan-free.
State at head bca7358 (base main): 8 files, +202/−34 — docs/api.md +14, cache.rs +73/−5, cache/lifecycle_tests.rs +3, cache/tests.rs +15/−4, scheduler.rs +49/−19, scheduler/tests.rs +22/−5, server/metrics.rs +18, server/runtime.rs +8/−1. Open and ready for review, no CI checks on the commit, no human reviews. The suite was not run from this environment; the author's "809 passed, 1 failed (unrelated template test)" is taken as given, and all line counts below are static readings of the diff and the files at head.
Key findings
| # | Where | Cut | Lines |
|---|---|---|---|
| 1 | scheduler.rs, metrics.rs, runtime.rs, docs/api.md, scheduler/tests.rs | whole reserved_pages / flare_reserved_kv_pages gauge |
~20 |
| 2 | scheduler.rs:2018-2033 | pin_prefix / unpin_prefix helpers |
~16 |
| 3 | scheduler/tests.rs, docs/api.md, runtime.rs | redundant assert, internals prose, long comment | ~12 |
| 4 | cache.rs | direct_request_pins and its guard |
~7-8 |
Ranked by lines saved.
1. Should fix (scope) — flare_reserved_kv_pages is a second gauge (~20 lines)
What goes. The reserved-growth page gauge, its stats field, its metric slot, its store, its help text, its doc sentence and its test rows, entirely:
helios/src/scheduler.rs:132-133(doc +pub reserved_pages: usize),1204(let mut reserved_pages = 0;),1208(reserved_pages += request.reserved_pages.len();),1221(reserved_pages,)helios/src/server/metrics.rs:266(atomic),518(store),1314-1318(name/help/gauge, 5 lines),1791(test fixture input),1836(test row)helios/src/server/runtime.rs:2448(reserved_pages: 0,)docs/api.md:304-305(definition sentence) and308-309(+ flare_reserved_kv_pagesinside the ratio)helios/src/scheduler/tests.rs:1019(tuple element),1023(assert), and the reserved half of1030
What replaces it. Nothing. The ratio in docs/api.md becomes flare_request_kv_pages over flare_total_kv_pages, and the copy-out override at runtime.rs:2441-2450 shrinks to one field:
scheduler: crate::scheduler::SchedulerStats { request_pages: 0, ..self.scheduler.stats() },
Why nothing is lost. Issue #537's proposal names exactly one gauge: "A gauge flare_request_kv_pages: distinct KV pages referenced by active requests (private pages plus shared/pinned prefix pages), each page counted once. Then flare_request_kv_pages / flare_total_kv_pages matches vLLM's metric." Reserved growth pages are not in the request, and nothing reads them beyond the Prometheus text: search_code reserved_pages under helios/src/server returns only the metrics field, its store, its gauge block, the two test lines and runtime.rs:2448. The JSON Snapshot (metrics.rs:70-110) has no such field, the page table in docs/api.md:330-360 lists cached/free/total only, dashboard.rs:515-529 renders cached/free/total only, and no script under scripts/ reads it. The author's own live numbers put reserved at 16-22 pages of 20,480 and 2-3 of 21,504, i.e. the documented ratio moves by ~0.1%.
Charter / rules. Charter line 35: "What gets merged: PRs that address a maintainer request, a roadmap item, a reproducible bug, a measured performance/memory issue, or bad docs." AGENTS.md:165-169 adds that hypothetical future consumers do not establish a need, and docs/design-review.md:125 asks reviewers to reject scope expansion. The maintainer request is #537's single gauge.
Must not cut: LiveRequest::reserved_pages (scheduler.rs:255) is scheduling state used at 1359, 1387, 1417-1426, 1480, 2183-2196, 2390, 2435, 2891, 3171 and in the checkpoints/sharing paths — untouched by this finding.
2. Should fix — pin_prefix / unpin_prefix (~16 lines)
What goes. helios/src/scheduler.rs:2018-2033: a doc comment plus two seven-line helpers that only dispatch on a bool.
What replaces it. A one-line if/else at each of their exactly three call sites — search_code pin_prefix|unpin_prefix returns only the definitions and 1638, 1649, 1671:
if let Some(id) = pinned { if request_pin { self.cache.pin_request(id)? } else { self.cache.pin(id)? } }
The file already writes that shape inline (scheduler.rs:1553 } else { self.cache.lookup(&history)? };, 2991). Net ~16 lines: the 17-line helper block minus one extra line written at each of the three sites.
Why nothing is lost. request_pin (scheduler.rs:1636, inbound.is_none()) still names the concept at the call sites, and both branches stay reachable: 1631-1635 pins the ticket ancestor plainly when creating && inbound.is_some(), and the request's own prefix when inbound.is_none().
Charter. "Keep the runtime small and model-agnostic" (charter line 12) and the How-We-Work guidance to "look for the smallest footprint in shared code"; docs/design-review.md:16, "Keep Helios as simple as possible".
3. Should fix — three leftovers around the new code (~12 lines)
All at bca7358.
(a) helios/src/scheduler/tests.rs:1013-1026 (~5 lines). The fold into branching_requests_own_distinct_tail_pages_and_terminal_snapshots is complete (the old standalone test is gone), but the added block carries a redundant assert!(!first_request.shared_pages.is_empty()); (1013 — the following assert_ne! on private pages and the two count assertions all fail on an empty set), a five-line tuple destructure (1016-1020) and a three-line comment (1024-1026) that restates the two cancel assertions. Smaller:
let stats = scheduler.stats();
assert_eq!(
stats.request_pages,
first_request.shared_pages.len()
+ first_request.private_pages.len()
+ second_request.private_pages.len()
);
scheduler.cancel(first).unwrap();
scheduler.cancel(second).unwrap();
let stats = scheduler.stats();
assert_eq!(stats.request_pages, 0);
assert!(stats.cached_pages > 0);
(b) docs/api.md:302-307 (~5 lines, of which 304-305 also go with finding 1). Two sentences of internals that no other gauge in this file documents: "Neither gauge counts pages draining after a request retires, or a restore ticket's in-flight pages" and "The worker publishes both when a scheduler pass makes progress, and again at startup and after the shutdown drain; a scrape reads the last published values." Compare the free/cached/total page fields at docs/api.md:350-352 — one line each, no cadence, no transient states. Keep the definition (298-301), the flare_cached_kv_pages overlap note (301-302) and the ratio.
(c) helios/src/server/runtime.rs:2443-2445 (~2 lines). A three-line comment for a one-field struct override (after finding 1). One line — "Decode moves the page count without moving cache resources." — says the same thing.
4. Nit — direct_request_pins and its guard (~7-8 lines)
What goes. helios/src/cache.rs:82-83 (doc + field), 461 (init), 531 (+= 1), 547-549 (the guard), 556 (-= 1), plus the fixture copy at helios/src/cache/lifecycle_tests.rs:77.
What replaces it. Nothing — and delete the guard with the field, because the check directly below it already covers the case:
if request && self.checkpoint(id)?.direct_request_pins == 0 {
return Err("checkpoint has no request pin to release".into());
}
if self.checkpoint(id)?.direct_pins == 0 {
return Err("checkpoint is not pinned".into());
}
Why nothing is lost. direct_request_pins <= direct_pins by construction, so the direct_pins == 0 check at cache.rs:550-552 already rejects a release on an unpinned checkpoint; every unpin_request site in scheduler.rs matches a pin_request (1649/1671 ↔ 1638, 1882 ↔ 3148, 2970 ↔ 2972, 2990 ↔ 2991). The pages still come from the request_pins chain counter (cache.rs:539/565), and the #[cfg(test)] drift assertion (cache.rs:827-846) still checks that counter against a full scan.
Why only a nit. This trades a cache-side caller check for a scheduler invariant that no type enforces; AGENTS.md:182-186 ("Do not remove validation") is a defensible counterargument, so a maintainer may keep it.
Do not cut (checked, load-bearing)
Checkpoint::request_pins(cache.rs:84-85, 461, 537-540) andPrefixCheckpointCache::request_pinned_pages(cache.rs:222-224, 253, 539, 565, 851, 189) with the#[cfg(test)]drift assertion (cache.rs:827-846) — this is precisely what keepsCache::statsfrom scanning the checkpoint graph, which the description and #537 require.- The compaction agreement assert (cache.rs:635-636) and
debug_assert!(node.request_pins > 0)(cache.rs:562): compaction moves the count into the surviving checkpoint, and charter line 42 requires the interaction to be checked across every cache scheme. pin_with/unpin_with(cache.rs:519-589): already the shorter shape — one body plus four thin wrappers. The previous round listed this as an optional subtraction; the author banked it, so it is not re-raised. Plainpin/unpinwrappers keep ~30 call sites (cache/tests.rs, lifecycle_tests.rs:181-667, scheduler/cache_memory.rs (not opened), sharing/tests.rs (not opened), vision_window_tests.rs (not opened)) pluspin_checkpoint/unpin_checkpoint(scheduler.rs:2037-2043) and the ticket-parent pins (scheduler.rs:1864, 1900).- The per-slot stats loop (scheduler.rs:1202-1209): it already existed to count
active_requests(was a.filter().count()), so summing private pages there costs no second pass. - The copy-out retry key zeroing (runtime.rs:2441-2450):
CopyoutResourcesderivesPartialEqover the wholeSchedulerStats(runtime.rs:1053-1059) and is compared at 2455, so a decode that moves request pages would re-trigger deferred host copy-outs. Needed; shrinks to one field once finding 1 lands. - The retired-request pin release moved before
request.take()(scheduler.rs:3142-3149): a real ordering requirement of the counter. flare_request_kv_pagesitself (metrics.rs:265, 517, 1309-1313, 1790, 1835) and its two test rows: the maintainer request.
Left behind
Nothing dead. Cache::pin/unpin still have live callers (scheduler.rs:1864, 1900, 2037-2043, plus the test sites above), has_pins (cache.rs:291) keeps its one caller (scheduler.rs:1262), and no flag, config or doc elsewhere in the repository describes the pre-change state. The new struct fields are additive (SchedulerStats, CacheStats; Checkpoint's fixture copy at cache/lifecycle_tests.rs:74-97 is updated).
Open questions / caveats
- The suite was not run here and the head commit has no CI checks; "809 passed, 1 failed" is the author's number, not verified.
- Finding 1 is a scope judgement: if a maintainer wants the reserved-growth number for its own sake, the gauge stands and the total removable drops to ~35 lines. On the stated purpose (the vLLM-comparable ratio) it buys ~0.1%.
- Finding 4 is the only one where a maintainer may reasonably prefer the existing check.
Total: ~55 of the 202 added lines removable (~28%), in four places.