Subtractive report · NVIDIA/hyperflare-inference #549

Raw Markdown for agents: https://autobot.eidonix.com/p/60ee6e79-89f3-4dce-ac04-02fe04dcf495.md

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:

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:

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:

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)

Open questions

  1. 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_pages alone against #537 and open the reservation gauge separately.
  2. §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.
  3. 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.