Subtractive scratchpad · NVIDIA/hyperflare-inference #549

Raw Markdown for agents: https://autobot.eidonix.com/p/46dac617-5032-457c-89d7-5cb6e6f9183f.md

#1 [high] Should fix: scheduler test duplicates an existing test's entire 40-line scenario (~55 lines)

helios/src/scheduler/tests.rs:970-1034 (request_kv_pages_count_shared_prefix_pages_once, +66 lines) reproduces, step for step, the scenario already in helios/src/scheduler/tests.rs:1036-1081 (branching_requests_own_distinct_tail_pages_and_terminal_snapshots). Both: scheduler(2, 8, 5); admit spec(64,1); init(1); plan/commit Fence(2); complete records(seed,2,64,1,77,2); freeze(seed,3); finish(seed); two admit(spec(65,4)); init(4); plan/commit Fence(5); complete records(first,5,65,1,88,1); retain_prompt(6); assert next plan is Prefill on second; commit Fence(7); complete records(second,7,65,1,90,1). The existing test already asserts the two requests share shared_pages and differ in private_pages.

Smaller version: delete request_kv_pages_count_shared_prefix_pages_once and append its four assertions to the existing test:

let stats = scheduler.stats();
assert_eq!(stats.request_pages, shared + 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, loses nothing: the same shared/private/reserved quantities and the same cancel-drains-to-zero path are checked, and the shared prefix, private pages and zero-pin retirement are still covered.

#2 [high] Should fix: second gauge flare_reserved_kv_pages is outside the issue's request (~20-25 lines)

Issue #537 (body read in full) asks for one of: (1) flare_request_kv_pages, or (2) split flare_cached_kv_pages into pinned/idle, plus optionally a ready-made ratio. It never mentions the pages reserved for active requests' growth. The PR adds that as a second, independent gauge: SchedulerStats::reserved_pages (helios/src/scheduler.rs:132-133), its computation in stats() (scheduler.rs:1223-1228, 6 lines), Metrics::reserved_pages (helios/src/server/metrics.rs:266), the store row (metrics.rs:518), the gauge entry with help text (metrics.rs:1314-1318), the test fixture value (metrics.rs:1791) and assertion row (metrics.rs:1836), and docs/api.md:301-302 plus the "reserved_kv_pages" name in the PR description and evidence section. Chromium checks: reserved_pages (the Vec<PageId> on LiveRequest) already exists and is used by scheduling; only the reported gauge is new, and no caller/consumer besides the Prometheus text uses it — it is not in the JSON Snapshot (metrics.rs:99-110 has no such field, and docs/api.md:325+ table lists only cached_pages, free_pages, total_pages), so no dashboard, view or Snapshot function reads it.

Smaller version: delete the reserved_pages stats field, its six-line sum in stats(), the metrics atomic + store row + gauge triple, the two test lines, and docs/api.md:301-302 ("flare_reserved_kv_pages counts pages reserved ... written yet." and drop the reserved mention from the last sentence). Saves ~20-25 lines. Nothing #537 asks for is lost; flare_request_kv_pages alone gives the vLLM-semantics ratio the issue wants. If a maintainer does want reservation visibility, it belongs in its own change with its own justification, per the charter's "stay focused / smallest footprint" rule.

#6 [high] Total: 218 added lines, ~95-105 removable; the rest is minimal

Total added/removed from the diff (7 files, +218/-10): 218 added, 10 removed, of which the removable/consolidatable estimate is ~95-105 lines:

Also verified: no code the change supersedes or leaves dead. Cache::pin/unpin keep real callers (host-store ticket pins scheduler.rs:1647/1662/1688/1882/1918, pin_checkpoint/unpin_checkpoint runtime.rs:2360-2489), and no existing helper computes the same number (has_pins cache.rs:291 only answers "any direct pin", and SchedulerStats had no page-held field). No branch or dead path is left behind in admit_planned other than the inbound.is_none() pairs itself.

#8 [high] Research summary

Reviewed PR #549 (Report KV pages held by active requests) through the subtraction lens. All seven changed files and the code they touch (Cache::pin/unpin, chain, compact_ancestor, SchedulerStats::stats, admit_planned, finish_inbound, publish_boundary, retire, the metrics gauge table and the test fixtures) were read in place; findings are in the scratchpad.

Four confirmed subtractions, ~95-105 of the 218 added lines:

  1. Should fix (~55 lines): helios/src/scheduler/tests.rs:970-1034 re-runs, line for line, the scenario already in branching_requests_own_distinct_tail_pages_and_terminal_snapshots (tests.rs:1036-1081). Its four assertions fold into that test.
  2. Should fix (~22-25 lines): flare_reserved_kv_pages is a second feature; issue #537 asks only for the pages active requests hold, and nothing but the Prometheus text reads this value (it is not in the JSON snapshot). It can go with its stats field, metric slot, help text, test rows and docs sentence.
  3. Nit (~12-14 lines): Checkpoint::direct_request_pins exists only for the "no request pin to release" guard, which unpin already enforces at the same call sites; the scheduler never releases a pin it did not take through pin_request.
  4. Nit (~10 lines): helios/src/cache/tests.rs:322-328 repeats the fixture of the test directly below it verbatim.

The rest is minimal and should stay: the two counter fields, the compaction debug_assert, the extended test-only drift assertion, and the request_pages sum are the smallest version of the requested number. Nothing the change supersedes is left dead. One candidate (the three pin/unpin branch pairs in admit_planned) was checked and rejected as load-bearing.

#9 [high] Charter citations and verification checklist for the report

Charter (read_charter, NVIDIA/hyperflare-inference) lines to cite:

Verification performed (so the report can say "checked", not "looks like"):

Report ranking (by lines saved): 1) scheduler test duplication ~55; 2) reserved gauge ~22-25; 3) direct_request_pins ~12-14; 4) cache test fixture ~10. Then the "already minimal" list and the rejected candidate. Total: pr_diff counted +218/-10 across 7 files; ~95-105 removable (~45% of what was added).

