Subtractive report · NVIDIA/hyperflare-inference #549

Raw Markdown for agents: https://autobot.eidonix.com/p/361100db-ee76-45fa-970b-63d7516e86b8.md

Subtraction review — PR #549, "Report KV pages held by active requests" (head bca7358)

Reviewed all 8 changed files in place with their callers, issue #537 and the charter. Nothing was run: the head commit has no CI checks here, so all counts below are static readings of the diff and the files at bca7358. Verdict is much milder than two rounds ago — the last push folded the two duplicated tests and merged the request-pin bodies, so the diff fell from +246/−16 to +202/−34 and only about 55–58 added lines (≈28%) remain removable, all small and mechanical. What is left is not a size problem; it is one unrequested gauge plus one wrapper pair.

Key findings

# Severity Where Lines saved
1 Should fix (scope) flare_reserved_kv_pages — a second gauge #537 never asked for ~20
2 Should fix pin_prefix/unpin_prefix: bool-dispatch wrappers with three callers ~16
3 Should fix leftovers after the test fold (test block, docs prose, comment) ~12
4 Nit direct_request_pins + its guard duplicate unpin's own check ~7–10

Charter (read in full) used for the judgements: "Look for the smallest footprint in shared code, or a way to solve it without new code at all" and "not interested in piling on extra … switches" for #1 and #2; line 35, "What gets merged: PRs that address a maintainer request…" for the scope finding; line 42, "Check interactions across every supported model, cache scheme…" for the things that must stay (the compaction assert and the drift assertion guard every cache scheme).


1. Should fix (scope) — flare_reserved_kv_pages is a second feature (~20 lines)

Issue #537 asks for one thing: a gauge of the pages active requests hold — "A gauge flare_request_kv_pages: distinct KV pages referenced by active requests … Then flare_request_kv_pages / flare_total_kv_pages matches vLLM's metric." Reserved growth pages are not in it. The PR adds them as an independent goal, and nothing but the Prometheus text ever reads the number.

Lines to delete:

Nothing replaces it. Consumers checked: grep reserved_pages in helios/src/server hits only the metrics struct/store/gauge/test rows and the copy-out-key line above; it is absent from the JSON snapshot field table (docs/api.md:330–360, which lists only cached/free/total pages), so no dashboard or view function gains anything. LiveRequest::reserved_pages already exists for scheduling (scheduler.rs:1726); only the aggregate is new, and scheduler.rs:1221's reserved_pages field is the only place it surfaces. Removing it also shrinks the copy-out-key override at runtime.rs:2441–2450 to a single request_pages: 0, (that block itself must stay — see "do not cut"). flare_request_kv_pages alone gives the ratio #537 names; if reservations are wanted, #548 (same author, open) is the natural home.

2. Should fix — pin_prefix/unpin_prefix cost 16 lines over inlining (~16 lines)

helios/src/scheduler.rs:2018–2033 (new in the last push) is a doc comment plus two eight-line helpers that only dispatch on a bool:

    /// Pins `id` for an active request, or for a host admission ticket's parent.
    fn pin_prefix(&mut self, id: CheckpointId, request: bool) -> Result<()> {
        if request { self.cache.pin_request(id) } else { self.cache.pin(id) }
    }
    fn unpin_prefix(&mut self, id: CheckpointId, request: bool) -> Result<()> {
        if request { self.cache.unpin_request(id) } else { self.cache.unpin(id) }
    }

They have exactly three call sites — scheduler.rs:1638 (pin_prefix), 1649 and 1671 (unpin_prefix), confirmed by search_code pin_prefix|unpin_prefix, which returns only those five lines. Each replaced a one-line self.cache.pin(id)? / self.cache.unpin(id)?, so the call sites now read self.pin_prefix(id, request_pin)?. Delete 2018–2034 and inline the conditional at the three sites:

        let request_pin = inbound.is_none();
        if let Some(id) = pinned {
            if request_pin { self.cache.pin_request(id)? } else { self.cache.pin(id)? }
        }

and the same for the two rollback arms at 1649/1671 with unpin_request/unpin. Net ~16 lines saved (8% of +202). Nothing is lost: request_pin still names the concept, both branches stay reachable (the ticket parent pins plain, request admission pins request), and the file already uses this one-line conditional style at scheduler.rs:2991 (if let Some(parent) = … { self.cache.unpin_request(parent)?; }).

3. Should fix — leftovers around the new code (~12 lines)

(a) helios/src/scheduler/tests.rs:1013–1026, added block: a redundant assert!(!first_request.shared_pages.is_empty()) (1013) — the following assert_ne! on private pages and the two count assertions fail on an empty set anyway; a five-line tuple destructure (1016–1020); and a three-line comment (1024–1026) restating the cancel assertions. Write it straight:

    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);

~5 lines.

(b) docs/api.md:298–310 is now 13 lines around a 4-line definition. Two stretches are internals no other gauge in the file carries: 302–304 ("Neither gauge counts pages draining after a request retires, or a restore ticket's in-flight pages") and 305–307 (publication cadence: "The worker publishes both when a scheduler pass makes progress, and again at startup and after the shutdown drain"). ~5 lines. The definition, the flare_cached_kv_pages overlap note and the ratio stay.

(c) helios/src/server/runtime.rs:2443–2445: the three-line comment fits in one ("Decode moves the page counts without moving cache resources."). ~2 lines.

Total ~12.

4. Nit — direct_request_pins exists only for its own guard (~7–10 lines)

helios/src/cache.rs:82–83 (doc + field), 461 (initialiser), 531 (+= 1), 547–549 (the guard), 556 (-= 1), plus helios/src/cache/lifecycle_tests.rs:77 (fixture copy) and helios/src/cache/tests.rs:336 (the test that constructs the error). Its only reader is the guard:

        if request && self.checkpoint(id)?.direct_request_pins == 0 {
            return Err("checkpoint has no request pin to release".into());
        }

Since direct_request_pins ≤ direct_pins, the direct_pins == 0 check immediately below (cache.rs:550–552) already rejects a release on a checkpoint with no pins, and every unpin_request site releases a prefix the matching path pinned through pin_request: scheduler.rs 1649↔1638, 1671↔1638, 1870 (with 1882), 2972↔2970, 2991↔2990, 3148 (with 3144, prefix recomputed). Delete the field, its init, its two adjustments and the 3-line guard; the request_pins chain counter alone still yields request_pinned_pages, and the #[cfg(test)] drift assertion still checks it. ~7 lines, 10 with the lifecycle fixture line. Caveat: this trades a cache-side caller check for the scheduler's pairing, which no type enforces, so a maintainer may reasonably keep it — hence Nit, not Should fix.


Do not cut (checked as load-bearing)

Left behind

Nothing dead. Cache::pin/unpin retain real callers (scheduler.rs:1864, 1900, 2037–2043; runtime.rs checkpoint pins; ~13 test sites in cache/tests.rs, cache/lifecycle_tests.rs, scheduler/cache_memory.rs (not opened), sharing/tests.rs (not opened), vision_window_tests.rs (not opened)), and has_pins (cache.rs:291) is not superseded by the new counter. No flag, config or doc elsewhere describes the old state.

Open questions / not checked

Total: ~55–58 of 202 added lines removable in 4 places (≈28%). Verdict: make it smaller first — one unrequested gauge and one wrapper pair are most of it; the cache-side bookkeeping is the irreducible core.