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
- Scope and approach remain right. The change lives in shared runtime layers only — cache accounting (
helios/src/cache.rs), scheduler stats and the pin API (helios/src/scheduler.rs), Prometheus text (helios/src/server/metrics.rs), the deferred-copy-out key (helios/src/server/runtime.rs),docs/api.md. No per-model branch, flag, env switch, or allocation/eviction/scheduling change;Cache::statsstill does not scannodes(cache.rs:825-861). Matches the charter ("keep the runtime small and model-agnostic", "smallest footprint in shared code") andAGENTS.md:165-200(not opened). - The four round-1/round-2 fixes are all in place at this head — do not re-raise them. The two gauges are zeroed when the
CopyoutResourcesretry key is built (runtime.rs:2441-2456);retirereleases the request pin before emptying the slot (scheduler.rs:3142-3150); thecache.rsdoc comment states only the cache's half (cache.rs:580-582);pin_request/unpin_requestare thin wrappers over onepin_with/unpin_withthat walks the chain once (cache.rs:519-589). - The head commit's two test folds are correct and land the biggest saving.
branching_requests_own_distinct_tail_pages_and_terminal_snapshots(scheduler/tests.rs:970-1032) keeps every assertion of the test it absorbed;branching_pins_ancestors_and_prevents_direct_ancestor_unpin(cache/tests.rs:320-373) now covers the shared-page count, the plain copy-out pin, the ancestor unpin guard, and compaction into the pinned heir (asserted 2, then 0). The docs paragraph now names one comparable share,(request + reserved) / total, scopes the gauge to "requests owning a model slot", states the correct publish cadence, and no longer mentions#[cfg(test)]. - One coverage regression was introduced by the same fold (SF2): the deleted assertion
assert!(cache.unpin_request(parent).is_err())was the only test of the newunpin_requestguard (cache.rs:547-549). - Verified correct — do not re-flag: request pin/release symmetry on every path (admission
scheduler.rs:1636-1638,1649,1671; ticket waiters1882; boundary publication2970/2972,2990/2991; retirement3148); ticket-parent pins keeping the plain API (1864,1900) and copy-out viapin_checkpoint/unpin_checkpoint(2037-2043); reserved pages genuinely popped out offree_pagesat admission and only later consumed intoprivate_pages(scheduler.rs:1714-1717,2434-2437);request_pinned_pagesmoving only on the 0↔1 crossings (cache.rs:536-541,561-566); compaction carrying request pins and tail pages into the heir under an assert (cache.rs:632-641); eviction gated onpins/child_count(cache.rs:667-673); gauges inside the existing gauge array, bulk store and test rows (metrics.rs:265-266,517-518,1309-1318,1790-1791,1835-1836) with nothing added to the JSONSnapshot; the test-only drift assertion comparing the kept counter to a full scan on everystatsread (cache.rs:827-846). - Not pressed: a
docs/runtime-core-design.md(not opened) entry (would add prose); new tests forpublish_boundary'sExistingbranch (cheapest reach is a variant of the existing fixture); any performance claim (none is made, so no benchmark is required); JSON-table rows for the two gauges (replaced by one prose sentence in SF1).
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:
- Preferred (one line): restore the assertion before
cache/tests.rs:338:assert!(cache.unpin_request(parent).is_err()); // parent holds only descendant request pins - Or delete the field, its initialiser, both adjustments, the guard and the lifecycle-fixture copy (
cache.rs:82-83,461,531,547-549,556;cache/lifecycle_tests.rs:77) and rely on the drift assertion (cache.rs:827-846) — about 9 lines, listed as S3 below.
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
helios/src/scheduler/tests.rs:1016-1020: the five-line tuple destructure is ceremony around threelen()sums; bind them on one line each.helios/src/scheduler/tests.rs:1024-1026: the three-line comment restates the two assertions below it (request_pages/reserved_pages→ 0). One clause suffices.helios/src/server/runtime.rs:2443-2445: "Decode moves request and reserved page counts without moving cache resources; zeroing them keeps deferred host copy-outs keyed on the cache state they actually depend on" fits in one line ("Decode moves page counts without moving cache resources.").- Keep
assert!(!first_request.shared_pages.is_empty())at1013: it is not redundant — if the shared prefix were empty the count assertions would still pass and the test would silently stop testing sharing.
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)
helios/src/scheduler.rs:1213,1216,1222-1233—stats()still walksself.slotsthree more times (retiring slots, anchor guards, inbound waiters) beside the new loop at1205-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.helios/src/cache.rs:529-532,547,550,554-557—pin_withfetchesnodes[&id]twice (529,531) andunpin_withcallscheckpoint(id)?twice (547,550) andget_muttwice (554,556). Onelet 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 atid, so the direct counters must stay out of the ancestor loop.helios/src/scheduler.rs:3144-3145—retirere-reads the slot twice (self.request(handle)?.prefix,self.request(handle)?.error_code) althoughprefixis bound at3113anderror_codeis read at3110, with nothing writing either in between: bindfailedonce beside3113.helios/src/server/runtime.rs:1053-1059with2441-2450—CopyoutResourcesembeds all ofSchedulerStats, 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.docs/api.md:304-305andhelios/src/server/metrics.rs:1316— "not yet written" is imprecise at the commit boundary: a reserved page popped intoprivate_pagesatscheduler.rs:2434-2437is counted inrequest_pagesuntil 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.- Naming drift for the same set:
docs/api.md:298says "requests owning a model slot",scheduler.rs:130andmetrics.rs:1311say "active requests" — whileinbound_waitingcounts a restore waiter as active (scheduler.rs:137-138) although it holds no prefix pin. Adopt the docs wording in both code sites. - Coverage note, no action requested: nothing drives
publish_boundary'sExisting { 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. TheCache::statsdrift 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
- No CI checks exist on
bca7358. The description's "809 passed, 1 failed" (filteredcache::/scheduler::/server::, the failure being theFLARE_TEST_TEMPLATE_DIRtemplate test) is taken on trust; the tests it cites were read and match their claims. Windows build, exported core and the full suite are disclosed as unrun. - The live scrape (request 399/402, reserved 3/2, cached 2037/2043 of 21504;
(request + reserved)/total= 0.0187/0.0188;request + reserved ≤ total − freeat 402/5922 and 404/6104) is not reproducible from this branch: it needs the AzallazA fork commit5ffe4d54and two GPUs. The description labels the instance, discloses that the agent's own session traffic was served, notes the one-pass publication lag, and claims no cross-runtime comparison. The in-repo drift assertion (cache.rs:827-846) is the checkable evidence; the description would be stronger citing it. - Authorization: the need rests on issue #537 (user-filed, Napuh), which documents a concrete gap that the shipped gauges cannot compute; that satisfies
AGENTS.md:165-169(not opened), but owners may prefer #537's option 2 (splitflare_cached_kv_pagesinto pinned/idle) or a ready-made ratio gauge, which would change S4's answer. - Not verified here: any GPU workload beyond the scrape, an exported core, the Windows build, the full helios suite, and the #548 merge order (both PRs touch disjoint regions of
metrics.rs). - Description nit carried for the author: the body's own live check
request + reserved < total − free − cacheddoes not attest the gauge (total − free − cachedis dominated by snapshot-backing pages,metrics.rs:1294-1298); the correct implied boundrequest + reserved ≤ total − freeis already stated. Also the sibling-PR cross-reference in the description ("#536") does not match the related-items list, which pairs this PR with #548 — likely a stale number.