#3 [medium] Nit/Should fix: direct_request_pins and its guard duplicate unpin's own check (~12 lines)

Checkpoint::direct_request_pins (helios/src/cache.rs:82-83, initialised cache.rs:460, incremented cache.rs:553, decremented cache.rs:570) exists only for the guard at cache.rs:566-568: if self.checkpoint(id)?.direct_request_pins == 0 { return Err("checkpoint has no request pin to release") }. The scheduler, the only caller of unpin_request, releases exactly the id it pinned: admission rollback (scheduler.rs:1660, 1686 pairs with 1645), boundary republishing (2972-2973, 2992), ticket waiters (1900 with the release at 3159 on the request's own prefix), and retirement (3159). No path releases a checkpoint it did not pin through pin_request, so the guard cannot fire; unpin (cache.rs:536-540) already rejects a release with no direct pin, which catches the same misuse. The check is also unreachable from the new test's positive side, which pins parent through pin_request in order to exercise the error branch (helios/src/cache/tests.rs:335) — the error path has to be constructed.

Smaller version: delete direct_request_pins and its four touch points (field + doc comment 3 lines, init 1, += 1 1, -= 1 1) and the four-line guard, and delete the two lines in the Fixture::fork copy at helios/src/cache/lifecycle_tests.rs:77-78 plus the assert!(cache.unpin_request(parent).is_err()) and its setup at helios/src/cache/tests.rs:335. 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, which is exactly what CacheStats::request_pinned_pages documents (cache.rs:188-189) and what the stats drift assertion checks (cache.rs:830-834).

#5 [medium] Nit: cache test repeats branching_pins test's fixture verbatim (~10 lines)

helios/src/cache/tests.rs:320-342 (request_pins_count_each_shared_page_once) opens with the same eight-line fixture as the test directly below it, branching_pins_ancestors_and_prevents_direct_ancestor_unpin (cache/tests.rs:344-352): let mut cache = cache(); let left = history(2, 0); let mut right = history(1, 0); right.append(&[999; 64], &[]).unwrap(); let parent = created(... proposal(None, 64, &[0], 0, 0)); let left_id = ...; let right_id = ... — character for character the same. The existing test already pins both children, asserts the shared parent's pin_count() is 2→1, compacts it, and checks page_chain stays [PageId(0), PageId(2)].

Smaller version: drop the duplicate preamble (cache/tests.rs:322-328) by moving the request-pin assertions into the existing test after its pin(left_id)/pin(right_id) pair, and keep only the four request-pin lines (pin_request ×2, the 3/2/0 counts and the plain-pin-leaves-it-unchanged line). Saves ~9-12 lines. The distinct behaviour still proven: the shared ancestor's page counts once for two request pins, plain pins do not move the count, and the count returns to zero. (The unpin_request(parent).is_err() line goes with the direct_request_pins finding.)

#4 [low] Note: fixture and metrics-test line accounting

helios/src/cache/lifecycle_tests.rs:74-95 adds two fields to the Fixture::fork struct-literal copy (direct_request_pins, request_pins at :77-78) and one to the cache copy (request_pinned_pages at :95). These are forced only because the fixture hand-copies every private field; they disappear with the direct_request_pins removal (separate finding) except request_pins/request_pinned_pages, which are needed by the counter. Zero saving beyond that, noted so the count is not double-claimed.

helios/src/server/metrics.rs test: metrics.rs:1790-1791 and :1835-1836 add two fixture values and two rows to the fixed-name table in counters_expose_fixed_names_without_request_payloads. That test is a table of every gauge name; the two rows are the cheapest possible coverage (2 lines each, no new test) — keep.

Net: the only removable lines in the metrics test are the reserved_pages pair if that gauge goes (finding on issue scope).

#7 [low] Rejected candidate: the admit_planned pin branches

helios/src/scheduler.rs:1637-1649, 1657-1664, 1683-1690 hold three copies of the same 5-line if inbound.is_none() { unpin_request } else { unpin } pair. Considered and rejected as a subtraction: the branch is load-bearing. The ticket-parent pin (inbound.is_some() && creating) must be taken before ensure_resources (scheduler.rs:1682), because that call evicts checkpoints and the ancestor must survive until finish_inbound releases it (scheduler.rs:1882); moving the pin below, so all three sites could call pin_request, would leave the ancestor evictable during eviction. Factoring the pair into a two-line helper would save ~8 lines but adds an abstraction whose only purpose is to hide a genuine two-kind distinction, so it is not a net subtraction. No finding.