Subtraction review — PR #549, "Report KV pages held by active requests"
Key findings
The requested number is small: one counter plus a gauge. The change is roughly twice that size. Of +218/−10 lines across 7 files, about 95–105 lines (≈45% of the additions) can go without losing a single behaviour the issue asks for:
| # | Severity | Where | Lines saved |
|---|---|---|---|
| 1 | Should fix | helios/src/scheduler/tests.rs:970–1034 — new test repeats an existing test's whole 40-line scenario |
~55 |
| 2 | Should fix | flare_reserved_kv_pages — a second gauge outside issue #537's request |
~22–25 |
| 3 | Nit | helios/src/cache.rs:82–83 — direct_request_pins exists only for a guard unpin already provides |
~12–14 |
| 4 | Nit | helios/src/cache/tests.rs:322–328 — fixture copied verbatim from the test below |
~10 |
Everything else is already the smallest version of what #537 asked for, and no code the change supersedes is left dead anywhere.
Project rules I judged against (read_charter, NVIDIA/hyperflare-inference): "Look for the smallest footprint in shared code, or a way to solve it without new code at all" and "Stay focused… We're not interested in piling on extra model aliases, random switches" (How We Work); "What gets merged: PRs that address a maintainer request…" (Standards). #537 is the maintainer request this change answers, and it bounds the scope.
1. Should fix — the scheduler test re-runs an existing test's entire scenario (~55 lines)
File: helios/src/scheduler/tests.rs:970–1034 (request_kv_pages_count_shared_prefix_pages_once, +66 added lines)
The new test reproduces, line for line, the scenario already in branching_requests_own_distinct_tail_pages_and_terminal_snapshots (helios/src/scheduler/tests.rs:1036–1081), which sits immediately below it:
- both:
scheduler(2, 8, 5)→admit(spec(64, 1))→init(1)→ plan/commitFence(2)→complete(records(seed, 2, 64, 1, 77, 2))→freeze(seed, 3)→finish(seed) - both:
admit(spec(65, 4))twice →init(4)→ plan/commitFence(5)→complete(records(first, 5, 65, 1, 88, 1))→retain_prompt(6)→ assertGraphKind::Prefillonsecond→ commitFence(7)→complete(records(second, 7, 65, 1, 90, 1)) - the existing test already asserts the two requests share
shared_pagesand differ inprivate_pages(tests.rs:1078–1080), which is the setup the new test exists to reach.
The only new content is four assertions and a cancel pair. Append them to the existing test:
// after tests.rs:1080, inside branching_requests_own_distinct_tail_pages_and_terminal_snapshots
let stats = scheduler.stats();
assert_eq!(stats.request_pages,
first.shared_pages.len() + first.private_pages.len() + second.private_pages.len());
assert_eq!(stats.reserved_pages,
first.reserved_pages.len() + second.reserved_pages.len());
scheduler.cancel(first).unwrap();
scheduler.cancel(second).unwrap();
let stats = scheduler.stats();
assert_eq!((stats.request_pages, stats.reserved_pages), (0, 0));
assert!(stats.cached_pages > 0);
Saves ~55 of the 66 added lines. Nothing is lost: the same shared/private/reserved quantities, the same shared-prefix-counted-once behaviour, and the same retire-drains-to-zero path are still asserted — against a fixture the suite was already paying for. The one thing the deleted version adds is the assert!(!first_request.shared_pages.is_empty()) line (tests.rs:1010), which is worth keeping in the merged form; it is one line.
2. Should fix — flare_reserved_kv_pages is a second feature, not the one requested (~22–25 lines)
Files: helios/src/scheduler.rs:132–133, helios/src/scheduler.rs:1223–1228, helios/src/server/metrics.rs:266, :518, :1314–1318, :1791, :1836, docs/api.md:301–302
Issue #537 (read in full) asks for exactly one thing, with alternatives: "A gauge flare_request_kv_pages: distinct KV pages referenced by active requests…", or "Split flare_cached_kv_pages into pages of checkpoints with at least one pin and pages of unpinned checkpoints", plus optionally a ready-made ratio. It never mentions pages reserved for active requests' growth. The PR description itself introduces that as an independent goal ("pages reserved for active requests' growth are invisible: they are neither free, cached, nor written") — a defensible observation, but a separate change with its own justification, which is what the charter's "stay focused" and "smallest footprint" rules ask for.
Consumers checked: helios/src/server/metrics.rs:266/518/1317 are the only readers. The value is deliberately not in the JSON Snapshot (the PR says so; docs/api.md:345–347 lists only cached_pages, free_pages, total_pages), so no dashboard, view, or snapshot function reads it. LiveRequest::reserved_pages (helios/src/scheduler.rs:255) already exists and is used throughout scheduling — only the reported aggregate is new.
Delete, in one pass:
helios/src/scheduler.rs:132–133—reserved_pagesfield and doc comment (2)helios/src/scheduler.rs:1223–1228— the six-linereserved_pages:sum instats()helios/src/server/metrics.rs:266—reserved_pages: AtomicU64helios/src/server/metrics.rs:518— the store rowhelios/src/server/metrics.rs:1313–1317— the gauge tuple and help texthelios/src/server/metrics.rs:1791— the fixture value;:1836— the assert rowdocs/api.md:301–302— theflare_reserved_kv_pagessentence, and drop the "reserved" wording from the closing sentence at :304–305
Saves ~22–25 lines. flare_request_kv_pages alone already yields the vLLM-semantics ratio #537 asks for (request / total), and the drift assertion (see §5) still validates request_pinned_pages. No stated purpose of the issue is lost.
3. Nit — direct_request_pins and its guard duplicate unpin's own check (~12–14 lines)
File: helios/src/cache.rs:82–83 (field + doc), :460 (init), :553 (+= 1), :566–568 (guard), :570 (-= 1)
direct_request_pins is read in exactly one place — the guard at helios/src/cache.rs:566–568:
if self.checkpoint(id)?.direct_request_pins == 0 {
return Err("checkpoint has no request pin to release".into());
}
It was added solely so unpin_request can distinguish request pins from plain pins. But the scheduler, the only caller (helios/src/scheduler.rs:1660, 1686, 2973, 2992, 3159), releases exactly the id it pinned through pin_request (:1645, 1900, 2971, 2991), so the guard cannot fire in production — and unpin (helios/src/cache.rs:536–540) already rejects a release with no direct pin, which catches the same misuse class. The only thing that exercises the guard is the new test at helios/src/cache/tests.rs:335, which has to pin parent through pin_request first purely to construct the error.
Delete the field, its three touch points, the guard, the two copied lines at helios/src/cache/lifecycle_tests.rs:77–78, and the two lines in helios/src/cache/tests.rs:335 (and :326's now-unneeded setup). unpin_request becomes:
pub fn unpin_request(&mut self, id: CheckpointId) -> Result<()> {
self.unpin(id)?;
let chain = self.chain(id)?;
for ancestor in chain {
let node = self.nodes.get_mut(&ancestor).unwrap();
node.request_pins -= 1;
if node.request_pins == 0 {
self.request_pinned_pages -= node.tail_pages.len();
}
}
Ok(())
}
Saves ~12–14 lines. The counter still counts tail pages of checkpoints with request_pins > 0, exactly what CacheStats::request_pinned_pages documents (helios/src/cache.rs:188–189) and what the drift assertion tests. If a maintainer prefers keeping a defensive assertion over the two lines it costs, that is a fair call — it is a nit, not a defect — but the field is unnecessary either way: the guard could compare request_pins on the chain.
4. Nit — the cache test's fixture is copied verbatim from the test below (~10 lines)
File: helios/src/cache/tests.rs:322–328
request_pins_count_each_shared_page_once (tests.rs:320–342) opens with eight lines that are character-identical to the fixture of branching_pins_ancestors_and_prevents_direct_ancestor_unpin (tests.rs:346–352): cache(), history(2, 0), history(1, 0) + append, and the three created(… proposal(…)) calls with the same pages 0/1/2 and parents. The existing test already pins both children, checks the shared parent's pin_count() falling 2→1, and compacts it.
Fold the request-pin assertions into the existing test after its pin(left_id)/pin(right_id) pair (tests.rs:355–356), and delete the duplicated preamble:
// keep only the request-pin-specific lines
cache.pin_request(left_id).unwrap();
cache.pin_request(right_id).unwrap();
assert_eq!(cache.stats().request_pinned_pages, 3); // shared page counts once
cache.pin(right_id).unwrap();
assert_eq!(cache.stats().request_pinned_pages, 3); // a plain pin changes nothing
cache.unpin_request(left_id).unwrap();
assert_eq!(cache.stats().request_pinned_pages, 2);
cache.unpin(right_id).unwrap();
assert_eq!(cache.stats().request_pinned_pages, 2);
cache.unpin_request(right_id).unwrap();
assert_eq!(cache.stats().request_pinned_pages, 0);
Saves ~9–12 lines. All four behaviours the new test proves survive — shared page counted once for two request pins, plain pins not moving the count, and the count returning to zero — because the fixture that reaches them is the existing one.
5. What must stay (already minimal — do not cut)
These were examined in place and are the smallest form of what #537 asks for:
Checkpoint::request_pins(helios/src/cache.rs:83–84) — one field.PrefixCheckpointCache::request_pinned_pages(helios/src/cache.rs:222–224) and the two-line bracket in each ofpin_request/unpin_request(:558–560,:575–577). This is what letsCache::statsavoid scanningnodes, which the PR (and the existingstatsdesign) explicitly requires; a full scan per scrape was rejected for good reason.- The compaction invariant
debug_assert_eq!(node.request_pins, child.request_pins)(helios/src/cache.rs:626–627) — two lines that are the reason compaction can move pages into an heir without touching the counter. Cheap and load-bearing. - The extended drift assertion (
helios/src/cache.rs:817–837,#[cfg(test)]only) — five added lines that check the new counter against a full scan on everystats()call in the entire suite. This is the highest test-value-per-line in the change; keep it. CacheStats::request_pinned_pages(helios/src/cache.rs:188–189) and therequest_pagessum inRequestScheduler::stats(helios/src/scheduler.rs:1216–1222) — this sum is the requested number.- The
flare_request_kv_pagesatomic/store/gauge triple (helios/src/server/metrics.rs:265, 517, 1308–1312) and its two table rows incounters_expose_fixed_names_without_request_payloads(:1790,:1835) — the table test is the cheapest possible coverage, two lines, no new test. docs/api.md:298–300and:303–305— the definition and the ratio statement the issue's dashboards need.
One further observation, not a finding: docs/api.md:298–303 largely restates the gauge help text in helios/src/server/metrics.rs:1308–1312. Both are user-facing surfaces and the duplication is conventional here (the table at docs/api.md:345–347 does the same for existing gauges), so cutting either would trade clarity for brevity.
6. Checked and rejected (not a subtraction)
- The three
if inbound.is_none() { unpin_request } else { unpin }pairs inadmit_planned(helios/src/scheduler.rs:1641–1649,1656–1664,1682–1690). These look like a candidate for a shared helper, but the branch is load-bearing: the ticket-parent pin (inbound.is_some()) must be taken beforeensure_resources(:1682), because that call evicts checkpoints and the ancestor has to survive untilfinish_inboundreleases it (:1882). Collapsing all three topin_requestwould leave the ancestor evictable during eviction. The distinction is real, not accidental. Cache::pin/unpindeadness. Still used by host-store ticket pins (helios/src/scheduler.rs:1647, 1662, 1688, 1882, 1918) and bypin_checkpoint/unpin_checkpoint(helios/src/server/runtime.rs:2360–2489). The plain API stays.- The
lifecycle_tests.rsfixture additions (helios/src/cache/lifecycle_tests.rs:77–78,:95).Fixture::forkhand-copies every private field, so two of these three lines are forced by the counter and the third (direct_request_pins) disappears with §3. Zero independent saving; noted so it is not double-counted. - No dead paths left behind. Nothing the change supersedes remains in the tree; all seven changed files were read with their callers.
has_pins(helios/src/cache.rs:291) answers only "any direct pin" and is not a duplicate of the new counter.
Open questions
- Does a maintainer want reserved-page visibility at all? If yes, §2 is not a subtraction but a scope split — the right move is still to land
flare_request_kv_pagesalone against #537 and open the reservation gauge separately. - §3 assumes the scheduler's pin/release pairing is a guarantee the reviewer may rely on. It holds at every call site I traced (
helios/src/scheduler.rs:1645↔1660, 1900↔3159, 2971↔2973, 2991↔2992, 1686), but it is an invariant no type enforces — a maintainer who wants it defended in the cache rather than the scheduler may prefer to keep the guard and drop only the field. - I did not run the suite (CI has no checks on this head commit); line counts come from the diff and file reads at head
5ed7af8.
Total: ~95–105 of 218 added lines removable in 4 places (≈45%). Verdict: make it smaller first — not because the change is wrong, but because item 1 alone halves it and item 2 is a feature the issue did not ask for.