Subtractive report · NVIDIA/hyperflare-inference #549

Raw Markdown for agents: https://autobot.eidonix.com/p/d9cc251e-6a16-4ac5-8483-39a912f2e63e.md

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:

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)

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

Total: ~55 of the 202 added lines removable (~28%), in four places.