#1 [high] PR #549 overview, scope, and what is verified-correct
PR #549 "Report KV pages held by active requests" (WynnD, draft, head 5ed7af8, +218/-10 across 7 files, closes #537; sibling PR is #548 which closes #536). Issue #537 asks for ONE gauge (flare_request_kv_pages = distinct KV pages referenced by active requests, vLLM kv_cache_usage_perc semantics) or a split of cached into pinned/idle, plus optionally a ratio gauge. #537 never mentions pages reserved for request growth.
Files: docs/api.md (+9), heilos/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).
Scope verdict (Architecture lens, agreed): in. Shared runtime layers only (cache accounting, SchedulerStats, Prometheus renderer, docs). No per-model branch, no flag, no env switch, no allocation/eviction/preemption policy change. Matches charter "smallest footprint in shared code" + AGENTS.md contribution-scope. Approach (maintain the count on pin/unpin so Cache::stats need not scan nodes) is the right one.
Verified-correct, do NOT re-flag:
- Request pin/unpin symmetry on every scheduler path: admission pin_request when inbound.is_none() (scheduler.rs:1643-1649) with mirrored unpin_request in both rollback arms (1657-1664, 1682-1690); ticket waiters pin_request (1900) before prefix=Some(id); boundary publication Created (2971-2974) and Existing (2991-2992) pin_request before unpin_request(parent); retirement unpin_request (3159); ticket-parent pins that belong to host admission keep plain pin/unpin (1638-1642, 1881-1883, 1917-1919); copy-out/export use pin_checkpoint/unpin_checkpoint (2038-2044).
- Counter cannot drift: pin_request/unpin_request adjust request_pinned_pages only at the 0<->1 transition of node.request_pins (cache.rs:551-580), matching the #[cfg(test)] full-scan assertion in Cache::stats (cache.rs:817-837). Compaction invariant holds: node.direct_pins==0 and request_pins==child.request_pins (cache.rs:613-631, debug_asserts at 623-627), so pages moving into the heir leave the total unchanged. retire_leaf/cancel_publication require pins==0, so no counted node leaves
nodes(cache.rs:594-663). - Gauges are additive, rendered inside the existing gauge array (metrics.rs:1309-1318) and stored in the existing bulk table (metrics.rs:514-518); deliberately absent from the JSON Snapshot; disjoint region of metrics.rs from PR #548, merges either order.
- No duplicated pre-existing helper: nothing in the tree computed "pages held by live requests".
- Prose scheme is complete (why / what / result / evidence), Discord line present and last, unrun Windows build + full suite disclosed, live numbers scoped to one instance with "no comparison claimed".
#2 [high] BLOCKER: new gauges leak into the copy-out retry key (CopyoutResources)
Where: helios/src/scheduler.rs:112-149 (SchedulerStats derives Clone, Copy, PartialEq, Eq; new fields request_pages/reserved_pages at 130-133) + helios/src/server/runtime.rs:1053-1059 (CopyoutResources embeds scheduler: crate::scheduler::SchedulerStats whole) + runtime.rs:2441-2449 (resources built each service_store call; retry_copyouts = retry || progress || self.copyout_resources != Some(resources); result decides whether entries in deferred_copyouts, filled at 2462-2470, are re-offered to store.store).
Verified mechanism: commit (scheduler.rs:2433-2438) pops pages out of request.reserved_pages into request.private_pages; free_pages was already reduced earlier at refill_reservations (scheduler.rs:1383-1425), and cached_pages/completed/retiring_slots do not move at that instant. So on each page-boundary crossing request_pages +1 and reserved_pages -1 with no cache-resource movement, which flips the CopyoutResources equality and re-offers deferred copy-outs. Same class of trigger on retire (scheduler.rs:3143 + 3170-3183 drop private+reserved into retired while free_pages is unchanged).
Why it matters: the PR body claims "No allocation, eviction, or scheduling decision changes". Copy-out re-offer timing IS such a decision, and the headroom-deferral mechanism (three phase tests: runtime/phase_tests.rs:6357-6384, 6387-6404, 6407-6431) degrades to "retry whenever a live request crosses a page boundary". Magnitude is bounded (no counter inflation: copyout_headroom_deferrals is guarded by !deferred_copyouts.contains(&id) at 2465-2468; the re-deferral is silent), but the coupling is accidental: an observability struct drives a control decision.
Fix, smallest first: build the key without the live-request gauges, e.g. let mut scheduler = self.scheduler.stats(); scheduler.request_pages = 0; scheduler.reserved_pages = 0; before CopyoutResources { scheduler, .. } with a one-line comment, or name the subset of SchedulerStats fields the key needs (completed fence, free/retiring/cached pages, snapshot backing, retiring slots, exports, next admission). Alternative if the author prefers keeping it: say in the description that copy-out retry cadence changes.
#3 [high] SHOULD FIX: docs/api.md gauge paragraph is inaccurate in two places
Doc sentence (docs/api.md:302-303): "Both are gauges read from scheduler state on each scrape." FALSE. Verified: Metrics::render renders the gauge array (metrics.rs:1309-1318) and emits value.load(Ordering::Relaxed) (metrics.rs:1390-1396); render never calls RequestScheduler::stats(). The atomics are stored only by Metrics::scheduler(stats) from the worker: runtime.rs:1148-1149 (if progress { self.metrics.scheduler(self.scheduler.stats()); }), once at worker start runtime.rs:722, once after shutdown runtime.rs:745. So a scrape reports the last published snapshot; with an idle worker the value is arbitrarily stale — exactly when an operator watches request pages fall to zero. Fix (smallest): delete the sentence.
Second doc defect, same paragraph (docs/api.md:298-305): the ratio sentence "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" is wrong/incomplete three ways, all verified:
(a) reserved pages (flare_reserved_kv_pages, defined one sentence earlier at 301-302) are also outside the numerator and disjoint (scheduler.rs:1216-1228 sums request and reserved separately). #537 asks for vLLM kv_cache_usage_perc parity, so the reader needs request+reserved; live numbers show reserved is small (3 and 2 vs 399/402 pages) but it is the stated second gauge of the PR.
(b) pinned tail pages are counted in BOTH gauges: request_pinned_pages adds node.tail_pages of checkpoints with request_pins>0 (cache.rs:551-561, 575-577) and those checkpoints are still in nodes, so count/uncount still adds their tail_pages to cached_pages (cache.rs:257-275, exposed as flare_cached_kv_pages at metrics.rs:1304-1308). "idle cached prefixes ... outside" invites reading free+cached+request as a partition. Must say request is not disjoint from cached.
(c) pages held by requests that no longer own a slot are in neither gauge: retire takes the request out of the slot at scheduler.rs:3143 and pushes private+reserved pages into self.retired (3170-3183); they return to free_pages only at advance_retirement (3037) after the GPU fence. Also pages of a host-store restore in flight sit in the Ticket (scheduler.rs:1704-1723), not in the request, so neither gauge counts them although inbound_waiting is documented as active (scheduler.rs:137-138). "live requests"/"active requests" overclaims.
#4 [high] SHOULD FIX + SUBTRACT: duplicate chain walk in pin_request/unpin_request, and wrong doc comment
cache.rs:548-580. pin_request calls self.pin(id)? (which computes self.chain(id)? at 523 and walks it at 530-532) and then calls self.chain(id)? AGAIN at 554; unpin_request does the same (self.unpin at 569 → chain at 540, then chain at 571). So two chain walks and two Vec allocations per request pin/unpin, plus a duplicated guard suite (ready check, u64::MAX saturation, direct_pins guard) that must stay in step. Call sites are hot-ish: admission scheduler.rs:1645, ticket waiters 1900, both boundary publications 2971/2991, retirement 3159 and the two rollback arms 1660/1686.
Fix: one private worker fn pin_with(&mut self, id, request: bool) computing chain once and doing both counter sets in the same loop; pin/pin_request become one-line wrappers; mirror for unpin. Net ~25 lines removed, one traversal removed, and the 0<->1 transition (where request_pinned_pages moves) gets a single site, which is also the right place for a debug assert on the usize subtraction at 576.
Agreement: Conventions SF1 and Simplicity SF1 independently, Simplicity supplied a concrete rewrite. Only detector of a drift today is the test-only full-scan assertion cache.rs:817-837 (plus debug_assert at 627), i.e. no release-build detector.
Doc comment on the same method, cache.rs:548-550: "Request pins also track the pages the request keeps referenced: its private pages plus the pinned ancestors' pages, each page counted once." The cache never sees private pages; request_pinned_pages only ever moves from node.tail_pages.len() at the 0<->1 transitions. Private pages are added by the scheduler separately (scheduler.rs:1216-1222) and only surface as SchedulerStats::request_pages. Fix: state the cache's half and point at the scheduler (1-2 lines instead of 3).
#5 [high] SHOULD FIX list (docs, pin-kind duplication, retire ordering, doc comment)
Verified in code, ranked.
SF-A (SS1, docs/api.md:302-303): delete "Both are gauges read from scheduler state on each scrape." False (see entry 3). Smallest fix is deletion, not rewording.
SF-B (docs/api.md:303-305 + evidence): rewrite the ratio sentence. Three omissions/corrections, all verified in code:
- reserved pages are outside the numerator and disjoint (scheduler.rs:1216-1228);
- request-pinned tail pages are ALSO in flare_cached_kv_pages because the checkpoint stays in
nodes(cache.rs:257-275, 551-561; metrics.rs:1304-1308) → say request is not disjoint from cached, do not let free+cached+request read as a partition; - pages of a request that no longer owns a slot (retire → self.retired, scheduler.rs:3143, 3170-3183, returned to free_pages only at 3037) and pages held by an in-flight host restore ticket (scheduler.rs:1704-1723) are in neither gauge, even though inbound_waiting counts those requests as active (scheduler.rs:137-138).
Evidence: the description's
request + reserved < total - free - cachedis not a bound on the gauge (total-free-cached is dominated by snapshot_backing_pages, metrics.rs:1294-1298); cite the in-repo drift assertion instead (cache.rs:817-837).
SF-C (scheduler.rs:1643-1649, 1657-1664, 1682-1690): the same if inbound.is_none() { pin_request } else { pin } conditional is written three times; inbound is immutable for the whole function so all three are deterministically the same branch. Repo precedent for deciding once: pin_checkpoint/unpin_checkpoint (scheduler.rs:2038-2044). Smallest fix: bind (id, request_pin: bool) once at the pinned binding (1638-1642) and use it at the three sites (a local closure or a two-variant enum + pin_as/unpin_as). Note the branch itself is load-bearing (Subtractive lens): the ticket-parent pin must exist before ensure_resources evicts, so do NOT collapse the three to pin_request — only deduplicate the choice.
SF-D (scheduler.rs:3143 vs 3155-3159): retire takes the request out of the slot at 3143 and only later calls self.cache.unpin_request(prefix)?; if that ever returns Err (cache.rs:565-568) the slot has no request, the prefix pin leaks forever and the request value is silently dropped. Not reachable today (symmetry verified) but the new error path makes an unpair bug worse than before. Fix: release the pin before request.take(), or debug_assert! at the release site instead of propagating.
SF-E (cache.rs:548-550): doc comment says request pins track "its private pages plus the pinned ancestors' pages" — the cache never sees private pages. Rewrite to state the cache half only (tail pages of chain checkpoints) and note the scheduler adds private pages.
Nit list (see separate entry).
#6 [high] SUBTRACT / SIMPLIFY: ~90-105 of +218 added lines removable in 4 places
SUBTRACT / SIMPLIFY — reconciled estimate: ~90-105 of the +218 added lines (~40-45%) removable in 4 places. Nothing in the diff adds a parallel mechanism (gauges reuse the existing gauge array, update table, and expected-exposition test rows; no second representation).
S-1 (~55 lines, biggest win): helios/src/scheduler/tests.rs:970-1034 request_kv_pages_count_shared_prefix_pages_once (+66) re-runs, line for line, the scenario of branching_requests_own_distinct_tail_pages_and_terminal_snapshots immediately below it (1036-1081): same scheduler(2,8,5), same admit(spec(64,1))/init/plan/commit Fence(2)/complete/freeze/finish, same two admit(spec(65,4)), init, Fence(5), complete, retain_prompt(6), Prefill second lane, Fence(7), complete — and that existing test already asserts the two requests share shared_pages (1078). Only the stats assertions + double cancel are new. Append ~8-10 assertion lines to the existing test (keep assert!(!first_request.shared_pages.is_empty()) and keep the handles rather than shadowing them at 1076-1077) and delete the new test. Coverage of shared-counted-once, reserved sum, and retire-drains-to-zero is preserved.
S-2 (~25 lines + one traversal): fold pin_request/unpin_request into one private worker (entry 4). Conventions SF1 and Simplicity SF1 agree; Simplicity supplied the concrete rewrite; keeps the drift assertion and request_pinned_pages semantics intact.
S-3 (~10 lines): helios/src/cache/tests.rs:322-328 copies the fixture of branching_pins_ancestors_and_prevents_direct_ancestor_unpin (346-352) verbatim. Fold the request-pin assertions into that existing test (after its pin(left_id)/pin(right_id) at 355-356) and drop the duplicated preamble. Drop cache/tests.rs:335 (unpin_request(parent).is_err()) — it only re-tests the direct-pin guard already covered by tests.rs:358 for the plain API, and parent has no direct request pin so it is not evidence about shared-page accounting.
S-4 (~22-25 lines, conditional): flare_reserved_kv_pages is a second gauge #537 never asked for (#537 asks for flare_request_kv_pages or a cached pinned/idle split). Its only consumers are metrics.rs:266/518/1314-1318 and the two test rows; it is absent from the JSON snapshot, so no dashboard reads it. Removal set: scheduler.rs:132-133 fields, scheduler.rs:1223-1228 sum, metrics.rs:266/518/1314-1318/1791/1836, docs/api.md:301-302 + the reserved wording at 304-305. Keep it only if the doc states the ratio as (request+reserved)/total, since vLLM counts reserved blocks as used; otherwise land request_kv_pages alone against #537.
Deliberately NOT removable (checked): Checkpoint::request_pins; PrefixCheckpointCache::request_pinned_pages + its 0<->1 brackets (this is what lets stats avoid scanning nodes); the compaction debug_assert (cache.rs:626-627); the extended #[cfg(test)] drift assertion (cache.rs:817-837, highest test value per line in the change); the CacheStats field; the request_pages sum in scheduler stats (this IS the requested number); the gauge atomic/store/render triple + 2 table rows; docs/api.md:298-300.
Also checked: direct_request_pins (cache.rs:82-83) is NOT safe to remove — a checkpoint can be pinned both by a request and for host-store copy-out (pin_checkpoint, scheduler.rs:2038-2044), so without the direct counter a duplicated request unpin would silently drive request_pins below its true value; the guard at cache.rs:565-568 is the only release-build detector. Simplicity lens reached the same conclusion. Subtractive lens offered it as an optional nit; do not press it.
#8 [high] Editorial reconciliation across the five lenses + verdict
Decisions made as editor across lenses (Rule 1 subtraction first, Rule 3 blocker discipline):
Took these from Architecture: SF on the false scrape-freshness sentence (smallest fix = delete), SF on the ratio paragraph (reserved / overlap / draining), nit on the three pin-kind copies, nit on the doc comment. Dropped Architecture's "smallest-footprint alternative deserved a sentence" (Nit 3: deriving pages from live slots) → handled as: the cache must own the count, so no code change; a sentence of PR rationale is optional, not a finding. Dropped "wrong cross-reference #536" from blockers (Rule 3) → folded into the single description bullet as a nit.
Took from Conventions: SF1 (fold pin_request/unpin_request) = S-2; SF2 (three copies of the pin branch) = SF. Dropped the docs/runtime-core-design.md entry request (would add docs; Rule 1) → optional nit N-3.
Took from Simplicity: its concrete pin_kind rewrite (used verbatim in the full report as the suggested shape), the three-scan fold nit, the cache.rs:548-550 doc-comment SF, the cache/tests.rs:335 nit (folded into S-3), the api.md duplication nit. Simplicity's keep-list saved direct_request_pins from deletion — I adopted that and explicitly rejected Subtractive's optional removal, because a checkpoint can be pinned both by a request and for copy-out (scheduler.rs:2038-2044), so the guard at cache.rs:565-568 is the only release-build detector of a mismatched release.
Took from Correctness: the CopyoutResources finding (raised to the single Blocker), the "live requests" overclaim during retirement drain (folded into the docs SF), the retire-ordering SF. Rejected Correctness nit 4's "add a test for the Existing branch" as a request for new code → folded into S-1 as the cheaper coverage.
Took from Subtractive: S-1 (55-line duplicate scheduler test — the single biggest win), S-3 (duplicate cache fixture), S-4 (reserved gauge, conditional on the ratio question), and its keep-list. Rejected its optional direct_request_pins deletion (see above). Its estimate ~95-105 lines reconciled to ~90-105 (S-2 ~25 not ~30, S-1 ~55, S-3 ~10, S-4 ~22-25 conditional).
Took from Prose: description's shared-ancestor sentence (contradicts code and its own test — request_pinned_pages adds tail pages once at the 0->1 transition, cache.rs:551-561; the test asserts 3 not 4), the zero-pins sentence, and the JSON-only nit.
Verdict: not ready to merge — 1 blocker (3-line fix or a disclosure), then 5 should-fix, ~90-105 lines removable, 5 nits. Scope and approach are right; the author should fold code, not add it.
#9 [high] FULL REPORT — PR #549 Blockers / Should Fix / Subtract / Nits
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 renderer/update-table/test rows, and there is no flag, branch, or second representation. One blocker that costs three lines, five should-fix items (three of them prose accuracy), and about 90 removable lines.
Blockers
B1. The new gauges are part of the key that decides whether deferred host copy-outs are re-offered.
SchedulerStats derives PartialEq and is embedded whole in CopyoutResources (helios/src/server/runtime.rs:1053-1059); service_store rebuilds it every pass and compares (runtime.rs:2441-2449) to set retry_copyouts, which decides whether ids parked in deferred_copyouts (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. Both move without any cache-resource movement: commit pops pages from request.reserved_pages into request.private_pages (scheduler.rs:2433-2438) while free_pages was already reduced by refill_reservations (1383-1425), so every page-boundary crossing shifts request_pages +1 / reserved_pages −1; retire empties both into self.retired (3143, 3170-3183) while free_pages waits for the fence (3037).
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: the description claims "No allocation, eviction, or scheduling decision changes", and copy-out re-offer timing is such a decision. The effect is bounded (extra export_fits attempts when headroom has not returned; copyout_headroom_deferrals cannot inflate because of the contains guard at 2465-2468), but an observability struct should not drive a control decision — and the claim is what an operator and the next reviewer will rely on.
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 (metrics.rs:1309-1318, value.load(Ordering::Relaxed) at 1394-1396) and never calls RequestScheduler::stats. The atomics are stored by the worker (runtime.rs:1148-1149, plus start 722 and post-shutdown 745). With an idle or stopped worker the scrape reports an arbitrarily stale value — exactly the case where someone watches request pages fall to zero.
Change: delete the sentence (smallest fix; the gauge contract is already established at api.md:287-296 and by every page row of the table).
S2. docs/api.md:303-305: the ratio paragraph is wrong in three ways.
"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-1228), and #537 asks for vLLM
kv_cache_usage_percparity, which counts blocks already allocated to running requests — so say thatrequest + 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). Do not let the wording implyfree + cached + requestis a partition; - "live requests" overclaims: a retiring request's pages sit in
self.retireduntil the fence (scheduler.rs:3143, 3170-3183, 3037) and an in-flight host restore's pages sit in the ticket (1704-1723), yetinbound_waitingdocuments those requests as active (137-138). Say "requests still owning a slot" or name both exclusions. Change: one rewritten sentence pair. Drop "helpful" additions; the paragraph already has the definition it needs. Also: the description's live checkrequest + reserved < total − free − cacheddoes not validate this gauge (total − free − cachedis dominated by snapshot-backing pages, metrics.rs:1294-1298). The in-repo evidence is stronger and already exists: the#[cfg(test)]drift assertion inCache::statscomparingrequest_pinned_pageswith a full scan on every stats read (cache.rs:817-837). 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).
Change: carry the choice in the binding that already exists (pinned, 1638-1642) — 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 all three to pin_request.
S4. scheduler.rs:3143 vs 3155-3159: retire can now fail after it has already emptied the slot.
request.take() runs before self.cache.unpin_request(prefix)?; if that ever returned Err (cache.rs:565-568) the slot would hold no request, the retirement would not be recorded, and the prefix pin would leak for the life of the process. Not reachable today — the pin/release symmetry is intact on every path — 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" — request_pinned_pages only ever moves from node.tail_pages.len() at the 0↔1 transitions; 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.
Subtract / Simplify
Could remove ~90 of +218 added lines without changing behaviour (up to ~112 if flare_reserved_kv_pages also goes).
- ~55 lines —
scheduler/tests.rs:970-1034repeats an existing test's whole scenario.request_kv_pages_count_shared_prefix_pages_oncereproducesbranching_requests_own_distinct_tail_pages_and_terminal_snapshots(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(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 at 1076-1077) and delete the new test. This also gives the merged test coverage of the retirement-drain path it does not have 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 at 523 and walks 530-532,unpinat 540), 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 exists in two places that must agree. One privatefn pin_with(&mut self, id, request: bool)with both counter sets in 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_asserton theusizesubtraction at 576. - ~10 lines —
cache/tests.rs:322-328copies the fixture ofbranching_pins_ancestors_and_prevents_direct_ancestor_unpin(346-352) verbatim. Fold the request-pin assertions into that test after itspin(left_id)/pin(right_id)at 355-356. In the same pass, dropcache/tests.rs:335(unpin_request(parent).is_err()): it re-tests the direct-pin guard already covered at 358 for the plain API, andparentholds no direct request pin, so it is not evidence about the shared-page accounting the test is named for. - ~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; nothing there mentions reserved growth. If the ratio paragraph (S2) namesrequest + reserved, the gauge earns its place and should stay — then this item is withdrawn. If the author does not intend it in the ratio, delete it in one pass: scheduler.rs:132-133, 1223-1228; metrics.rs:266, 518, 1314-1318, 1791, 1836; docs/api.md:301-302 and the reserved clause at 304-305. Nothing else reads it (it is deliberately absent from the JSON snapshot).
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 drift assertion (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 565-568 is the only release-build detector of a mismatched release.
Nits
scheduler.rs:1203-1228: three passes overself.slotswhere one fold gives both new fields; a fold also makes them read as the pair the docs describe. No behaviour change.cache.rs:626: "Both nodes are counted or neither is…" — "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: the paragraph partly restates the HELP text (metrics.rs:1310-1317). Keep one home; if a JSON note is wanted, one clause ("Neither appears in the JSON snapshot") suffices.- 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. The merged test from S-1 is the cheapest place to reach it; no new test needed. - Description-only, fold into one bullet: "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 at 627 permits nonzero pins carried into the heir) — say that folding an ancestor into its heir loses no request pin; and the sibling PR is #548, not #536 (#536 is the issue #548 closes).
Not findings: the third-party fork base 5ffe4d54 and the absent CI on 5ed7af8 are disclosed honestly in the description; the unrun Windows build and full suite are named. Scope is inside the charter, Cache::stats' no-scan property is preserved, and the metrics.rs regions touched are disjoint from #548, so the two merge in either order.
#10 [high] SUMMARY REPORT — the GitHub post
Summary report (the GitHub post body)
Recommendation: Changes Requested
The scope and the approach are right — the count is maintained as pins change so Cache::stats keeps its no-scan-nodes property, and the gauges reuse the existing renderer, update table, and test rows. One three-line blocker, then five should-fix items and about 90 removable lines. Nothing below asks for new code.
Blockers
- The new gauges leaked into the copy-out retry key.
SchedulerStatsderivesPartialEqand is embedded whole inCopyoutResources(runtime.rs:1053-1059, compared at 2441-2449), sorequest_pages/reserved_pagesnow change when a request crosses a page boundary (commit, scheduler.rs:2433-2438) and re-offer deferred host copy-outs with no cache-resource movement. Fix: zero the two fields when building the key (let mut s = self.scheduler.stats(); s.request_pages = 0; s.reserved_pages = 0;), or say in the description that retry cadence changes.
Should fix
docs/api.md:302-303: delete "Both are gauges read from scheduler state on each scrape" — the scrape only loads atomics (metrics.rs:1394-1396); the worker publishes them (runtime.rs:1148-1149).docs/api.md:303-305: the ratio sentence needs one rewrite: reserved pages are outside the numerator and disjoint; request-pinned tail pages are counted in both gauges (the checkpoint stays innodes, cache.rs:551-561, 257-275); and "live requests" excludes pages draining throughself.retired(scheduler.rs:3143, 3170-3183) and an in-flight restore ticket (1704-1723). Also prefer the in-repo drift assertion (cache.rs:817-837) as evidence overrequest + reserved < total − free − cached, which is dominated by snapshot-backing pages.scheduler.rs:1643-1649, 1657-1664, 1682-1690: the sameif inbound.is_none()pin-kind conditional three times; carry the choice once in thepinnedbinding (1638-1642) — the branch must stay, the repetition need not.scheduler.rs:3143 vs 3155-3159:retirecan fail afterrequest.take(); release the pin first (ordebug_assert!), so a future unpair bug is not a silent pin leak.cache.rs:548-550: the doc comment says request pins track "its private pages" — the cache never sees them (they are added in scheduler.rs:1216-1222). One line on the cache's half, pointing at the consumer.
Subtract / Simplify
Could remove ~90 of +218 added lines (up to ~112 if flare_reserved_kv_pages goes):
- ~55 —
scheduler/tests.rs:970-1034repeatsbranching_requests_own_distinct_tail_pages_and_terminal_snapshots(1036-1081) step for step. Append the ~10stats/cancelassertions to that test and delete this one. - ~25 — fold
pin_request/unpin_requestintopin/unpin: they walkchain(id)twice per call (cache.rs:551-563, 565-580) on the admission, ticket-waiter, boundary-publication and retirement paths. One privatepin_with(id, request)with both counters in the existing loop keeps the drift assertion intact. - ~10 —
cache/tests.rs:322-328copies the fixture below verbatim; fold the request-pin assertions in, and drop:335, which re-tests the plain-pin guard already at:358. - ~22-25 (conditional) —
flare_reserved_kv_pagesis a gauge #537 did not ask for. Keep it only if the ratio paragraph namesrequest + reserved; otherwise delete scheduler.rs:132-133, 1223-1228, metrics.rs:266/518/1314-1318/1791/1836, docs/api.md:301-302 and the reserved clause.
Nits
5, one of them the description's "a checkpoint leaves nodes only at zero pins" (compaction removes ancestors carrying pins into the heir) and the #536/#548 mix-up; the rest are a three-scan fold in stats(), one comment, one paragraph to keep in one place, and optional coverage of the Existing publication branch that the merged test in S-1 would reach for free.
#11 [high] Research summary
Reviewed PR #549 against all five lens reports, re-verified every contested claim in the code, reconciled them (subtraction first), and wrote both deliverables into the scratchpad: entry 9 is the full report, entry 10 is the summary post body; entries 1-8 hold the evidence and the reconciliation decisions.
Verdict: Changes Requested — not ready to merge, but the scope and approach are right (charter-compliant: shared runtime layers only, no flag/branch/model special case, and Cache::stats keeps its no-scan-nodes property). One three-line blocker, five should-fix items (three of them prose accuracy), ~90 removable lines, 5 nits.
The single blocker: SchedulerStats derives PartialEq and is embedded whole in CopyoutResources (runtime.rs:1053-1059, compared at 2441-2449), so the two new fields now change the host copy-out re-offer decision whenever a request crosses a page boundary via commit (scheduler.rs:2433-2438) — contradicting the PR's "no scheduling decision changes". Fix is three lines: zero the two gauges when building the key.
Key editorial calls: I accepted Simplicity's finding that direct_request_pins must stay (it is the only release-build detector when a checkpoint is pinned both by a request and for copy-out), overruling Subtractive's optional deletion of it. I demoted the false scrape-freshness sentence and the wrong ratio paragraph to Should Fix with deletion/rewrite as the fix rather than expanded prose, and folded the description's factual errors (zero-pins sentence, #536/#548 mix-up, shared-ancestor contradiction) into a single nit bullet. The largest subtraction is a new 66-line scheduler test that re-runs an existing test's scenario step for step.
#12 [high] Concrete fix snippets for each requested change (so the author can apply them directly)
Concrete patch sketches so the author can apply each item in minutes. All line numbers are at head 5ed7af8.
B1 fix (runtime.rs:2441-2449) — keep live gauges out of the copy-out retry key: let mut scheduler = self.scheduler.stats(); scheduler.request_pages = 0; // live-request gauges must not re-offer deferred copy-outs scheduler.reserved_pages = 0; let resources = CopyoutResources { completed: self.scheduler.completed(), scheduler, exports: self.exports.len(), next: next_admission(&self.scheduler, &self.parked, &self.pending) .map(|next| (next.prompt_tokens, next.max_new_tokens, next.growable)), };
S1 fix (docs/api.md:302-303): delete the sentence "Both are gauges read from scheduler state on each scrape." If a freshness note is wanted at all, it belongs in one clause: "Both are published by the serving worker as scheduling advances, so a scrape reports the most recently published value."
S2 fix (docs/api.md:298-305) — suggested replacement paragraph (same length, no additions):
flare_request_kv_pages counts the KV pages held by requests that own a model
slot: their private pages plus the tail pages of the checkpoints they pin, each
page counted once however many requests pin checkpoints below it. It is not a
partition alongside flare_cached_kv_pages: a pinned checkpoint stays published,
so its tail pages count in both. Pages still draining after a request retires, and
pages held by a host restore still in flight, are counted in neither gauge.
flare_reserved_kv_pages counts pages reserved for those requests' growth that
are neither free, cached, nor written yet. Dividing the sum of both by
flare_total_kv_pages gives the share comparable to vLLM's kv_cache_usage_perc;
idle cached prefixes and snapshot backing pages are outside it.
S3 fix (scheduler.rs:1638-1690) — decide the pin kind once, at the binding that already exists, then never branch again:
let pin = pinned.map(|id| (id, inbound.is_none())); // (id, request_pin)
if let Some((id, request)) = pin {
if request { self.cache.pin_request(id)?; } else { self.cache.pin(id)?; }
}
// both rollback arms reuse pin:
let release = |cache: &mut PrefixCheckpointCache, (id, request): (CheckpointId, bool)| -> Result<()> {
if request { cache.unpin_request(id) } else { cache.unpin(id) }
};
Either a local closure like that, or a PinKind enum with pin_as/unpin_as on the scheduler, mirroring the existing pin_checkpoint/unpin_checkpoint (scheduler.rs:2038-2044). The branch must stay (the ticket-parent pin has to exist before ensure_resources evicts), only the repetition goes.
S4 fix (scheduler.rs:3143 vs 3155-3159) — release before the slot is emptied:
let prefix = self.request(handle)?.prefix; // read first
...
if let Some(prefix) = prefix {
if !publish || request.error_code.is_some() { self.record_publication(prefix); }
self.cache.unpin_request(prefix)?; // now before/outside the take()
}
Cheaper alternative: debug_assert! the release instead of propagating ?, matching how the cache checks its pin invariants.
S5 fix (cache.rs:548-550) — doc comment, 3 lines to 3 lines:
/// Pins a checkpoint on behalf of an active request, 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.
S-2 fix (cache.rs:519-580) — one worker, one chain walk; pin/unpin/pin_request/unpin_request become one-liners:
fn pin_with(&mut self, id: CheckpointId, request: bool) -> Result<()> {
if !self.checkpoint(id)?.ready { return Err("cannot pin a checkpoint before GPU readiness".into()); }
let chain = self.chain(id)?;
if self.nodes[&id].direct_pins == u64::MAX || chain.iter().any(|id| self.nodes[id].pins == u64::MAX) {
return Err("checkpoint reference count exhausted".into());
}
self.nodes.get_mut(&id).unwrap().direct_pins += 1;
if request { self.nodes.get_mut(&id).unwrap().direct_request_pins += 1; }
for ancestor in chain {
let node = self.nodes.get_mut(&ancestor).unwrap();
node.pins += 1;
if request {
node.request_pins += 1;
if node.request_pins == 1 { self.request_pinned_pages += node.tail_pages.len(); }
}
}
Ok(())
}
pub fn pin(&mut self, id: CheckpointId) -> Result<()> { self.pin_with(id, false) }
pub fn pin_request(&mut self, id: CheckpointId) -> Result<()> { self.pin_with(id, true) }
Mirror unpin_with(id, request), keeping the direct_request_pins == 0 guard for request == true and adding a debug_assert!(node.request_pins > 0) at the 1->0 transition (the usize subtraction at 576 is otherwise only guarded by an invariant).
#15 [high] FULL REPORT (round 2) — PR #549 at head 9cca87a
PR #549 — Report KV pages held by active requests
Reviewed at head 9cca87ac ("Keep page gauges out of the copy-out retry key"), 8 files, +246/−16, draft. Closes #537. Sibling metrics PR is #548 ("Add request latency histograms and process metrics"); #553 is the new per-request-metrics PR.
Verdict: Changes Requested — small. The previous round's blocker is fixed at this head, as are the retire-ordering defect and the wrong cache.rs doc comment. What remains is one API paragraph that contradicts itself, four mechanical accuracy defects in the PR description, and about 80 of the 246 added lines that can be deleted. Nothing below asks for new code, a new flag, a new test, or new documentation.
Key findings
- Scope and approach are right. Shared runtime layers only (cache accounting,
SchedulerStats, the Prometheus renderer,docs/api.md): no per-model branch, no policy flag, no allocation/eviction/preemption decision change. The count is maintained on the pin paths, soCache::statskeeps its no-scan-nodesproperty (cache.rs:816-837scans only under#[cfg(test)]), which matches the charter ("keep the runtime small and model-agnostic"; "look for the smallest footprint in shared code") andAGENTS.md:165-200. - The previously reported blocker is fixed and must not be re-raised.
runtime.rs:2441-2456now zeroesrequest_pages/reserved_pageswhen building theCopyoutResourceskey (runtime.rs:2446-2449, compared at2455), so page movement between reserved and private pages no longer re-offers deferred host copy-outs. Residual coupling only — see Nit 3. - Also fixed at this head:
retirereleases the request pin before emptying the slot (scheduler.rs:3149-3157);pin_request's doc comment now states the cache's half and points at the scheduler (cache.rs:548-550); the three mirroredif inbound.is_none()pin branches became one dispatcher (scheduler.rs:2025-2040). - Verified correct, do not re-flag: request pin/release symmetry on every path (admission
scheduler.rs:1645/1656/1678; ticket waiters1889; boundary publication2977/2979/2997/2998; retirement3155) with ticket-parent pins keeping the plain API (1871,1907);request_pinned_pagesmoving only at the 0↔1 transition ofrequest_pins(cache.rs:551-580); compaction carrying request pins into the heir (cache.rs:623-631, assert at627); eviction gated onpins == 0(cache.rs:658-663); gauges rendered inside the existing gauge array (metrics.rs:1309-1318), stored in the bulk table (metrics.rs:517-518), and absent from the JSONSnapshot; reserved pages genuinely "neither free, cached, nor written" (popped at admissionscheduler.rs:1721-1724, consumed into private at commit2439-2444); retirement drain and in-flight restore tickets outside both gauges (scheduler.rs:1887-1899,3177-3191). - Checked and deliberately not pressed: a
docs/runtime-core-design.mdentry for the two gauges (that is more prose, not less); a new test forpublish_boundary'sExistingbranch (cheapest coverage is the merged test in S-1 — Nit 5); deletion ofCheckpoint::direct_request_pins, of the retention offlare_reserved_kv_pages, and of the runtime zeroing block (all three have load-bearing reasons — see "Answered, not cut").
Blockers
None. Every lens at this head reports no blocking issue: correctness is clean, architecture found no blocking issue, and the prose has no blocking defect. Do not re-raise the copy-out retry key as a blocker — it is fixed at runtime.rs:2446-2449.
Should Fix
SF1. docs/api.md:307-312 — the paragraph defines two different ratios and invites the wrong reading of the exclusions
Current text:
Reserved pages are outside the request gauge, so
flare_request_kv_pages + flare_reserved_kv_pagesis the figure comparable to another runtime's used KV cache. Dividing either gauge byflare_total_kv_pagesexcludes idle cached prefixes and snapshot backing pages, and the test-only assertion inCache::statscompares the maintained request-pinned count with a full scan of every checkpoint on each read.
Three defects in five lines:
- Two incompatible ratios in adjacent sentences. 308 says the sum is the comparable figure; 309 says dividing either gauge gives the share. Both cannot be true, and by the author's own scrape (
flare_reserved_kv_pages3 and 2 of 21504)reserved/totalcarries no information. An operator cannot tell whether to plotrequest/totalor(request + reserved)/total— which is exactly the number #537 exists to make computable. - The exclusion is misattributed. "Dividing … by
flare_total_kv_pagesexcludes …" makes the division the cause; what is excluded is a property of the numerator. Combined with "idle cached prefixes" it also reads as ifcachedis excluded wholesale, contradictingdocs/api.md:303-306two lines above (pinned tail pages appear in both gauges). - A
#[cfg(test)]assertion in the operator-facing API page.helios/src/cache.rs:818-837is validation evidence; it belongs in the PR description, not a present-state specification (docs/design-review.mdprinciple 16;.agents/skills/repo-prose/SKILL.md:26-29).
Also in the same paragraph, docs/api.md:302-303 says the worker publishes "on every scheduler pass"; the worker stores only when a pass reports progress (runtime.rs:1148-1153), plus startup (runtime.rs:722) and the post-shutdown drain (runtime.rs:745).
Requested change — replace docs/api.md:298-312 with (net −2 lines, no new claims):
`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 an admission ticket's
in-flight restore. `flare_reserved_kv_pages` counts pages reserved for those
requests' growth that are neither free, cached, nor written yet. The worker
publishes both when a scheduler pass makes progress, and a scrape reads the last
published values. `(flare_request_kv_pages + flare_reserved_kv_pages)` over
`flare_total_kv_pages` is the share comparable to vLLM's `kv_cache_usage_perc`;
idle cached prefixes and snapshot backing pages are outside it.
One ratio, stated once; the exclusions stated as a property of the numerator; the test hook deleted (already in the PR body); "requests owning a model slot" instead of "active requests", which is what scheduler.rs:1216-1228 actually sums (inbound_waiting counts a restore ticket's request as active, yet its pages are in neither gauge).
Why it matters: this is the only prose in the repository that defines the ratio the new gauge exists to enable, and it is internally inconsistent. AGENTS.md:165-166 requires a contribution to leave documentation accurate; principle 16 requires prose a reviewer can reconstruct the argument from.
SF2. PR description — four mechanical accuracy defects, one edit
None of these break the change; all of them are what a reviewer or agent must guess today (AGENTS.md:88-102, 135-137).
- "What changed" omits
helios/src/server/runtime.rs. The head commit makes the deferred host copy-out retry key depend on aSchedulerStatswith the two new gauges zeroed (runtime.rs:2441-2456). That is a behavioural change in a file the description never names, and it is what makes "No allocation, eviction, or scheduling decision changes" true. Add a bullet: the deferred host copy-out key embedsSchedulerStatswhole (CopyoutResources,runtime.rs:1053-1059), so the two gauges are zeroed when the key is built because decode moves page counts without moving cache resources. - "A page shared through a pinned ancestor therefore counts once for every request that references it" is wrong and contradicts the PR's own test.
cache.rs:551-563adds a checkpoint's tail pages only on the 0→1 transition ofrequest_pins, so a shared page counts once in total.cache/tests.rs:320-342asserts 3, not 4, for a parent shared by two children. As written the sentence makes the reported live values (399/402 of 21504) look implausibly small. Say: a page in a shared ancestor's tail is counted once in the total, however many requests pin checkpoints below it; per-request totals add each request's private pages. - "a checkpoint leaves
nodesonly at zero pins" is false for compaction.compact_ancestorremoves the node atcache.rs:614with its pins still held and moves them into the heir (cache.rs:615-616,629-631; assert at627). Say: a leaf leavesnodesonly at zero pins; a compacted ancestor's request pins and pages move into its heir. - The live consistency check does not attest the gauge, and the measured ratio is not the one the docs define.
request + reserved < total − free − cachedholds becausetotal − free − cachedis dominated by snapshot-backing pages (metrics.rs:1294-1298); the in-repo invariant that does attest the counter is the drift assertion (cache.rs:818-837), optionally plusrequest_pinned_pages <= cached_pages. And the "ratio measured 0.0186 and 0.0187" isrequest/total, while the docs callrequest + reservedthe comparable figure — label it, so the two do not disagree.
Subtract / Simplify
About 80 of the 246 added lines can go without losing anything #537 asks for (~33%). Nothing in this change adds a parallel mechanism: the gauges reuse the existing gauge array, update table and expected-exposition rows, and no second representation of the count exists.
| # | Where | Lines saved |
|---|---|---|
| S-1 | helios/src/scheduler/tests.rs:970-1034 re-runs an existing test's entire scenario |
~50 |
| S-2 | helios/src/cache/tests.rs:320-342 copies the fixture below it verbatim |
~10 |
| S-3 | helios/src/cache.rs:519-580 — pin_request/unpin_request split pin/unpin's invariant and walk the chain twice |
~20 |
S-1 (~50 lines) — the new scheduler test is a copy of the test directly below it
request_kv_pages_count_shared_prefix_pages_once (scheduler/tests.rs:970-1034) repeats branching_requests_own_distinct_tail_pages_and_terminal_snapshots (1036-1081) step for step: same scheduler(2, 8, 5), same seed admit/init/plan/commit Fence(2)/complete/freeze(3)/finish, same two admit(spec(65, 4)), same Fence(5) completion, same retain_prompt(6), same prefill-lane assertion, same Fence(7) completion. Lines 972-1009 are identical to 1038-1075, and the existing test already asserts the two requests share shared_pages (1078) and differ in private pages (1079).
Only 1010-1033 is new evidence: the five lengths, the two stats assertions, the two cancels, and the (0, 0) / cached_pages > 0 checks.
Change: delete the test and append its new content to the existing one, keeping the handles instead of shadowing them at 1076-1077:
let (shared, private, reserved) = (
first.shared_pages.len(),
first.private_pages.len() + second.private_pages.len(),
first.reserved_pages.len() + second.reserved_pages.len(),
);
assert!(!shared_pages.is_empty());
let stats = scheduler.stats();
assert_eq!(stats.request_pages, shared + private);
assert_eq!(stats.reserved_pages, reserved);
scheduler.cancel(first.handle).unwrap();
scheduler.cancel(second.handle).unwrap();
let stats = scheduler.stats();
assert_eq!((stats.request_pages, stats.reserved_pages), (0, 0));
assert!(stats.cached_pages > 0);
Take the lengths into locals before the cancels (the borrow comes back for cancel); LiveRequest::handle is public (scheduler.rs:226). Every behaviour the new test proves survives — shared pages counted once, the reserved sum, and the retire-to-zero drain — on a fixture the suite already pays for (AGENTS.md:194-199).
S-2 (~10 lines) — the new cache test repeats the fixture below it
helios/src/cache/tests.rs:322-328 is character-identical to 346-352 in branching_pins_ancestors_and_prevents_direct_ancestor_unpin. Because pin_request calls pin first (cache.rs:552), the existing test can take its pins through pin_request/unpin_request and gain the request_pinned_pages assertions without losing its pin_count() checks. Also drop cache/tests.rs:335 (assert!(cache.unpin_request(parent).is_err())): it re-tests the "no direct pin" guard already covered for the plain API at :358, and parent holds no direct request pin, so it is not evidence for the shared-page accounting the test is named for.
Caveat: inserting request pins at :356 changes the pin counts the later eviction steps assert (357-386); place the fold after :372 or re-run that test and adjust the two pin_count() expectations.
S-3 (~20 lines) — pin_request/unpin_request duplicate pin/unpin's guards and walk the chain twice
pin (cache.rs:519-534) and unpin (536-546) each compute self.chain(id)? once and own their whole invariant inside that walk, including the refcount-exhaustion guard (524-528). pin_request calls self.pin(id)? and then chains again (552-554); unpin_request does the same (569-571). So every request pin and release pays two walks and two Vec allocations, and the "request_pins ⊆ pins" invariant lives in two function pairs that must stay in agreement, with the test-only drift assert (cache.rs:818-837) as the only detector.
Call sites are the hot paths: admission (scheduler.rs:1645), ticket waiters (1889), both boundary publications (2977, 2997), retirement (3155), and the two rollback arms (1656, 1678).
Change: one private worker, one walk, both counter sets; the public methods become one-liners (keeps the direct_request_pins == 0 guard and both error strings, so cache/tests.rs:329-340 stays meaningful):
fn pin_with(&mut self, id: CheckpointId, request: bool) -> Result<()> {
if !self.checkpoint(id)?.ready { return Err("cannot pin a checkpoint before GPU readiness".into()); }
let chain = self.chain(id)?;
if self.nodes[&id].direct_pins == u64::MAX
|| chain.iter().any(|id| self.nodes[id].pins == u64::MAX) {
return Err("checkpoint reference count exhausted".into());
}
self.nodes.get_mut(&id).unwrap().direct_pins += 1;
if request { self.nodes.get_mut(&id).unwrap().direct_request_pins += 1; }
for ancestor in chain {
let node = self.nodes.get_mut(&ancestor).unwrap();
node.pins += 1;
if request {
node.request_pins += 1;
if node.request_pins == 1 { self.request_pinned_pages += node.tail_pages.len(); }
}
}
Ok(())
}
pub fn pin(&mut self, id: CheckpointId) -> Result<()> { self.pin_with(id, false) }
pub fn pin_request(&mut self, id: CheckpointId) -> Result<()> { self.pin_with(id, true) }
Mirror unpin_with(id, request), keeping the direct_request_pins == 0 check for request == true and adding a debug_assert!(node.request_pins > 0) at the 1→0 transition (the usize subtraction at 576 is otherwise guarded only by an invariant). This also gives the 0↔1 transition — the only place request_pinned_pages moves — a single site.
Answered, not cut (so no agent re-proposes them)
flare_reserved_kv_pages(~22-25 lines) stays. Subtractive flagged it as scope the issue did not request; the docs'request + reservedcomparison with vLLM'skv_cache_usage_percis the justification, so the gauge earns its place once SF1 states that ratio. If the paragraph is instead reduced torequest/total(what #537 literally asks and what the description measured), the gauge becomes deletable in one pass:scheduler.rs:132-133,1223-1228;metrics.rs:266,518,1314-1318,1791,1836;docs/api.mdreserved clause, andruntime.rs:2448shrinks to one zeroing line. Do not press it while the ratio paragraph names the sum.Checkpoint::direct_request_pinsstays (cache.rs:82-83,461,553,566-568,570). A checkpoint can be pinned by both a request and for host-store copy-out (pin_checkpoint,scheduler.rs:2042-2050), so a duplicated request release would silently driverequest_pinsbelow its true value; the guard at566-568is the only release-build detector.- The runtime zeroing block stays (
runtime.rs:2443-2450) — it is what makes the head truthful. Its permanent removal is Nit 3. - Keep as-is:
PrefixCheckpointCache::request_pinned_pagesand its 0↔1 brackets (this is what keepsstatsoffnodes); the compaction assert (cache.rs:623-627); the extended drift assertion (818-837, highest test value per line in the change); therequest_pages/reserved_pagessums (scheduler.rs:1216-1228); the atomic/store/render triple;docs/api.md:298-300's definition. pin_prefix/unpin_prefix(scheduler.rs:2025-2040) stay. They are net +4 lines against the three inline branches they replaced and they encode the admission pin kind once. Deleting them would re-inline the dispatch at three sites; routing the four directcache.pin_requestcalls (1889,2977,2997,3155) through them is line-neutral, so neither is worth a change request. The residual "three entry points" complaint is Nit 6.
Nits
scheduler.rs:1203-1228:stats()now walksself.slotsthree times (active_requests1203-1207,private_pages1216-1222,reserved_pages1223-1228) on every progressing pass (runtime.rs:1148-1149). Onefoldseeded overslot.requestyields both new values and reads as the pair the docs describe. No behaviour change.scheduler.rs:3151-3152:retirecallsself.request(handle)?twice more than needed forprefixanderror_code; bind both once beside the existing locals at3120. Two fewer slot lookups, no behaviour change.runtime.rs:2441-2456:CopyoutResourcesstill embeds all ofSchedulerStats(1053-1059), so every future gauge joins the copy-out retry key by default and needs a second edit here. The zeroing is correct today; the smaller long-term shape is a key holding only the cache-side values copy-out depends on (free_pages,free_snapshots,cached_pages, snapshot backing, retiring slots). That changes which movements re-offer deferred copy-outs, so it needs its own justification — a note, not a request.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."- Coverage, free and optional: nothing exercises
publish_boundary'sExisting { ready: true }re-pin (scheduler.rs:2994-3006), the one place where a second request pins a checkpoint another request already pinned — where a double count or a missing pin would hide. The drift assertion would catch a cache-side error there, but no test reaches it. Cheapest reach is the merged fixture from S-1; do not add a new test. scheduler.rs:2025-2040: the pin kind travels as a barebool, sopin_prefix(id, request_pin)is boolean-blind at the call site and reads as a third way to take a request pin alongside the directcache.pin_requestcalls. With one dispatcher and three call sites the risk is low; if the API spreads, an enum or aRequestPinmarker turns an inverted argument into a compile error. Not worth changing now.
Process notes (not findings)
- The head has no reported CI run; the 508-test figure is taken on trust (the two named tests were read and match their claims).
- The live scrape numbers come from a validation tree built on fork commit
5ffe4d54(upstream PR #482 plus #536/#548), so they are not reproducible from this branch alone; the description discloses the instance, the contamination from this agent session, and "no comparison claimed" — that is honest. docs/api.mdgains no table rows for the two gauges; that is correct, because the table maps JSONSnapshotfields and the gauges are deliberately text-only (docs/api.md:332-355).
#16 [high] SUMMARY (round 2) — the GitHub post, counts only
Recommendation: Changes Requested
The previous blocker is fixed at 9cca87a — the two gauges are now zeroed in the copy-out retry key — as are the retire ordering and the wrong cache.rs doc comment. What remains is one self-contradictory API paragraph, four mechanical description fixes, and about 80 of the 246 added lines that can simply be deleted. No new code, tests, flags or docs are requested.
Blockers: 0 Should fix: 2 Subtractive suggestions: 3 Nits: 5
#17 [high] Line-savings arithmetic correction: ~75, not ~80
Correction to entry 15 (which says ~80 lines): recomputed from the actual line spans at head 9cca87a.
- S-1:
scheduler/tests.rs:970-1034is 65 lines; the new-only content is1010-1033(24 lines, of which ~13 are the assertions/cancels that must move). Delete 65, add ~20 → net ~45 lines. - S-2:
cache/tests.rs:320-342is 23 lines; ~8 assertion lines move into the test at 344-386 → net ~10 lines (plus:335). - S-3:
cache.rs:519-580—pin_with/unpin_withcollapse four methods into two workers plus four one-line wrappers → net ~20 lines, and one chain walk + oneVecallocation removed per request pin and per release.
Total: ~75 of +246 added lines (~30%). Use "about 75" in both deliverables; "up to ~100 if flare_reserved_kv_pages also goes" (~22-25 lines) holds only if SF1's ratio paragraph is reduced to request/total.
#18 [high] Final counts: 0 / 2 / 3 / 5
Final nit set is FIVE (entry 15 listed 6). Dropped the "bare bool / enum" nit: it asks for a change that adds a type, and the report already says pin_prefix/unpin_prefix should stay — inconsistent to request an enum for them.
Final counts, matching the deliverables exactly: Blockers 0 · Should fix 2 (SF1 docs/api.md:298-312; SF2 PR description) · Subtractive 3 (S-1 ~45, S-2 ~10, S-3 ~20 = ~75) · Nits 5.
#19 [high] Research summary
Deliverable 1 — FULL REPORT
PR #549 — Report KV pages held by active requests
Reviewed at head 9cca87ac ("Keep page gauges out of the copy-out retry key"), draft, 8 files, +246/−16. Closes #537. Sibling metrics PR is #548 ("Add request latency histograms and process metrics"); #553 is the new per-request-metrics PR.
Verdict: Changes Requested — small. The previous round's single blocker is fixed at this head (the two gauges are zeroed when the copy-out retry key is built), as are the retire pin-ordering defect and the wrong cache.rs doc comment. What remains is one API paragraph that contradicts itself, four mechanical accuracy fixes in the PR description, and about 75 of the 246 added lines that can be deleted. Nothing below asks for new code, a new flag, a new test, or new documentation.
Key findings
- Scope and approach are right. The change is confined to shared runtime layers — KV cache accounting (
helios/src/cache.rs), scheduler statistics (helios/src/scheduler.rs), the Prometheus renderer (helios/src/server/metrics.rs),docs/api.md. No per-model branch, no boolean policy flag, no environment switch, no allocation/eviction/preemption/readmission change. That matches the charter ("keep the runtime small and model-agnostic"; "look for the smallest footprint in shared code") andAGENTS.md:165-200(not opened). - The stated constraint is respected.
Cache::statsstill does not scannodes; the count is maintained on the pin paths (cache.rs:551-580) and the scheduler adds per-slot counts (scheduler.rs:1216-1228). Work is bounded per pin operation, so no steady-state cost class changes. - The previously reported blocker is fixed and must not be re-raised.
runtime.rs:2441-2456builds theCopyoutResourceskey withSchedulerStats { request_pages: 0, reserved_pages: 0, ..self.scheduler.stats() }(2446-2449, compared at2455), so page movement between reserved and private pages no longer re-offers deferred host copy-outs. Residual coupling only — Nit 3. - Also fixed at this head:
retirereleases the request pin before emptying the slot (scheduler.rs:3149-3157);pin_request's doc comment now states the cache's half and points at the scheduler (cache.rs:548-550); the three mirroredif inbound.is_none()pin branches became one dispatcher (scheduler.rs:2025-2040). - Verified correct — do not re-flag: request pin/release symmetry on every path (admission
scheduler.rs:1645/1656/1678; ticket waiters1889; boundary publication2977/2979/2997/2998; retirement3155), with ticket-parent pins keeping the plain API (1871,1907) and copy-out usingpin_checkpoint(2044/2048);request_pinned_pagesmoving only at the 0↔1 transition ofrequest_pins(cache.rs:551-580); compaction carrying request pins into the heir (cache.rs:623-631, assert at627); eviction gated onpins == 0(cache.rs:658-663); gauges rendered inside the existing gauge array (metrics.rs:1309-1318), stored in the bulk table (metrics.rs:517-518), and absent from the JSONSnapshot; reserved pages genuinely "neither free, cached, nor written" (popped fromfree_pagesat admissionscheduler.rs:1721-1724, consumed intoprivate_pagesat commitscheduler.rs:2439-2444); retirement drain and in-flight restore tickets outside both gauges (scheduler.rs:1887-1899,3177-3191). - Explicitly not pressed (a later round should not re-propose these): adding a
docs/runtime-core-design.md(not opened) entry (that is more prose, not less); adding a test forpublish_boundary'sExistingbranch (cheapest coverage is the fixture merge in S-1, Nit 5); deletingCheckpoint::direct_request_pins, deletingflare_reserved_kv_pageswhile the docs namerequest + reserved, or removing the runtime zeroing block — each has a load-bearing reason, see "Answered, not cut".
Blockers
None. At this head correctness is clean, architecture reports no blocking issue, and prose has no blocking defect.
Should Fix
SF1. docs/api.md:298-312 — the paragraph defines two different ratios and misattributes the exclusions
Current text, docs/api.md:307-312:
Reserved pages are outside the request gauge, so
flare_request_kv_pages + flare_reserved_kv_pagesis the figure comparable to another runtime's used KV cache. Dividing either gauge byflare_total_kv_pagesexcludes idle cached prefixes and snapshot backing pages, and the test-only assertion inCache::statscompares the maintained request-pinned count with a full scan of every checkpoint on each read.
Four defects in six lines:
- Two incompatible ratios in adjacent sentences. Line 308 says the sum is the comparable figure; line 309 says dividing either gauge gives the share. Both cannot be true, and by the author's own scrape (
flare_reserved_kv_pages3 and 2 of 21504)reserved/totalcarries no information. An operator cannot tell whether to plotrequest/totalor(request + reserved)/total— the very number #537 exists to make computable. - The exclusion is misattributed. "Dividing … by
flare_total_kv_pagesexcludes …" makes the division the cause; what is left out is a property of the numerator. Coupled with "idle cached prefixes" it reads as ifcachedis excluded wholesale, contradictingdocs/api.md:303-306two lines above (pinned tail pages appear in both gauges). - A
#[cfg(test)]assertion in the operator-facing API page.helios/src/scheduler… specificallyhelios/src/cache.rs:818-837is validation evidence; it belongs in the PR description, not a present-state specification (docs/design-review.md(not opened) principle 16;.agents/skills/repo-prose/SKILL.md:26-29(not opened)). - Cadence overstated.
docs/api.md:302-303says the worker publishes "on every scheduler pass"; the worker stores only when a pass reports progress (runtime.rs:1148-1153), plus startup (runtime.rs:722) and the post-shutdown drain (runtime.rs:745). A stalled scheduler legitimately leaves the gauge at its last published value.
Requested change — replace docs/api.md:298-312 with the following (net −2 lines, no new claims):
`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 an admission ticket's
in-flight restore. `flare_reserved_kv_pages` counts pages reserved for those
requests' growth that are neither free, cached, nor written yet. The worker
publishes both when a scheduler pass makes progress, and a scrape reads the last
published values. `(flare_request_kv_pages + flare_reserved_kv_pages)` over
`flare_total_kv_pages` is the share comparable to vLLM's `kv_cache_usage_perc`;
idle cached prefixes and snapshot backing pages are outside it.
One ratio stated once; the exclusions stated as a numerator property; the test hook deleted (it already lives in the PR body); "requests owning a model slot" instead of "active requests", which is what scheduler.rs:1216-1228 sums (inbound_waiting counts a restore ticket's request as active, yet its pages are in neither gauge, scheduler.rs:1229-1232).
Why it matters: this is the only prose in the repository defining the ratio the new gauge exists to enable, and it is internally inconsistent, so an operator mis-states both the formula and what the numerator excludes. AGENTS.md:165-166 (not opened) requires a contribution to leave documentation accurate; principle 16 requires prose a reviewer can reconstruct the argument from.
SF2. PR description — four mechanical accuracy defects, one edit
None break the change; all are what a reviewer or agent must guess today (AGENTS.md:88-102 (not opened), 135-137).
- "What changed" omits
helios/src/server/runtime.rs. The head commit makes the deferred host copy-out retry key depend on aSchedulerStatswith the two new gauges zeroed (runtime.rs:2441-2456). That is a behavioural change in a file the description never names, and it is precisely what makes "No allocation, eviction, or scheduling decision changes" true. Add a bullet:CopyoutResourcesembedsSchedulerStatswhole (runtime.rs:1053-1059), sorequest_pages/reserved_pagesare zeroed when the key is built, because decode moves those counts without moving cache resources. - "A page shared through a pinned ancestor therefore counts once for every request that references it" is wrong and contradicts the PR's own test.
cache.rs:551-563adds a checkpoint's tail pages only on the 0→1 transition ofrequest_pins, so a shared page counts once in total.cache/tests.rs:320-342asserts 3, not 4, for a parent shared by two children. As written the sentence makes the reported live values (399/402 of 21504) look implausibly small. Say: a page in a shared ancestor's tail is counted once in the total, however many requests pin checkpoints below it; per-request totals add each request's private pages. - "a checkpoint leaves
nodesonly at zero pins" is false for compaction.compact_ancestorremoves the node atcache.rs:614with its pins still held and moves them into the heir (cache.rs:615-616,629-631; assert at627). Say: a leaf leavesnodesonly at zero pins; a compacted ancestor's request pins and pages move into its heir. - The live consistency check does not attest the gauge, and the quoted ratio is not the documented one.
request + reserved < total − free − cachedholds becausetotal − free − cachedis dominated by snapshot-backing pages (metrics.rs:1294-1298); the in-repo invariant that does attest the counter is the drift assertion (cache.rs:818-837), optionally plusrequest_pinned_pages <= cached_pages. "The ratio measured 0.0186 and 0.0187" isrequest/total, while the docs callrequest + reservedthe comparable figure — label it so the two do not disagree.
Subtract / Simplify
About 75 of the 246 added lines can go without losing anything #537 asks for (~30%). Nothing here adds a parallel mechanism: the gauges reuse the existing gauge array, the bulk update table, and the expected-exposition rows, and no second representation of the count exists.
| # | Where | Lines saved |
|---|---|---|
| S-1 | helios/src/scheduler/tests.rs:970-1034 re-runs an existing test's whole scenario |
~45 |
| S-2 | helios/src/cache/tests.rs:320-342 copies the fixture directly below it |
~10 |
| S-3 | helios/src/cache.rs:519-580 — pin_request/unpin_request re-walk the chain and duplicate pin/unpin's guards |
~20 |
Up to ~100 lines if flare_reserved_kv_pages is also dropped (see "Answered, not cut").
S-1 (~45 lines) — the new scheduler test duplicates the test directly below it
request_kv_pages_count_shared_prefix_pages_once (scheduler/tests.rs:970-1034, 65 lines) repeats branching_requests_own_distinct_tail_pages_and_terminal_snapshots (1036-1081) step for step: same scheduler(2, 8, 5), same seed admit/init/plan/commit Fence(2)/complete/freeze(3)/finish, same two admit(spec(65, 4)), same Fence(5) completion, same retain_prompt(6), same prefill-lane assertion, same Fence(7) completion. Lines 972-1009 are identical to 1038-1075, and the existing test already asserts the two requests share shared_pages (1078) and differ in private pages (1079).
Only 1010-1033 is new evidence: five lengths, two stats assertions, two cancels, and the (0, 0) / cached_pages > 0 checks.
Change: delete the test; append its new content to the existing one, keeping the handles instead of shadowing them at 1076-1077:
let (shared, private, reserved) = (
first.shared_pages.len(),
first.private_pages.len() + second.private_pages.len(),
first.reserved_pages.len() + second.reserved_pages.len(),
);
assert!(!first.shared_pages.is_empty());
let stats = scheduler.stats();
assert_eq!(stats.request_pages, shared + private);
assert_eq!(stats.reserved_pages, reserved);
scheduler.cancel(first.handle).unwrap();
scheduler.cancel(second.handle).unwrap();
let stats = scheduler.stats();
assert_eq!((stats.request_pages, stats.reserved_pages), (0, 0));
assert!(stats.cached_pages > 0);
Take the lengths into locals before the cancels (the borrow must come back for cancel); LiveRequest::handle is public (scheduler.rs:226). Every behaviour the new test proves survives — shared pages counted once, the reserved sum, the retire-to-zero drain — on a fixture the suite already pays for. AGENTS.md:194-199 (not opened) asks a test to exercise the contract it names, not re-establish a fixture another test already builds.
S-2 (~10 lines) — the new cache test repeats the fixture below it
helios/src/cache/tests.rs:322-328 is character-identical to 346-352 in branching_pins_ancestors_and_prevents_direct_ancestor_unpin. Because pin_request calls pin first (cache.rs:552), the existing test can take its pins through pin_request/unpin_request and gain the request_pinned_pages assertions without losing its pin_count() checks. Also drop cache/tests.rs:335 (assert!(cache.unpin_request(parent).is_err())): it re-tests the "no direct pin" guard already covered for the plain API at :358, and parent holds no direct request pin, so it is not evidence for the shared-page accounting the test is named for.
Caveat: inserting request pins at :356 changes the pin counts the later eviction steps assert (357-386); place the fold after :372, or re-run the test and adjust the two pin_count() expectations.
S-3 (~20 lines) — pin_request/unpin_request duplicate pin/unpin's guards and walk the chain twice
pin (cache.rs:519-534) and unpin (536-546) each compute self.chain(id)? once and own their whole invariant inside that walk, including the refcount-exhaustion guard (524-528). pin_request calls self.pin(id)? and then chains again (552-554); unpin_request does the same (569-571). So every request pin and release pays two walks and two Vec allocations, and the "request_pins ⊆ pins" invariant lives in two function pairs that must stay in agreement, with the test-only drift assert (cache.rs:818-837) as the only detector.
Call sites are the hot paths: admission (scheduler.rs:1645), ticket waiters (1889), both boundary publications (2977, 2997), retirement (3155), and the two rollback arms (1656, 1678).
Change: one private worker, one walk, both counter sets; the public methods become one-liners, keeping the direct_request_pins == 0 guard and both error strings so cache/tests.rs:329-340 stays meaningful:
fn pin_with(&mut self, id: CheckpointId, request: bool) -> Result<()> {
if !self.checkpoint(id)?.ready { return Err("cannot pin a checkpoint before GPU readiness".into()); }
let chain = self.chain(id)?;
if self.nodes[&id].direct_pins == u64::MAX
|| chain.iter().any(|id| self.nodes[id].pins == u64::MAX) {
return Err("checkpoint reference count exhausted".into());
}
self.nodes.get_mut(&id).unwrap().direct_pins += 1;
if request { self.nodes.get_mut(&id).unwrap().direct_request_pins += 1; }
for ancestor in chain {
let node = self.nodes.get_mut(&ancestor).unwrap();
node.pins += 1;
if request {
node.request_pins += 1;
if node.request_pins == 1 { self.request_pinned_pages += node.tail_pages.len(); }
}
}
Ok(())
}
pub fn pin(&mut self, id: CheckpointId) -> Result<()> { self.pin_with(id, false) }
pub fn pin_request(&mut self, id: CheckpointId) -> Result<()> { self.pin_with(id, true) }
Mirror unpin_with(id, request), keeping the direct_request_pins == 0 check when request == true and adding a debug_assert!(node.request_pins > 0) at the 1→0 transition (the usize subtraction at 576 is otherwise guarded only by an invariant). This also gives the 0↔1 transition — the only place request_pinned_pages moves — a single site.
Answered, not cut (so no later round re-proposes them)
flare_reserved_kv_pages(~22-25 lines) stays while the docs namerequest + reserved; that comparison to vLLM'skv_cache_usage_percis its justification, and SF1 states it. If SF1 is instead answered by reducing the paragraph torequest/total(what #537 literally asks and what the description measured), the gauge becomes cleanly deletable:scheduler.rs:132-133,1223-1228;metrics.rs:266,518,1314-1318,1791,1836; thedocs/api.mdreserved clause — andruntime.rs:2448shrinks to one zeroing line.Checkpoint::direct_request_pinsstays (cache.rs:82-83,461,553,566-568,570). A checkpoint can be pinned both by a request and for host-store copy-out (pin_checkpoint,scheduler.rs:2044), so a duplicated request release would silently driverequest_pinsbelow its true value; the guard at566-568is the only release-build detector.- The runtime zeroing block stays (
runtime.rs:2443-2450): it is what makes the head truthful. Its permanent replacement is Nit 3. pin_prefix/unpin_prefix(scheduler.rs:2025-2040) stay. They are net +4 lines over the three inline branches they replaced and they encode the admission pin kind once; deleting them re-inlines the dispatch at three sites, and routing the four directcache.pin_requestcalls through them is line-neutral. Neither is worth a change request.- Keep as-is:
PrefixCheckpointCache::request_pinned_pagesand its 0↔1 brackets (this is what keepsstatsoffnodes); the compaction assert (cache.rs:623-627); the extended drift assertion (818-837, highest test value per line in the change); therequest_pages/reserved_pagessums (scheduler.rs:1216-1228); the atomic/store/render triple;docs/api.md's first three definition lines.
Nits
scheduler.rs:1203-1228:stats()now walksself.slotsthree times (active_requests1203-1207, private pages1216-1222, reserved pages1223-1228) on every progressing pass (runtime.rs:1148-1149). Onefoldseeded overslot.requestyields both new values and reads as the pair the docs describe. No behaviour change.scheduler.rs:3151-3152:retirecallsself.request(handle)?twice more than needed forprefix(already bound at3120) anderror_code; bind both once beside the other locals. Two fewer slot lookups, no behaviour change.runtime.rs:2441-2456:CopyoutResourcesstill embeds all ofSchedulerStats(1053-1059), so every future gauge joins the copy-out retry key by default and needs a second edit here. The zeroing is correct today; the smaller long-term shape is a key holding only the cache-side values copy-out depends on (free_pages,free_snapshots,cached_pages, snapshot backing, retiring slots). That changes which movements re-offer deferred copy-outs, so it needs its own justification — a note, not a request.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."- Coverage, free and optional: nothing exercises
publish_boundary'sExisting { ready: true }re-pin (scheduler.rs:2994-3006), the one place where a second request pins a checkpoint another already pinned — where a double count or a missing pin would hide. The drift assertion would catch a cache-side error there, but no test reaches it. Cheapest reach is the merged fixture from S-1; do not add a new test.
Process notes (not findings)
- The head has no reported CI run; the 508-test figure is taken on trust (the named tests were read and match their claims).
- The live scrape values come from a validation tree built on fork commit
5ffe4d54(upstream PR #482 plus #536/#548), so they are not reproducible from this branch alone. The description discloses the instance, this agent session's contamination of the gauges, and "no comparison claimed" — that is honest and should not be pressed. docs/api.mdgains no table rows for the two gauges; that is correct, because the table maps JSONSnapshotfields and the gauges are deliberately text-only (docs/api.md:332-355).
Deliverable 2 — SUMMARY (counts only, for the GitHub comment)
Recommendation: Changes Requested
The blocker from the last round is fixed at 9cca87a — the two gauges are now zeroed in the copy-out retry key — as are the retire ordering and the wrong cache.rs doc comment. What remains is one self-contradictory API paragraph, four mechanical description fixes, and about 75 of the 246 added lines that can simply be deleted; no new code, tests, flags or docs are requested.
Blockers: 0 Should fix: 2 Subtractive suggestions: 3 Nits: 5
#20 [high] FINAL FULL REPORT (supersedes #15) — PR #549 at head 9cca87a
PR #549 — Report KV pages held by active requests
Reviewed at head 9cca87ac ("Keep page gauges out of the copy-out retry key"), draft, 8 files, +246/−16. Closes #537. Sibling metrics PR is #548 ("Add request latency histograms and process metrics"); #553 is the new per-request-metrics PR (#553 changes no code this PR touches).
Verdict: Changes Requested — small. The previous round's single blocker is fixed at this head (the two gauges are zeroed when the copy-out retry key is built), as are the retire pin-ordering defect and the wrong cache.rs doc comment. What remains is one API paragraph that contradicts itself, four mechanical accuracy fixes in the PR description, and about 75 of the 246 added lines that can be deleted. Nothing below asks for new code, a new flag, a new test, or new documentation.
Key findings
- Scope and approach are right. Confined to shared runtime layers — KV cache accounting (
helios/src/cache.rs), scheduler statistics (helios/src/scheduler.rs), the Prometheus renderer (helios/src/server/metrics.rs),docs/api.md. No per-model branch, no boolean policy flag, no environment switch, no allocation/eviction/preemption/readmission change. Matches the charter ("keep the runtime small and model-agnostic"; "look for the smallest footprint in shared code") andAGENTS.md:165-200. - The stated constraint holds.
Cache::statsstill does not scannodes; the count is maintained on the pin paths (cache.rs:551-580) and the scheduler adds per-slot counts (scheduler.rs:1216-1228). Work is bounded per pin operation; no steady-state cost class changes. - The previously reported blocker is fixed — do not re-raise it.
runtime.rs:2441-2456builds theCopyoutResourceskey withSchedulerStats { request_pages: 0, reserved_pages: 0, ..self.scheduler.stats() }(2446-2449), compared at2455, so page movement between reserved and private pages no longer re-offers deferred host copy-outs. Residual coupling only — Nit 3. - Also fixed at this head:
retirereleases the request pin before emptying the slot (scheduler.rs:3149-3157);pin_request's doc comment states the cache's half and points at the scheduler (cache.rs:548-550); the three mirroredif inbound.is_none()pin branches became one dispatcher (scheduler.rs:2025-2040). - Verified correct — do not re-flag: pin/release symmetry on every path (admission
scheduler.rs:1645/1656/1678; ticket waiters1889; boundary publication2977/2979/2997/2998; retirement3155), ticket-parent pins keeping the plain API (1871,1907), copy-out viapin_checkpoint(2044/2048);request_pinned_pagesmoving only at the 0↔1 transition ofrequest_pins(cache.rs:551-580); compaction carrying request pins into the heir (cache.rs:614-631, assert at627); eviction gated onpins == 0(cache.rs:658-663); gauges inside the existing gauge array (metrics.rs:1309-1318), stored in the bulk table (metrics.rs:517-518), absent from the JSONSnapshot; reserved pages genuinely "neither free, cached, nor written" (popped fromfree_pagesatscheduler.rs:1721-1724, consumed intoprivate_pagesatscheduler.rs:2439-2444); retirement drain and in-flight restore tickets outside both gauges (scheduler.rs:1887-1899,3177-3191). - Explicitly not pressed: a
docs/runtime-core-design.mdentry (more prose, not less); a new test forpublish_boundary'sExistingbranch (cheapest coverage is the S-1 fixture merge, Nit 5); deletingCheckpoint::direct_request_pins, deletingflare_reserved_kv_pageswhile the docs namerequest + reserved, or removing the runtime zeroing block — see "Answered, not cut".
Blockers
None. At this head correctness is clean, architecture reports no blocking issue, and prose has no blocking defect.
Should Fix (2)
SF1. docs/api.md:298-312 — two incompatible ratios, misattributed exclusions, a test hook, wrong cadence
Current docs/api.md:307-312: "Reserved pages are outside the request gauge, so flare_request_kv_pages + flare_reserved_kv_pages is the figure comparable to another runtime's used KV cache. Dividing either gauge by flare_total_kv_pages excludes idle cached prefixes and snapshot backing pages, and the test-only assertion in Cache::stats compares the maintained request-pinned count with a full scan of every checkpoint on each read."
Four defects:
- Two incompatible ratios in adjacent sentences (308 vs 309). By the author's own scrape
reservedis 2–3 of 21504, soreserved/totalcarries no information; an operator cannot tell whether to plotrequest/totalor(request+reserved)/total— the number #537 exists to make computable. - Exclusion misattributed: the division is not the cause; what is left out is a property of the numerator. "idle cached prefixes" also reads as excluding
cachedwholesale, contradictingdocs/api.md:303-306(pinned tail pages appear in both gauges). - A
#[cfg(test)]assertion in the operator-facing API page (helios/src/cache.rs:818-837) — validation evidence, belongs in the PR body (docs/design-review.mdprinciple 16;.agents/skills/repo-prose/SKILL.md:26-29). - Cadence overstated at
docs/api.md:302-303: the worker stores only when a pass reports progress (runtime.rs:1148-1153), plus startup (runtime.rs:722) and post-shutdown drain (runtime.rs:745).
Requested replacement for docs/api.md:298-312 (net −2 lines, no new claims):
`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 an admission ticket's
in-flight restore. `flare_reserved_kv_pages` counts pages reserved for those
requests' growth that are neither free, cached, nor written yet. The worker
publishes both when a scheduler pass makes progress, and a scrape reads the last
published values. `(flare_request_kv_pages + flare_reserved_kv_pages)` over
`flare_total_kv_pages` is the share comparable to vLLM's `kv_cache_usage_perc`;
idle cached prefixes and snapshot backing pages are outside it.
Why: this is the only prose defining the ratio the gauge exists to enable, and it is internally inconsistent; "requests owning a model slot" is what scheduler.rs:1216-1228 sums (inbound_waiting counts a restore-ticket request as active at 1229-1232 yet its pages are in neither gauge). AGENTS.md:165-166 + principle 16.
SF2. PR description — four mechanical accuracy defects, one edit
- "What changed" never names
helios/src/server/runtime.rs. The head commit makes the deferred copy-out retry key depend on a zeroedSchedulerStats(runtime.rs:2441-2456;CopyoutResourcesembeds the whole struct at1053-1059). That is the behavioural change that makes "No allocation, eviction, or scheduling decision changes" true — add a bullet saying so and why (decode moves page counts without moving cache resources). - "A page shared through a pinned ancestor therefore counts once for every request that references it" is wrong and contradicts the PR's own test.
cache.rs:551-563adds tail pages only on the 0→1 transition, so a shared page counts once in total;cache/tests.rs:320-342asserts 3, not 4. As written it makes the reported 399/402 of 21504 look implausible. Say: counted once in the total, however many requests pin checkpoints below it; per-request totals add each request's private pages. - "a checkpoint leaves
nodesonly at zero pins" is false for compaction.compact_ancestorremoves the node atcache.rs:614with pins held, moving them into the heir (615-616,629-631; assert627). Say: a leaf leavesnodesonly at zero pins; a compacted ancestor's request pins and pages move into its heir. - The live consistency check does not attest the gauge, and the quoted ratio is not the documented one.
request + reserved < total − free − cachedholds because the right side is dominated by snapshot-backing pages (metrics.rs:1294-1298); cite the drift assertion (cache.rs:818-837), optionally plusrequest_pinned_pages <= cached_pages. "ratio measured 0.0186 and 0.0187" isrequest/totalwhile the docs namerequest + reserved— label it.
Citations for rules: AGENTS.md:88-102, 135-137.
Subtract / Simplify (3 items, ~75 of +246 lines ≈ 30%; up to ~100 if flare_reserved_kv_pages goes)
Nothing adds a parallel mechanism: the gauges reuse the existing gauge array, the bulk update table and the expected-exposition rows; no second representation of the count exists.
S-1 (~45 lines) — the new scheduler test re-runs the test directly below it
request_kv_pages_count_shared_prefix_pages_once (helios/src/scheduler/tests.rs:970-1034, 65 lines) repeats branching_requests_own_distinct_tail_pages_and_terminal_snapshots (1036-1081) step for step: same scheduler(2, 8, 5), same seed admit/init/plan/commit Fence(2)/complete/freeze(3)/finish, same two admit(spec(65, 4)), same Fence(5) completion, retain_prompt(6), prefill-lane assertion, Fence(7) completion. Lines 972-1009 are identical to 1038-1075; the existing test already asserts shared pages equal (1078) and private pages differing (1079). Only 1010-1033 is new evidence. Delete the test; append to the existing one (keeping the handles instead of shadowing them at 1076-1077):
let (shared, private, reserved) = (
first.shared_pages.len(),
first.private_pages.len() + second.private_pages.len(),
first.reserved_pages.len() + second.reserved_pages.len(),
);
assert!(!first.shared_pages.is_empty());
let stats = scheduler.stats();
assert_eq!(stats.request_pages, shared + private);
assert_eq!(stats.reserved_pages, reserved);
scheduler.cancel(first.handle).unwrap();
scheduler.cancel(second.handle).unwrap();
let stats = scheduler.stats();
assert_eq!((stats.request_pages, stats.reserved_pages), (0, 0));
assert!(stats.cached_pages > 0);
Take the lengths into locals before the cancels (the borrow comes back for cancel); LiveRequest::handle is public (scheduler.rs:226). All proven behaviour survives on a fixture the suite already pays for (AGENTS.md:194-199).
S-2 (~10 lines) — the new cache test repeats the fixture below it
helios/src/cache/tests.rs:322-328 is character-identical to 346-352 in branching_pins_ancestors_and_prevents_direct_ancestor_unpin. Because pin_request calls pin first (cache.rs:552), the existing test can take its pins through pin_request/unpin_request and gain the request_pinned_pages assertions without losing its pin_count() checks. Also drop cache/tests.rs:335 (unpin_request(parent).is_err()): it re-tests the "no direct pin" guard already at :358, and parent holds no direct request pin, so it is not evidence for shared-page accounting. Caveat: request pins inserted at :356 change the pin counts asserted at 357-386; fold after :372 or adjust the two pin_count() expectations.
S-3 (~20 lines) — pin_request/unpin_request duplicate pin/unpin's guards and walk the chain twice
pin (cache.rs:519-534) and unpin (536-546) each chain once and own their whole invariant inside that walk, including the refcount guard (524-528). pin_request calls self.pin(id)? then chains again (552-554); unpin_request likewise (569-571). Two walks and two Vec allocations per request pin and per release, on admission (scheduler.rs:1645), ticket waiters (1889), both boundary publications (2977, 2997), retirement (3155), and both rollback arms (1656, 1678); the request_pins ⊆ pins invariant lives in two function pairs with only the test-only drift assert (cache.rs:818-837) as detector. Fold into one private worker:
fn pin_with(&mut self, id: CheckpointId, request: bool) -> Result<()> {
if !self.checkpoint(id)?.ready { return Err("cannot pin a checkpoint before GPU readiness".into()); }
let chain = self.chain(id)?;
if self.nodes[&id].direct_pins == u64::MAX
|| chain.iter().any(|id| self.nodes[id].pins == u64::MAX) {
return Err("checkpoint reference count exhausted".into());
}
self.nodes.get_mut(&id).unwrap().direct_pins += 1;
if request { self.nodes.get_mut(&id).unwrap().direct_request_pins += 1; }
for ancestor in chain {
let node = self.nodes.get_mut(&ancestor).unwrap();
node.pins += 1;
if request {
node.request_pins += 1;
if node.request_pins == 1 { self.request_pinned_pages += node.tail_pages.len(); }
}
}
Ok(())
}
pub fn pin(&mut self, id: CheckpointId) -> Result<()> { self.pin_with(id, false) }
pub fn pin_request(&mut self, id: CheckpointId) -> Result<()> { self.pin_with(id, true) }
Mirror unpin_with(id, request), keeping the direct_request_pins == 0 check when request == true and adding debug_assert!(node.request_pins > 0) at the 1→0 transition (the usize subtraction at 576 is otherwise guarded only by an invariant). Gives the 0↔1 transition — the only place request_pinned_pages moves — a single site.
Answered, not cut
flare_reserved_kv_pages(~22-25 lines) stays while the docs namerequest + reserved(vLLMkv_cache_usage_percparity), which SF1 states. If SF1 is answered instead by reducing the paragraph torequest/total(what #537 literally asks and what the description measured), it becomes cleanly deletable:scheduler.rs:132-133,1223-1228;metrics.rs:266,518,1314-1318,1791,1836; thedocs/api.mdreserved clause — andruntime.rs:2448shrinks to one zeroing line.Checkpoint::direct_request_pinsstays (cache.rs:82-83,461,553,566-568,570): a checkpoint can be pinned by a request and for copy-out (pin_checkpoint,scheduler.rs:2044), so a duplicated release would silently driverequest_pinsbelow truth; the guard at566-568is the only release-build detector.- The runtime zeroing block stays (
runtime.rs:2443-2450) — it is what makes the head truthful; permanent replacement is Nit 3. pin_prefix/unpin_prefix(scheduler.rs:2025-2040) stay: net +4 lines over the three inline branches, and they encode the admission pin kind once; routing the four directcache.pin_requestcalls through them is line-neutral.- Keep:
request_pinned_pages+ its 0↔1 brackets; the compaction assert (cache.rs:623-627); the drift assertion (818-837, best value per line in the change); therequest_pages/reserved_pagessums; the atomic/store/render triple;docs/api.md's first three definition lines.
Nits (5)
scheduler.rs:1203-1228—stats()walksself.slotsthree times (1203-1207,1216-1222,1223-1228) on every progressing pass (runtime.rs:1148-1149); onefoldyields both new values and reads as the documented pair.scheduler.rs:3151-3152—retirere-readsself.request(handle)?forprefix(already bound at3120) anderror_code; bind both once. No behaviour change.runtime.rs:2441-2456—CopyoutResourcesstill embeds all ofSchedulerStats(1053-1059), so every future gauge joins the retry key by default and needs a second edit here; the smaller long-term shape is a key holding only the cache fields copy-out depends on (free_pages,free_snapshots,cached_pages, snapshot backing, retiring slots). That changes which movements re-offer deferred copy-outs, so it needs its own justification — a note, not a request.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."- Coverage, free and optional — nothing exercises
publish_boundary'sExisting { ready: true }re-pin (scheduler.rs:2994-3006), the one place a second request pins a checkpoint another already pinned. Cheapest reach is the S-1 merged fixture; do not add a test.
Process notes (not findings)
- No reported CI run at the head; the 508-test figure is taken on trust (the named tests were read and match their claims).
- The live scrape numbers come from a validation tree on fork commit
5ffe4d54(upstream PR #482 plus #536/#548), so they are not reproducible from this branch; the description discloses the instance, the agent session's contamination, and "no comparison claimed" — honest, do not press. - No table rows for the two gauges in
docs/api.md:332-355is correct: that table maps JSONSnapshotfields and the gauges are deliberately text-only.
#7 [medium] NITS + process notes (fold, don't add; subtraction first)
Keep these short in the full report.
N-1 (scheduler.rs:1216-1228): stats() now walks self.slots three times (active_requests 1203-1207, private_pages 1216-1222, reserved_pages 1223-1228). One fold yields both new fields and reads as the pair api.md describes:
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()));
stats() runs from the worker loop (runtime.rs:1148-1149), so this is per-progress not per-scrape.
N-2 (cache.rs:626): added comment "Both nodes are counted or neither is, and the pages move into the counted heir." — "counted" does two jobs. Suggest "the ancestor's request pins equal its heir's, and its pages move into that heir."
N-3 (docs/api.md:298-306): one home for the content. The new paragraph partly restates the HELP text (metrics.rs:1310-1317) and the page table at api.md:325-348 lists cached_pages/free_pages/total_pages but not the two new Prometheus-only gauges (consistent, since that table mirrors JSON fields — do not add rows unless a row is added for the JSON snapshot). Optional one clause: "Neither appears in the JSON snapshot." Optional, and only if the design doc route is preferred: docs/runtime-core-design.md:873 already carries the flare_snapshot_backing_pages rule; a matching two-sentence rule there would replace, not add to, the api.md prose. Skip if api.md is tightened (subtraction first).
N-4 coverage (optional): no test drives pin_request through publish_boundary's Existing branch (scheduler.rs:2988-3000) — the one place where two requests pin the same just-published checkpoint, where a double count or a missed pin would hide. Cheapest coverage is the merged test in S-1, not a new test.
N-5 (description nit, not a code finding): #536 is named as the sibling PR but the numerical sibling is #548 (both by WynnD); #536 is the issue #548 closes. Also the description says "a checkpoint leaves nodes only at zero pins" — wrong for compaction (compact_ancestor requires direct_pins==0 && child_count==1, cache.rs:662, 686-690, and the new assert at 627 lets an ancestor leave carrying nonzero pins into its heir). Fold both into the one description bullet.
Process/evidence notes worth one line total: head 5ed7af8 has no CI checks; live numbers come from a third-party fork base 5ffe4d54 (upstream PR #482) so they are not reproducible from this branch; both are disclosed honestly in the description and should not be pressed.
#13 [medium] Test-merge patch sketches for the two duplicate-test removals (S-1, S-3)
Two merges, both pure deletion once the assertions move. Line numbers at head 5ed7af8.
A. scheduler/tests.rs — delete request_kv_pages_count_shared_prefix_pages_once (970-1034, +66) and append its new content to branching_requests_own_distinct_tail_pages_and_terminal_snapshots (1036-1081). The existing test's body up to line 1075 is byte-identical to the new test's up to 1009, so nothing else is needed. Change 1076-1077 to stop shadowing the handles:
let first_request = scheduler.request(first).unwrap();
let second_request = scheduler.request(second).unwrap();
assert_eq!(first_request.shared_pages, second_request.shared_pages);
assert!(!first_request.shared_pages.is_empty()); // keep from 1014
assert_ne!(first_request.private_pages, second_request.private_pages);
assert!(first_request.terminal_snapshot.is_none() && second_request.terminal_snapshot.is_none());
let stats = scheduler.stats();
assert_eq!(stats.request_pages,
first_request.shared_pages.len() + first_request.private_pages.len() + second_request.private_pages.len());
assert_eq!(stats.reserved_pages, first_request.reserved_pages.len() + second_request.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);
(Borrow check note for the author: take the lengths into locals before the cancels, as the new test already does at 1010-1022 — scheduler.cancel needs the borrow back. Keeping the 1010-1022 destructuring block and only moving the two assert_eq! pairs plus the cancel tail is the least-risk edit.)
Net ~55 lines.
B. cache/tests.rs — delete request_pins_count_each_shared_page_once's preamble (322-328, identical to 346-352) and fold its assertions into branching_pins_ancestors_and_prevents_direct_ancestor_unpin right after its cache.pin(left_id)/cache.pin(right_id) (355-356):
cache.pin_request(left_id).unwrap();
cache.pin_request(right_id).unwrap();
assert_eq!(cache.stats().request_pinned_pages, 3); // shared page counted once for both
cache.pin(right_id).unwrap();
assert_eq!(cache.stats().request_pinned_pages, 3); // a plain pin changes nothing
cache.unpin_request(left_id).unwrap();
assert_eq!(cache.stats().request_pinned_pages, 2);
cache.unpin(right_id).unwrap();
assert_eq!(cache.stats().request_pinned_pages, 2);
cache.unpin_request(right_id).unwrap();
assert_eq!(cache.stats().request_pinned_pages, 0);
Drop 335 (assert!(cache.unpin_request(parent).is_err())) entirely: the plain-API equivalent already sits at 358, and parent holds no direct request pin so it is not evidence about shared-page accounting. Note that inserting the request pins at 356 changes the pin counts the later eviction steps at 357-386 assert — the author should re-run that test and adjust the two pin_count() expectations, or place the fold after line 372 instead. Net ~10 lines.