Code review summary report · NVIDIA/hyperflare-inference #549

Raw Markdown for agents: https://autobot.eidonix.com/p/d8ca7f9b-35b6-4739-a6c0-6afe037bd479.md

PR #549 — Report KV pages held by active requests (head bca7358)

Reviewed at head bca7358c ("Fix KV-page docs ratio and fold duplicated page tests"), 8 files, +202/−34. Closes #537. Sibling open metrics PR: #548 (same author). Verdict: Changes Requested — the change is small and what is left is one docs edit, one restored assertion, and deletions.

Key findings

Blockers

None. Correctness is clean at this head — every request-owned pin has a matching release on success and failure paths, the counter cannot underflow or strand pages, architecture reports no blocking issue, and no prose claim is outright false.

Should Fix (2)

SF1. docs/api.md:298-310 — the paragraph never says the gauges are text-only, and it asserts a vLLM equivalence the PR declines to claim

Two defects in one 13-line paragraph; both fixable in one edit.

(a) Nothing says the two gauges are absent from ?format=json. The PR description states it ("They are not added to the JSON snapshot"), the adjacent paragraph already routes text-only families (docs/api.md:292-296), the JSON field table has no row for either gauge (docs/api.md:330-360), and Snapshot deserializes absent fields as zero (docs/api.md:317-318). A dashboard author on the JSON path therefore reads zeros and concludes no request holds KV pages. This replaces two competing options from other lenses (add table rows = more prose; leave it = misleading) with one sentence.

(b) "(flare_request_kv_pages + flare_reserved_kv_pages) over flare_total_kv_pages is the share comparable to vLLM's kv_cache_usage_perc" (docs/api.md:308-310) asserts a cross-runtime equivalence, while the description says "No comparison with another runtime is claimed". The mapping is definitional (vLLM counts blocks held by running requests over total blocks), so name it as the definition being followed.

Requested replacement for docs/api.md:298-310 (13 → 14 lines, both defects fixed):

`flare_request_kv_pages` counts the distinct KV pages that requests owning a
model slot reference: their private pages plus the tail pages of the prefix
checkpoints they pin, each page counted once even when several requests
reference it. It is not disjoint from `flare_cached_kv_pages`: a pinned
checkpoint stays published, so its tail pages count in both gauges. Neither
gauge counts pages draining after a request retires, or a restore ticket's
in-flight pages. `flare_reserved_kv_pages` counts pages reserved for those
requests' growth that are neither free, cached, nor written yet. Both are text
only and absent from the `?format=json` snapshot. 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.
`(flare_request_kv_pages + flare_reserved_kv_pages)` over
`flare_total_kv_pages` is the share that uses vLLM's `kv_cache_usage_perc`
definition; idle cached prefixes and snapshot backing pages are outside it.

Why: AGENTS.md:52-60 (not opened) (state support as present qualification) and AGENTS.md:95-102 (not opened) (distinguish definition from measurement). The cadence and exclusions already in the text are correct and are kept (runtime.rs:722, 1148-1153, 743-746; ticket pages popped from free at scheduler.rs:1686-1688 and only pinned at 1882).

SF2. helios/src/cache/tests.rs + PR description — the head commit deleted the only test of the new request-pin release guard, and the description still cites it

bca7358 removed assert!(cache.unpin_request(parent).is_err()) from branching_pins_ancestors_and_prevents_direct_ancestor_unpin; what survives at cache/tests.rs:336 is assert!(cache.unpin(parent).is_err()), which exercises the plain direct_pins == 0 guard (cache.rs:550-552), not the new request-pin guard (cache.rs:547-549) — verified at the head: the parent holds only descendant request pins, and the call is the plain unpin. The description's Evidence section still says the test proves "releasing the parent without a request pin is an error".

That leaves the new guard — and the field direct_request_pins it protects (cache.rs:82-83, 461, 531, 556) — with no test at all, and the scheduler can never reach it (every unpin_request site follows a successful pin_request: scheduler.rs 1638/1649/1671, 1882, 2970/2972, 2990/2991, 3148). Meanwhile the guard is the only release-build detector of a mismatched release: a checkpoint can be pinned both by a request and for copy-out (pin_checkpoint, scheduler.rs:2037-2038), so a duplicated unpin_request would otherwise drive request_pins below truth and subtract tail_pages from request_pinned_pages unchecked (cache.rs:561-566; the debug_assert! at 562 is test-only).

Requested change — pick one, do not ship the field and the missing test together:

Either way the description sentence must be corrected, because the surviving assertion tests the plain-pin guard. Why: AGENTS.md:194-199 (not opened) requires tests to exercise the affected contract; the head commit removed the only one that did.

Subtract / Simplify (~55 of +202 added lines, ~27%; ~75–80 if S4 is taken)

S1 (~16 lines, should-fix severity) — delete pin_prefix/unpin_prefix; the cache already dispatches the same flag

