PR #549 — Report KV pages held by active requests (head bca7358)
Reviewed at bca7358c ("Fix KV-page docs ratio and fold duplicated page tests"), base main, 8 files, +202/−34, closes #537. Sibling PRs by the same author: #548 and #560. Verdict: Changes Requested — small; everything left is one deletion, one test line, and cutting about 50 of the +202 added lines. Nothing here asks for new code, new flags, or new docs.
Round delta: no new commits (search_history at pr/549: bca7358c, 9cca87ac, 5ed7af86, then main). Two things changed since the previous round: (a) the author posted a live-validation comment (2026-11-28 03:26) naming the build combination and the scrape numbers; (b) the PR description body was edited without a new commit, and its Evidence no longer claims the folded test proves "releasing the parent without a request pin is an error". Result: the description-side should-fix from the earlier round is resolved; the missing test-assertion half is not.
Key findings
- Scope and approach remain right. The change is confined to shared runtime layers —
helios/src/cache.rs(accounting),helios/src/scheduler.rs(stats + pin API),helios/src/server/metrics.rs(Prometheus text),helios/src/server/runtime.rs(copy-out retry key), and one paragraph indocs/api.md. No per-model branch, flag, environment switch, or optional policy path, and no change to allocation, eviction, preemption, or readmission.Cache::statsstill never scans the node graph (helios/src/cache.rs:825-861). Satisfies charter line 12 ("keep the runtime small and model-agnostic") andAGENTS.md:165-200(not opened). - Need is demonstrated. Issue #537 (user-filed) shows the gap with numbers and proposes exactly
flare_request_kv_pages; the PR implements #537's option 1 verbatim. SatisfiesAGENTS.md:165-169(not opened) and charter line 35. - Every earlier code defect is fixed at this head — do not re-raise. The copy-out retry key zeroes both new fields (
runtime.rs:2446-2449, comment2443-2445, compare2455);retirereleases the request pin beforerequest.take()(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_withwith a single chain walk (cache.rs:519-589); both test folds land with their assertions intact (cache/tests.rs:320-373,scheduler/tests.rs:970-1032). - Verified correct — do not re-flag: request pin/release symmetry on every path (admission
scheduler.rs:1636-1638,1649,1671; ticket waiters1882; boundary2970/2972,2990/2991; retirement3148); ticket-parent and copy-out pins stay on the plain API (1864,1900,2037-2043);request_pinned_pagesmoves only on the 0↔1 pin crossings (cache.rs:538-541,564-566); compaction carries pins and tail pages into the heir underdebug_assert_eq!(cache.rs:632-641); eviction is gated onpins/child_count(cache.rs:667-673); the gauges reuse the existing atomics table, bulk store and test rows with nothing added to the JSONSnapshot(metrics.rs:265-266,517-518,1309-1318,1790-1791,1835-1836); the test-only drift assertion compares the maintained count to a fullnodesscan on everystats()read (cache.rs:826-846). - The live-validation evidence is honest and now discloses the stack. The 03:26 comment names the build ("upstream main with this PR, #548, and #560 merged"), which is what
AGENTS.md:98-100(not opened) asks for, and its numbers are internally consistent (request + reserved < total − free). Checked atpr/548andpr/560: neither addsrequest_pages/reserved_pagestoSchedulerStats(pr/560'sstats()atscheduler.rs:1198-1200has no such fields), so the readings are attributable to this PR. - Two things remain: one pin-dispatch layer that two lenses flagged independently (SF1), and one coverage regression introduced by the head commit's test fold (SF2). Subtraction is the bulk of the remaining work: ≈50 of the +202 added lines (≈25%) can simply go.
- No instruction-injection attempt was found in the description or thread; the pasted
flare-autobotreview was treated as material, and its two should-fix items were re-derived independently here (they correspond to nit 3 and SF2).
Blockers
None. Audited and clean: the counter cannot drift, underflow, or be stranded (cache.rs:519-570, 825-861); every request-owned pin has a matching release on success, cancel, preempt, finish, and shutdown (scheduler.rs:3067-3085, 3105-3155); the gauges cannot perturb deferred copy-outs (runtime.rs:2446-2449); the JSON contract is unchanged (metrics.rs:355-393, docs/api.md:317-318); no prose claim is contradicted by the code.
Should Fix (2)
SF1. Delete pin_prefix/unpin_prefix; no function should take the pin kind as a bare bool
Where: helios/src/scheduler.rs:2018-2033 — a doc comment plus two seven-line helpers whose entire body is if request { self.cache.pin_request(id) } else { self.cache.pin(id) } (definitions at 2019 and 2027).
Why. The scheduler now names a pin kind three ways: the named, documented pair pin_checkpoint/unpin_checkpoint (scheduler.rs:2035-2043, the only path to a copy-out pin, with every caller routed through it), the bool pair at 2019/2027, and raw self.cache.*_request calls. Six request-pin sites bypass the pair entirely — 1882, 2970, 2972, 2990, 2991, 3148 — so the wrapper is the least-used of the three shapes. Its only three callers are 1638, 1649, 1671, all passing request_pin from 1636, and a reader at 1638 cannot tell which counter moves without re-reading 1636. Meanwhile 1864 and 1900 (plain ticket-parent unpins) sit in the same function as the request pin at 1882, so the two kinds meet exactly where a mismatch is cheapest and nothing names which is which. A swapped kind is silent in a release build; the only detector is the #[cfg(test)] full-scan assertion (cache.rs:826-846), and only if some test reads stats afterwards. Rules: docs/design-review.md:16 (not opened) ("Keep Helios as simple as possible"), AGENTS.md:188-193 (not opened) (reject an added forwarding layer that removes no demonstrated source of defects).
Requested change (net −13 lines). Delete both helpers, and at the three admission sites select the named cache method once, where request_pin is bound (scheduler.rs:1631-1636):
// 1638
if let Some(id) = pinned { if request_pin { self.cache.pin_request(id)? } else { self.cache.pin(id)? } }
and mirror the shape at the two release sites 1649 and 1671. This is the shape the file already writes inline elsewhere (scheduler.rs:1553, 2991). Do not replace the pair with a 14-line named-helper variant; deletion is both smaller and removes the layer. Keep pin_checkpoint/unpin_checkpoint as they are.
SF2. Restore the one assertion that reaches the unpin_request double-release guard
Where: helios/src/cache/tests.rs:320-373 (the folded test) and helios/src/cache.rs:547-549.
Why. Checkpoint::direct_request_pins (cache.rs:83: "Direct pins held by active requests, a subset of direct_pins") has exactly one reader in the tree — the guard if request && self.checkpoint(id)?.direct_request_pins == 0 { return Err("checkpoint has no request pin to release") } (cache.rs:547-549). Writers are only 461 (init), 531 (+= 1), 556 (-= 1), plus a fixture copy at cache/lifecycle_tests.rs:77. The head commit's test fold deleted the only assertion that exercised that branch: the merged test now asserts the plain guard (assert!(cache.unpin(parent).is_err()), cache/tests.rs:336), and both surviving unpin_request calls (338, 359) follow a pin_request on the same id. The three scheduler sites (2972, 2991, 3148) likewise always hold a request pin. So the PR adds a guard branch and a per-checkpoint counter that no test reaches — AGENTS.md:194-199 (not opened) ("tests must exercise the affected behaviour or contract").
Requested change (one line). Insert immediately before cache/tests.rs:338:
assert!(cache.unpin_request(parent).is_err());
parent holds only descendant request pins (via left_id/right_id), so it has no direct request pin and the guard fires. This is what the deleted assertion did, and it should pass without touching production code. The alternative is to delete the field and guard outright (see S3); do not do both.
Subtract / Simplify
≈50 of the +202 added lines (≈25%) can be deleted, in four places. Subtraction is preferred over every additive suggestion raised by the other lenses.
S1 — Drop the second gauge flare_reserved_kv_pages (~20-25 lines) — scope call
The maintainer request (#537) names one gauge: "A gauge flare_request_kv_pages … Then flare_request_kv_pages / flare_total_kv_pages matches vLLM's metric." Reserved-growth pages are a second gauge nothing else reads: search_code reserved_pages under helios/src/server returns only the metric field, its store, its gauge block, the two test lines, and the retry-key override. The JSON Snapshot (metrics.rs:70-110) has no such field, the page table in docs/api.md:350-352 lists cached/free/total only, dashboard.rs:515-529 (not opened) renders cached/free/total only, and no script under scripts/ reads it. The author's own live numbers put reserved at 16-22 of 20,480 pages and 2-3 of 21,504, i.e. the documented ratio moves by ~0.1%.
Removals: scheduler.rs:132-133 (doc + field), 1204, 1208, 1221; metrics.rs:266, 518, 1314-1318, 1791, 1836; runtime.rs:2448 (leaving SchedulerStats { request_pages: 0, ..self.scheduler.stats() }); docs/api.md:304-305 and the + flare_reserved_kv_pages term at 308-309; scheduler/tests.rs:1019, 1023, and the reserved half of 1030.
Must not cut: LiveRequest::reserved_pages (scheduler.rs:255) is live scheduling state used at 1359, 1387, 1417-1426, 1480, 2183-2196, 2390, 2435, 2891, 3171 — untouched.
If a maintainer wants the reserved-growth number for its own sake, the gauge stands and the removable total drops to ≈25-30 lines.
S2 — Strip leftovers around the new code (~8 lines)
helios/src/scheduler/tests.rs:1016-1026: a five-line tuple destructure plus a three-line comment that restates the two assertions that follow it (1027-1031). Inlinefirst_request.shared_pages.len() + first_request.private_pages.len() + second_request.private_pages.len()instead, and delete the comment. Keepassert!(!first_request.shared_pages.is_empty())at1013— without it the count assertions would still pass on an empty shared set and the test would stop testing sharing.docs/api.md:302-307: two sentences of internals no other gauge in this file documents — "Neither gauge counts pages draining after a request retires, or a restore ticket's in-flight pages" and the publication-cadence sentence. Compare the free/cached/total page fields atdocs/api.md:350-352: one line each, no cadence, no transient states. Keep the definition (298-301), theflare_cached_kv_pagesoverlap note (301-302) and the ratio.helios/src/server/runtime.rs:2443-2445: a three-line comment for a one-field struct override (after S1). One line — "Decode moves the page count without moving cache resources." — says the same thing.
S3 — direct_request_pins and its guard (~6-7 lines net), the alternative to SF2
Only consumer is the guard at cache.rs:547-549. Delete the doc+field (82-83), initialiser (461), increment (531), guard (547-549), decrement (556) and fixture copy (cache/lifecycle_tests.rs:77), and add SF2's one-line assertion → net ≈−6. Nothing is lost for a release made on an unpinned checkpoint: direct_pins == 0 is already checked at cache.rs:550-552, and direct_request_pins <= direct_pins by construction. It trades a cache-side caller check for a scheduler invariant no type enforces, so prefer SF2's assertion unless a maintainer judges the guard itself unnecessary (AGENTS.md:182-186 (not opened) cautions against removing validation).
S4 — Redundant debug_assert! (1 line)
cache.rs:562: debug_assert!(node.request_pins > 0); before node.request_pins -= 1; on a u64. Debug builds enable overflow checks (no overflow-checks = false in the root or helios Cargo.toml (not opened)), so an underflow already panics, and the drift assertion (cache.rs:826-846) catches the same drift on every stats() read. Delete. Goes with S3 if that is taken.
Do not cut (checked, load-bearing)
Checkpoint::request_pins (cache.rs:84-85, 461, 537-540) and PrefixCheckpointCache::request_pinned_pages (cache.rs:222-224, 253, 539, 565, 851, surfaced at 189) with the #[cfg(test)] drift assertion (cache.rs:826-846) — this is precisely what keeps Cache::stats scan-free. The compaction agreement assert (cache.rs:635-636). pin_with/unpin_with (cache.rs:519-589) — already the short shape, four thin wrappers. The per-slot stats loop (scheduler.rs:1202-1209) — it already existed to count active_requests. The retry-key zeroing (runtime.rs:2441-2450) — required, since CopyoutResources derives PartialEq over the whole SchedulerStats (runtime.rs:1053-1059) and is compared at 2455. The retired-pin release moved before request.take() (scheduler.rs:3142-3150) — a real ordering requirement. flare_request_kv_pages itself (metrics.rs:265, 517, 1309-1313, 1790, 1835) — the maintainer request.
Nits (6)
SchedulerStats::statswalks the slot array four times.scheduler.rs:1205-1209(the new loop) plus1213(retiring_slots),1216(anchor guards),1222-1233(inbound waiting), on every progressing pass (runtime.rs:1148-1153), at startup (722) and after the shutdown drain (745). Folding all four into the onefilter_maploop (retiring += slot.retiring as usize;outside theif let) removes three passes and ~14 lines.pin_with/unpin_withlook the same node up twice.cache.rs:529-532and554-557(self.nodes.get_mut(&id).unwrap()twice), and547/550callself.checkpoint(id)?twice. Oneget_mutper function and one counter read for both guards saves ~4 lines and two hashes per pin and per release. Caveat:chain()starts atid(cache.rs:312-321), so the direct counters must stay out of the ancestor loop.retirere-reads values it already bound.scheduler.rs:3144-3145re-fetchesprefixanderror_codealthoughprefixis bound at3113anderror_coderead at3110, with nothing mutating in between (publish_with_retention,touch,record_publicationare all cache-side). Bindlet failed = request.error_code.is_some();beside3113and use it: four fewer slot lookups and one fewer shadowed binding.- "not yet written" is imprecise across the commit→completion window.
docs/api.md:304-305and the HELP text atmetrics.rs:1316.commitpops reservations intoprivate_pages(scheduler.rs:2432-2437) before the GPU writes complete, so a scrape can count a page inflare_request_kv_pageswhile the prose says such pages are "neither free, cached, nor written yet". Exact wording: "pages set aside for those requests' growth that no request holds a page for yet, and which are not counted inflare_cached_kv_pages." - The docs paragraph introduces
flare_reserved_kv_pagesbefore naming it.docs/api.md:298-302opens "flare_request_kv_pagescounts …" then says "Neither gauge counts …" at302, naming the second gauge only at304. One clause at298("Both gauges below are text only.") or moving the reserved definition first fixes it. Also related:docs/api.md:298says "requests owning a model slot" whilescheduler.rs:130andmetrics.rs:1311say "active requests" for the same set (self.slots.iter().filter_map(|slot| slot.request.as_ref()),scheduler.rs:1205) — adopting the api.md wording at the two code sites removes a reader question. - Coverage observation, no action requested: nothing drives
publish_boundary'sExisting { ready: true }re-pin (scheduler.rs:2990-2991) with astats()read — the path where a request swaps its parent's request pin for a checkpoint another request already pins (the "shared page counted once" case), and the path with the most pin-kind surface. TheCache::statsdrift assertion (cache.rs:826-846) would catch a double count; the cheapest future reach is a variant of the existing fixture, not a new test.
Considered and deliberately not requested
- A
docs/runtime-core-design.md(not opened) entry for the two gauges (the comparableflare_snapshot_backing_pagesnote is atdocs/runtime-core-design.md:873-877(not opened)) — would add prose for an exposition-only change already documented indocs/api.md. Subtraction first. - A dedicated
CopyoutResourceskey struct instead of the per-field zeroing atruntime.rs:2443-2450— the coupling is real (CopyoutResourcesembeds all ofSchedulerStats,runtime.rs:1053-1059) and every future gauge needs a second edit, but the fix changes which page movements re-offer copy-outs and needs its own justification. Current code is correct and commented. - Two rows for the new gauges in the
docs/api.mdfield table (330-360) — the table maps JSON fields to Prometheus names, and neither gauge appears in the JSON snapshot, so anone-style row would misrepresent the table's purpose; the prose paragraph and the292-296text-only sentence already route the reader. - A GPU benchmark or cost measurement — no performance claim is made beyond one counter update per page-count crossing, which matches
cache.rs:538-541/564-566plus the pre-existing slot loop. - The description's "Compaction moves the count into the surviving checkpoint." — loose wording (nothing arithmetic is moved:
cache.rs:622-641uncounts the ancestor, adds its tail pages back totail_pagesat626, and appends them to the heir at638-640; the count is unchanged because the heir already carried the samerequest_pins), but it agrees with the code comments at624-626and635and misleads nobody about behaviour. Not worth a prose edit against the deletion work. - The description's live-run bullets not naming the build combination — resolved by the 03:26 comment ("upstream main with this PR, #548, and #560 merged"); neither sibling touches KV-page accounting.
Open questions / what could not be verified
- No CI checks exist on
bca7358. The reported "809 passed; 1 failed (template test needingFLARE_TEST_TEMPLATE_DIR)" is taken on trust; the tests cited above were read and match their claims, but the suite was not run from this review environment. - The live scrapes are not reproducible from this branch (fork build plus two-GPU hardware). The in-repo evidence that is checkable is the test-only drift assertion (
cache.rs:826-846) pluscache/tests.rs:320-373andscheduler/tests.rs:970-1032. - Authorization rests on #537, a user-filed issue with numbers (
AGENTS.md:165-169(not opened)). Owners may still prefer #537's option 2 (splittingflare_cached_kv_pagesinto pinned/idle) or a ready-made ratio gauge; that is a product decision, and S1 gives the cheapest path if they prefer #537 literally. - Not verified here: any GPU workload beyond the author's scrapes, an exported core, the Windows build, the full helios suite, and whether #548 merges cleanly (different regions of
metrics.rs; #560'sSchedulerStatsadditions were checked and do not collide with the new fields). - Open judgement: whether SF2's
direct_request_pinsguard is worth keeping at all is a maintainer call — it can only fire on a doubleunpin_request, which would otherwise silently corruptrequest_pins. SF2 and S3 are the two answers; only a decision is missing, not code.
Link: https://github.com/NVIDIA/hyperflare-inference/pull/549 · Closes #537