Full report — PR #549 "Report KV pages held by active requests"
Verdict: Changes Requested. Scope and approach are right: the count is maintained on the pin paths so Cache::stats keeps its no-scan-nodes property, the gauges ride the existing gauge array, update table and expected-exposition rows, and there is no flag, per-model branch, or second representation — inside the charter's "smallest footprint in shared code" and the AGENTS.md (not opened) contribution-scope rules. What remains is one blocker that costs three lines, five should-fix items (three of them prose accuracy), and about 90 removable added lines.
Size: +218/−10 across 7 files (docs/api.md +9, helios/src/cache.rs +60/−1, cache/lifecycle_tests.rs +3, cache/tests.rs +24, scheduler.rs +38/−9, scheduler/tests.rs +66, server/metrics.rs +18). Closes #537; the sibling PR is #548 (which closes #536). Case file: this document plus the summary post.
Key findings
- One blocker: an observability struct drives a control decision.
SchedulerStatsderivesPartialEqand is embedded whole inCopyoutResources, so the two new gauges now re-offer deferred host copy-outs — contradicting the PR's "no scheduling decision changes". - Five should-fix: two false/misleading
docs/api.mdsentences, one missed predicate (pinned) that lets an unpair bug become a silent leak, one 3× repeated pin-kind conditional, and one doc comment describing bookkeeping the cache does not do. - ~90 of +218 added lines removable (≈41%), rising to ~112 if the unrequested second gauge goes; the largest single win is a duplicate 66-line scheduler test.
- The accounting itself is correct on every path traced, and the
#[cfg(test)]full-scan drift assertion inCache::statsmakes it cheap to keep correct. Do not re-litigate it.
Blockers
B1. The new gauges are part of the key that decides whether deferred host copy-outs are re-offered.
SchedulerStats derives PartialEq (helios/src/scheduler.rs:112) and is embedded whole in CopyoutResources (helios/src/server/runtime.rs:1053-1059):
#[derive(Clone, Copy, PartialEq, Eq)]
struct CopyoutResources {
completed: crate::cache::Fence,
scheduler: crate::scheduler::SchedulerStats,
exports: usize,
next: Option<(usize, u32, bool)>,
}
service_store rebuilds it every pass and compares (runtime.rs:2441-2449) to set retry_copyouts, which decides whether ids parked in deferred_copyouts (runtime.rs:2462-2470) get another export_fits + store.store attempt. Adding request_pages/reserved_pages (scheduler.rs:130-133) puts live-request accounting into that key, and both move with no cache-resource movement:
commitpops pages fromrequest.reserved_pagesintorequest.private_pages(scheduler.rs:2433-2438) whilefree_pageswas already reduced byrefill_reservations(scheduler.rs:1383-1425), so every page-boundary crossing shiftsrequest_pages+1 /reserved_pages−1;retireempties both intoself.retired(scheduler.rs:3143,3170-3183) whilefree_pageswaits for the fence.
Change: build the key without the two live gauges — let mut scheduler = self.scheduler.stats(); scheduler.request_pages = 0; scheduler.reserved_pages = 0; with a one-line comment — or name the fields the key actually needs. Alternatively state in the description that copy-out retry cadence now follows live-request page movement.
Why: copy-out re-offer timing is a scheduling decision, and the description claims there are none. The effect is bounded (extra export_fits attempts when headroom has not returned; copyout_headroom_deferrals cannot inflate because of the contains guard at runtime.rs:2465-2468), but an observability struct should not drive a control decision — and the claim is what the next reviewer will rely on.
Settled by: a runtime test that leaves one copy-out deferred for headroom, advances one decode step crossing a page boundary, and asserts FakeStore saw no second store call.
Should Fix
S1. docs/api.md:302-303: "Both are gauges read from scheduler state on each scrape" is false.
Metrics::render only loads atomics (the two gauges at helios/src/server/metrics.rs:1309-1318; value.load(Ordering::Relaxed) at 1394-1396) and never calls RequestScheduler::stats. The atomics are stored by the worker on iterations that made progress (helios/src/server/runtime.rs:1148-1149), at start (722) and after shutdown (745). With an idle or stopped worker a scrape reports an arbitrarily stale value — exactly the case where someone watches request pages fall to zero.
Change: delete the sentence. The gauge contract is already established at api.md:287-296 and by every page row of the table; nothing needs adding in its place.
S2. docs/api.md:303-305: the ratio paragraph is wrong in three ways.
Current text: "Dividing flare_request_kv_pages by flare_total_kv_pages gives the KV share held by live requests; idle cached prefixes and snapshot backing pages are outside that share."
- reserved pages are outside the numerator and disjoint from it (
scheduler.rs:1216-1230); #537 asks for vLLMkv_cache_usage_percparity, which counts blocks already allocated to running requests — so sayrequest + reservedis the comparable figure; - request-pinned tail pages are counted in both gauges: they are tail pages of checkpoints still in
nodes(cache.rs:551-561), socount/uncountstill adds them tocached_pages(cache.rs:257-275→flare_cached_kv_pages,metrics.rs:1304-1308). The wording must not letfree + cached + requestread as a partition; - "live requests" overclaims: a retiring request's pages sit in
self.retireduntil the fence (scheduler.rs:3143,3170-3183) and an in-flight host restore's pages sit in the ticket (scheduler.rs:1704-1723), yetinbound_waitingdocuments those requests as active (scheduler.rs:137-138). Say "requests still owning a slot", or name both exclusions.
Change: one rewritten sentence pair; the paragraph already has the definition it needs, so nothing should be added.
Evidence knock-on: the description's live check request + reserved < total − free − cached does not validate this gauge — total − free − cached is dominated by snapshot-backing pages (metrics.rs:1294-1298) and is not a superset bound on request pages. The in-repo drift assertion comparing request_pinned_pages against a full scan of nodes on every stats read (cache.rs:817-837) is stronger evidence and already covers every cache and scheduler test. Cite that instead, or alongside.
S3. scheduler.rs:1643-1649, 1657-1664, 1682-1690: the same pin-kind conditional is written three times.
inbound is immutable for the whole function, so all three sites are deterministically the same branch; the repo already decides once for exactly this reason (pin_checkpoint/unpin_checkpoint, scheduler.rs:2038-2044), and the pinned binding (1638-1642) was already the "decide once" shape.
Change: carry the choice in that binding — let pin = pinned.map(|id| (id, inbound.is_none())) — and use one small pin_as/unpin_as (or a local closure) at the three sites. The branch itself must stay: the ticket-parent pin has to exist before ensure_resources evicts, so do not collapse the three to pin_request. Today a future edit that changes one site produces a pin on one counter and an unpin on the other, invisible in release builds.
S4. scheduler.rs:3143 vs 3155-3159: retire can now fail after it has already emptied the slot.
self.slots[..].request.take() runs before self.cache.unpin_request(prefix)? and before retiring = true (3169) and the self.retired.push (3171). If unpin_request ever returned Err (cache.rs:565-568) the slot would hold no request, the retirement would not be recorded, the request value would be dropped and the prefix pin would leak for the life of the process. Not reachable today — the pin/release symmetry is intact on every path (see "Verified correct" below) — but the new error path turns a future unpair bug into a silent leak instead of a detected one.
Change: release the pin before request.take(), or debug_assert! at the release site instead of propagating.
S5. cache.rs:548-550: the doc comment claims bookkeeping the cache does not do.
"Request pins also track the pages the request keeps referenced: its private pages plus the pinned ancestors' pages, each page counted once." request_pinned_pages only ever moves from node.tail_pages.len() at the 0↔1 transitions of request_pins (cache.rs:553-561, 572-578); private pages are added by the scheduler (scheduler.rs:1216-1222). A reader cannot tell whether adding them double counts.
Change: state the cache's half in one line and point at the consumer, e.g. "adding the tail pages of every checkpoint on its chain to request_pinned_pages while at least one request pin remains. A request's private pages are not cache pages; the scheduler adds them."
Subtract / Simplify
Could remove ~90 of +218 added lines without changing behaviour (up to ~112 if flare_reserved_kv_pages also goes). Nothing in the diff adds a parallel mechanism — the gauges reuse the existing gauge array, update table and expected-exposition rows — so the removable weight is inside the diff, not in its design.
- ~55 lines —
helios/src/scheduler/tests.rs:970-1034re-runs an existing test's whole scenario.request_kv_pages_count_shared_prefix_pages_once(+66) reproducesbranching_requests_own_distinct_tail_pages_and_terminal_snapshots(tests.rs:1036-1081) step for step: samescheduler(2, 8, 5), same seed prefill/freeze/finish, same twoadmit(spec(65, 4)), same fences 5 and 7, sameretain_prompt(6)— and that test already asserts the two requests shareshared_pages(tests.rs:1078). Only thestatsassertions and the doublecancelare new: append those ~10 lines to the existing test (keepassert!(!first_request.shared_pages.is_empty()), and keep the handles instead of shadowing them at1076-1077) and delete the new test. Coverage of shared-counted-once, the reserved sum and retire-drains-to-zero is preserved, and the merged test gains coverage of the retirement-drain path it lacks today. - ~25 lines — fold
pin_request/unpin_requestintopin/unpin. They callself.pin(id)?and then walkself.chain(id)?a second time (cache.rs:551-563,565-580;pinchains at523and walks530-532,unpinat540), so every request pin and release pays two walks and twoVecallocations on the admission (scheduler.rs:1645), ticket-waiter (1900), boundary-publication (2971/2991) and retirement (3159) paths — and the guard suite (readiness,u64::MAXsaturation,direct_pins) exists in two places that must agree. One privatefn pin_with(&mut self, id, request: bool)with both counter sets inside the existing loop, andpin/pin_requestas one-line wrappers (mirror for unpin): deletes ~25 lines, one traversal, and gives therequest_pins0↔1 transition a single site — the right home for adebug_assertorsaturating_subon theusizesubtraction atcache.rs:576. The drift assertion andrequest_pinned_pagessemantics are unchanged, so the existing tests keep passing. - ~10 lines —
helios/src/cache/tests.rs:322-328copies the fixture ofbranching_pins_ancestors_and_prevents_direct_ancestor_unpin(tests.rs:346-352) verbatim (cache(),history(2, 0),history(1, 0)+append, the same threecreated(..., proposal(...))with pages 0/1/2). Fold the request-pin assertions into that test after itspin(left_id)/pin(right_id)at355-356and delete the duplicated preamble. In the same pass dropcache/tests.rs:335(assert!(cache.unpin_request(parent).is_err())): it only re-tests the direct-pin guard already covered at358for the plain API, andparentholds no direct request pin, so it is not evidence about the shared-page accounting the test is named for. The real evidence (331-334,336-341) survives. - ~22-25 lines, conditional —
flare_reserved_kv_pagesis a second gauge #537 did not ask for. #537 asks forflare_request_kv_pagesor acachedpinned/idle split, plus optionally a ready-made ratio; it never mentions reserved growth. If S2 namesrequest + reservedin the ratio, the gauge earns its place and this item is withdrawn. If not, delete in one pass:scheduler.rs:132-133,1223-1228;metrics.rs:266,518,1314-1318,1791,1836;docs/api.md:301-302and the reserved clause at304-305. Nothing else reads it — it is deliberately absent from the JSON snapshot, so no dashboard sees it.
Keep, checked and not cuttable: Checkpoint::request_pins; PrefixCheckpointCache::request_pinned_pages and its 0↔1 brackets (this is what lets stats avoid scanning nodes); the compaction assertion (cache.rs:626-627) that lets pages move into the heir without touching the counter; the extended #[cfg(test)] drift assertion (cache.rs:817-837) — the highest test value per line in the change; the request_pages sum in SchedulerStats::stats (this is the requested number); the atomic/store/render triple and its two table rows; docs/api.md:298-300.
In particular do not delete Checkpoint::direct_request_pins (cache.rs:82-83): a checkpoint can be pinned both by a request and for host-store copy-out (pin_checkpoint, scheduler.rs:2038-2044), so the guard at cache.rs:565-568 is the only release-build detector of a mismatched release.
Nits
scheduler.rs:1203-1228:stats()now walksself.slotsthree times (active_requests1203-1207,private_pages1216-1222,reserved_pages1223-1228). One fold yields both new fields and makes them read as the pair the docs describe:let (request_pages, reserved_pages) = self.slots.iter().filter_map(|s| s.request.as_ref()).fold((cache.request_pinned_pages, 0), |(p, r), q| (p + q.private_pages.len(), r + q.reserved_pages.len()));. No behaviour change;stats()runs per progress, not per scrape.cache.rs:626: "Both nodes are counted or neither is, and the pages move into the counted heir" — "counted" does two jobs; "the ancestor's request pins equal its heir's, and its pages move into that heir" says it once.docs/api.md:298-306: one home for the content. The paragraph partly restates the HELP text (metrics.rs:1310-1317) and the page table (api.md:325-348) listscached_pages/free_pages/total_pagesbut not the two new Prometheus-only gauges — consistent, since that table mirrors JSON fields, so do not add rows unless the JSON snapshot gains them. If a JSON note is wanted, one clause ("Neither appears in the JSON snapshot") suffices; if a design-doc home is preferred,docs/runtime-core-design.md:873already carries theflare_snapshot_backing_pagesrule and could hold these — but only as a replacement for the api.md prose, not in addition.- Coverage, optional and free: no test drives
pin_requestthroughpublish_boundary'sExistingbranch (scheduler.rs:2988-3000) — the one place where a second request pins a checkpoint another just published, where a double count or a missed pin would hide. The merged test from the first subtraction item is the cheapest place to reach it; no new test needed. - Description only, fold into one bullet: (a) "a checkpoint leaves
nodesonly at zero pins" is wrong for compaction —compact_ancestorrequiresdirect_pins == 0 && child_count == 1(cache.rs:662,686-690) and the new assert at627permits nonzero pins carried into the heir, so say that folding an ancestor into its heir loses no request pin; (b) "A page shared through a pinned ancestor therefore counts once for every request that references it" contradicts the code and the PR's own test — it is counted once in total (cache.rs:553-561), andrequest_pins_count_each_shared_page_onceasserts 3, not 4 (cache/tests.rs:331-334); (c) the sibling PR is #548, not #536 (#536 is the issue #548 closes).
Verified correct — do not press these
- Request pin/unpin symmetry on every scheduler path: admission
pin_requestwheninbound.is_none()(scheduler.rs:1643-1649) with mirroredunpin_requestin both rollback arms (1657-1664,1682-1690); ticket waiterspin_request(1900) immediately beforeprefix = Some(id); boundary publicationCreated(2971-2974) andExisting(2991-2992) pin the new checkpoint beforeunpin_request(parent); retirementunpin_request(3159); ticket-parent pins for host admission keep the plain API (1638-1642,1881-1883,1917-1919); copy-out/export usepin_checkpoint/unpin_checkpoint(2038-2044) and never touch a request prefix, so the new "no request pin to release" error cannot fire from them. - The counter cannot drift:
request_pinned_pagesmoves only at the 0↔1 transition ofnode.request_pins(cache.rs:551-580), exactly matching the full-scan assertion inCache::stats(817-837). Compaction keepsnode.request_pins == child.request_pinswithdirect_pins == 0(613-631), so pages moving into the heir leave the total unchanged;retire_leaf/cancel_publicationrequirepins == 0(594-663), so no counted node leavesnodes.pinrejectsu64::MAXbeforerequest_pinscan grow (524-528), andunpin_requestrejects the release atdirect_request_pins == 0before decrementing anything (566-568). - No duplicated pre-existing helper: nothing in the tree computed "pages held by live requests", and
has_pins(cache.rs:291) is not a duplicate of the new counter. reserved_pagessemantics hold: reserved pages are popped fromfree_pagesat admission (scheduler.rs:1732-1735) and are disjoint fromprivate_pages(commitmoves them across,2433-2438), so "neither free, cached, nor written" is accurate.- Merge logistics: the
metrics.rsregions touched are disjoint from #548's, so the two merge in either order. - Prose scheme and disclosures: all four questions are present in order, the "why" names the constraint that makes the approach valid (
Cache::statsmust not scannodes), the Discord line is present and last, the unrun Windows build and full suite are disclosed, and the live numbers are scoped to one instance with "no comparison claimed". - Not findings: the third-party fork base
5ffe4d54(upstream PR #482) means the live numbers are not reproducible from this branch, and head5ed7af8has no CI checks — both are disclosed honestly in the description and should not be pressed.
Open questions and what could not be verified
- Is
request + reservedthe intended operator figure? If yes,flare_reserved_kv_pagesstays and the fourth subtraction item is withdrawn; the omission in the ratio paragraph, not the choice, is the defect. - Intended semantics of the inbound ticket pages (
scheduler.rs:1704-1723) and of pages inself.retired: either the prose names the exclusions or the counters cover them. A test asserting both gauges duringRequestPhase::Inboundand during retirement drain would settle the phase boundaries exactly, and would also decide whether the doc or the accounting is wrong. - Whether the extra copy-out retries from B1 are observable in
flare_host_cache_reoffer_calls_total— only the runtime test sketched under B1 or a scrape during a long deferral settles it. - The
docs/api.mdratio dips during drain by one GPU fence's worth of pages; I could not measure that against the documented scrape interval. - The live scrape numbers (request 399/402, reserved 3/2, cached 2037/2043 of 21504 pages, ratio ≈0.0186/0.0187 on the two-GPU DeepSeek-V4.1-Flash instance) cannot be reproduced here. The in-repo drift assertion is what attests the gauge independently of that instance, and it is verified.
- Not verified here: CI status, the Windows build, and the
--libpass count (the description's 508 tests in--lib -- cache:: scheduler:: server::metricsis taken on trust; I read the named tests in source). - Note for the author: whether #537 was filed by a maintainer affects the merge path under AGENTS.md (not opened) ("addresses a maintainer request"); the owners should confirm, not the reviewer. I also could not apply the repo prose skill (
.agents/skills/repo-prose/SKILL.md(not opened)) itself — its requirements are reflected in the prose findings above, but an owner should do the style pass.