helios/src/scheduler.rs:2018-2033 is a doc comment plus two helpers whose whole body is if request { cache.pin_request(id) } else { cache.pin(id) } (verified: 2019-2025 and 2027-2033). Their three call sites are all inside admission (1638, 1649, 1671, driven by request_pin from 1636); the six other request-pin sites call the cache directly (1882, 2970, 2972, 2990, 2991, 3148). So the repo now has two ways to name a pin kind — the named pin_checkpoint/unpin_checkpoint convention (2035-2043) and a bare bool — and the bool wrapper is the least used of the three.

Fix: make the cache entry points the single dispatcher and delete the pair, e.g. pub(crate) fn pin_for(&mut self, id, request: bool) / unpin_for beside helios/src/cache.rs:519-589, then self.cache.pin_for(id, request_pin)? at 1638 and self.cache.unpin_for(id, request_pin)? at 1649 and 1671; delete scheduler.rs:2018-2033. Net −16 lines, one fewer layer, and the flag is visible at the call site. Do not instead inline the conditional at the three call sites — that adds lines.

S2 (~8 lines) — leftovers from the test fold and the runtime comment

S3 (~9 lines, alternative to SF2) — direct_request_pins and its guard

Only consumer is the guard at cache.rs:547-549. Deleting the field (82-83), initialiser (461), increment (531), decrement (556), guard (547-549) and the fixture copy (helios/src/cache/lifecycle_tests.rs:77) removes a branch no test and no scheduler path reaches. It also removes the only release-build check of a mismatched release, so prefer restoring the one-line test (SF2) unless you are comfortable that unpin_request pairing is enforced by the scheduler alone.

S4 (~20-25 lines, scope decision for the owners) — flare_reserved_kv_pages is a second gauge #537 did not ask for

Issue #537 asks for one thing: "A gauge flare_request_kv_pages … Then flare_request_kv_pages / flare_total_kv_pages matches vLLM's metric." Reserved growth pages are not in it; the reserve is an independent visibility goal (real: those pages are popped out of free_pages at scheduler.rs:1714-1717 and are therefore invisible in every existing gauge).

If the maintainers want #537 literally, delete: scheduler.rs:132-133, 1204, 1208, 1221; metrics.rs:266, 518, 1314-1318, 1791, 1836; runtime.rs:2448 (the zeroing block shrinks to a single request_pages: 0,); docs/api.md:304-305 and the reserved part of 308-309 (the ratio becomes request/total, exactly what #537 names); scheduler/tests.rs:1019, 1023, 1030. Nothing else reads the value — it appears in no JSON Snapshot field and no view function. Three lenses (architecture, simplicity, correctness) accept it as-is, so this is a decision rather than a defect; it is listed so the line saving is not lost, and #548 is the natural home for it.

Nits (7)

  1. helios/src/scheduler.rs:1213, 1216, 1222-1233 — stats() still walks self.slots three more times (retiring slots, anchor guards, inbound waiters) beside the new loop at 1205-1209, on every progressing pass (runtime.rs:1148-1149) plus startup (722) and the shutdown drain (745). Folding them into the existing loop is ~14 lines shorter and three passes fewer.
  2. helios/src/cache.rs:529-532, 547, 550, 554-557 — pin_with fetches nodes[&id] twice (529, 531) and unpin_with calls checkpoint(id)? twice (547, 550) and get_mut twice (554, 556). One let node = self.nodes.get_mut(&id).unwrap(); per function saves ~4 lines and two hash lookups per pin and per release on the admission/ticket/boundary/retirement paths. Careful: chain() starts at id, so the direct counters must stay out of the ancestor loop.
  3. helios/src/scheduler.rs:3144-3145 — retire re-reads the slot twice (self.request(handle)?.prefix, self.request(handle)?.error_code) although prefix is bound at 3113 and error_code is read at 3110, with nothing writing either in between: bind failed once beside 3113.
  4. helios/src/server/runtime.rs:1053-1059 with 2441-2450 — CopyoutResources embeds all of SchedulerStats, so every future gauge joins the deferred-copy-out comparison key by default and needs a second edit here. Correct as written; a key struct holding only the copy-out-relevant fields is the smaller long-term shape, but it changes which movements re-offer copy-outs, so it is a note, not a request for this PR.
  5. docs/api.md:304-305 and helios/src/server/metrics.rs:1316 — "not yet written" is imprecise at the commit boundary: a reserved page popped into private_pages at scheduler.rs:2434-2437 is counted in request_pages until the GPU completion fence though it is still unwritten. "pages set aside for those requests' growth that no request holds a page for yet" is exact.
  6. Naming drift for the same set: docs/api.md:298 says "requests owning a model slot", scheduler.rs:130 and metrics.rs:1311 say "active requests" — while inbound_waiting counts a restore waiter as active (scheduler.rs:137-138) although it holds no prefix pin. Adopt the docs wording in both code sites.
  7. Coverage note, no action requested: nothing drives publish_boundary's Existing { ready: true } re-pin (scheduler.rs:2987-2999) with a stats read — the path where a request swaps its parent's request pin for a checkpoint another request already pins. The Cache::stats drift assertion would catch a double count; the cheapest future reach is a variant of the existing scheduler fixture, not a new test.

Open questions / what could not be verified