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

Raw Markdown for agents: https://autobot.eidonix.com/p/aaec3527-4dbf-4250-9234-fff8f1c88b4f.md

#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:

#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:

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."

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).

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

  1. scheduler.rs:1203-1228: three passes over self.slots where one fold gives both new fields; a fold also makes them read as the pair the docs describe. No behaviour change.
  2. 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.
  3. 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.
  4. Coverage, optional and free: no test drives pin_request through publish_boundary's Existing branch (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.
  5. Description-only, fold into one bullet: "a checkpoint leaves nodes only at zero pins" is wrong for compaction (compact_ancestor requires direct_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

Should fix

Subtract / Simplify

Could remove ~90 of +218 added lines (up to ~112 if flare_reserved_kv_pages goes):

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

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_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.

Three defects in five lines:

  1. 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_pages 3 and 2 of 21504) reserved/total carries no information. An operator cannot tell whether to plot request/total or (request + reserved)/total — which is exactly the number #537 exists to make computable.
  2. The exclusion is misattributed. "Dividing … by flare_total_kv_pages excludes …" makes the division the cause; what is excluded is a property of the numerator. Combined with "idle cached prefixes" it also reads as if cached is excluded wholesale, contradicting docs/api.md:303-306 two lines above (pinned tail pages appear in both gauges).
  3. A #[cfg(test)] assertion in the operator-facing API page. helios/src/cache.rs:818-837 is validation evidence; it belongs in the PR description, not a present-state specification (docs/design-review.md principle 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).

  1. "What changed" omits helios/src/server/runtime.rs. The head commit makes the deferred host copy-out retry key depend on a SchedulerStats with 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 embeds SchedulerStats whole (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.
  2. "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-563 adds a checkpoint's tail pages only on the 0→1 transition of request_pins, so a shared page counts once in total. cache/tests.rs:320-342 asserts 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.
  3. "a checkpoint leaves nodes only at zero pins" is false for compaction. compact_ancestor removes the node at cache.rs:614 with its pins still held and moves them into the heir (cache.rs:615-616, 629-631; assert at 627). Say: a leaf leaves nodes only at zero pins; a compacted ancestor's request pins and pages move into its heir.
  4. The live consistency check does not attest the gauge, and the measured ratio is not the one the docs define. request + reserved < total − free − cached holds because total − free − cached is 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 plus request_pinned_pages <= cached_pages. And the "ratio measured 0.0186 and 0.0187" is request/total, while the docs call request + reserved the 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)

Nits

  1. scheduler.rs:1203-1228: stats() now walks self.slots three times (active_requests 1203-1207, private_pages 1216-1222, reserved_pages 1223-1228) on every progressing pass (runtime.rs:1148-1149). One fold seeded over slot.request yields both new values and reads as the pair the docs describe. No behaviour change.
  2. scheduler.rs:3151-3152: retire calls self.request(handle)? twice more than needed for prefix and error_code; bind both once beside the existing locals at 3120. Two fewer slot lookups, no behaviour change.
  3. runtime.rs:2441-2456: CopyoutResources still embeds all of SchedulerStats (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.
  4. 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."
  5. Coverage, free and optional: nothing exercises publish_boundary's Existing { 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.
  6. scheduler.rs:2025-2040: the pin kind travels as a bare bool, so pin_prefix(id, request_pin) is boolean-blind at the call site and reads as a third way to take a request pin alongside the direct cache.pin_request calls. With one dispatcher and three call sites the risk is low; if the API spreads, an enum or a RequestPin marker turns an inverted argument into a compile error. Not worth changing now.

Process notes (not findings)

#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.

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

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_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 in six lines:

  1. 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_pages 3 and 2 of 21504) reserved/total carries no information. An operator cannot tell whether to plot request/total or (request + reserved)/total — the very number #537 exists to make computable.
  2. The exclusion is misattributed. "Dividing … by flare_total_kv_pages excludes …" makes the division the cause; what is left out is a property of the numerator. Coupled with "idle cached prefixes" it reads as if cached is excluded wholesale, contradicting docs/api.md:303-306 two lines above (pinned tail pages appear in both gauges).
  3. A #[cfg(test)] assertion in the operator-facing API page. helios/src/scheduler… specifically helios/src/cache.rs:818-837 is 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)).
  4. Cadence overstated. 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). 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).

  1. "What changed" omits helios/src/server/runtime.rs. The head commit makes the deferred host copy-out retry key depend on a SchedulerStats with 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: CopyoutResources embeds SchedulerStats whole (runtime.rs:1053-1059), so request_pages/reserved_pages are zeroed when the key is built, because decode moves those counts without moving cache resources.
  2. "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-563 adds a checkpoint's tail pages only on the 0→1 transition of request_pins, so a shared page counts once in total. cache/tests.rs:320-342 asserts 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.
  3. "a checkpoint leaves nodes only at zero pins" is false for compaction. compact_ancestor removes the node at cache.rs:614 with its pins still held and moves them into the heir (cache.rs:615-616, 629-631; assert at 627). Say: a leaf leaves nodes only at zero pins; a compacted ancestor's request pins and pages move into its heir.
  4. The live consistency check does not attest the gauge, and the quoted ratio is not the documented one. request + reserved < total − free − cached holds because total − free − cached is 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 plus request_pinned_pages <= cached_pages. "The ratio measured 0.0186 and 0.0187" is request/total, while the docs call request + reserved the 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)

Nits

  1. scheduler.rs:1203-1228: stats() now walks self.slots three times (active_requests 1203-1207, private pages 1216-1222, reserved pages 1223-1228) on every progressing pass (runtime.rs:1148-1149). One fold seeded over slot.request yields both new values and reads as the pair the docs describe. No behaviour change.
  2. scheduler.rs:3151-3152: retire calls self.request(handle)? twice more than needed for prefix (already bound at 3120) and error_code; bind both once beside the other locals. Two fewer slot lookups, no behaviour change.
  3. runtime.rs:2441-2456: CopyoutResources still embeds all of SchedulerStats (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.
  4. 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."
  5. Coverage, free and optional: nothing exercises publish_boundary's Existing { 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)


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

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:

  1. Two incompatible ratios in adjacent sentences (308 vs 309). By the author's own scrape reserved is 2–3 of 21504, so reserved/total carries no information; an operator cannot tell whether to plot request/total or (request+reserved)/total — the number #537 exists to make computable.
  2. 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 cached wholesale, contradicting docs/api.md:303-306 (pinned tail pages appear in both gauges).
  3. 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.md principle 16; .agents/skills/repo-prose/SKILL.md:26-29).
  4. 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

  1. "What changed" never names helios/src/server/runtime.rs. The head commit makes the deferred copy-out retry key depend on a zeroed SchedulerStats (runtime.rs:2441-2456; CopyoutResources embeds the whole struct at 1053-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).
  2. "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-563 adds tail pages only on the 0→1 transition, so a shared page counts once in total; cache/tests.rs:320-342 asserts 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.
  3. "a checkpoint leaves nodes only at zero pins" is false for compaction. compact_ancestor removes the node at cache.rs:614 with pins held, moving them into the heir (615-616, 629-631; assert 627). Say: a leaf leaves nodes only at zero pins; a compacted ancestor's request pins and pages move into its heir.
  4. The live consistency check does not attest the gauge, and the quoted ratio is not the documented one. request + reserved < total − free − cached holds because the right side is dominated by snapshot-backing pages (metrics.rs:1294-1298); cite the drift assertion (cache.rs:818-837), optionally plus request_pinned_pages <= cached_pages. "ratio measured 0.0186 and 0.0187" is request/total while the docs name request + 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

Nits (5)

  1. scheduler.rs:1203-1228 — stats() walks self.slots three times (1203-1207, 1216-1222, 1223-1228) on every progressing pass (runtime.rs:1148-1149); one fold yields both new values and reads as the documented pair.
  2. scheduler.rs:3151-3152 — retire re-reads self.request(handle)? for prefix (already bound at 3120) and error_code; bind both once. No behaviour change.
  3. runtime.rs:2441-2456 — CopyoutResources still embeds all of SchedulerStats (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.
  4. 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."
  5. Coverage, free and optional — nothing exercises publish_boundary's Existing { 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)

#22 [high] FULL REPORT (round 3, head bca7358) — PR #549

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

Reviewed at head bca7358c ("Fix KV-page docs ratio and fold duplicated page tests"), 8 files, +202/−34. Closes #537. Sibling/open metrics PRs: #548 (same author). Verdict: Changes Requested — small, and everything left is either a docs/test edit or a deletion.

Key findings

Blockers

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

Should Fix (2)

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

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

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

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

Requested replacement for docs/api.md:298-310 (same length, both fixed):

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

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

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

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

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

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

Either way the description sentence must be corrected, because the surviving assertion tests the plain-pin guard.

Why: AGENTS.md:194-199 requires tests to exercise the affected contract; the head commit removed the only one that did.

Subtract / Simplify (~55 of +202 added lines, ~27%)

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

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

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

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

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

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

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

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

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

Nits (7)

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

Open questions / process

#23 [high] SUMMARY (round 3, head bca7358) — counts only: 0 / 2 / 4 / 7

Recommendation: Changes Requested

bca7358 fixes everything from the previous round and folds the duplicate tests; the remaining work is one API-doc sentence, one restored test assertion, and about 55 of the +202 added lines that can simply be deleted. Nothing asks for new code, tests, flags, or docs.

Counts match entry #22 exactly: Should fix = SF1 (docs/api.md:298-310 text-only + vLLM definition), SF2 (restore the unpin_request guard assertion / description sentence); Subtract = S1 pin_prefix pair −16, S2 test+comment leftovers −8, S3 direct_request_pins −9, S4 flare_reserved_kv_pages −20-25 (scope decision); Nits 1-7 in #22.

Character count ~390 — under the ~500 limit, no per-item bullets.

#25 [high] Research summary

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

Reviewed at head bca7358c ("Fix KV-page docs ratio and fold duplicated page tests"), 8 files, +202/−34, closes #537. Verdict: Changes Requested — small, and everything left is a docs edit, a restored assertion, or a deletion.

Key findings

Blockers

None.

Should Fix (2)

SF1 — docs/api.md:298-310 never says the gauges are text-only, and asserts a vLLM equivalence the PR declines to claim. (a) Nothing says the two gauges are absent from ?format=json, although the description says it, the adjacent paragraph already routes text-only families (292-296), the JSON table has no row (330-360), and Snapshot reads absent fields as zero (317-318) — a dashboard author on the JSON path reads zeros. (b) (request + reserved)/total "is the share comparable to vLLM's kv_cache_usage_perc" (308-310) is a cross-runtime assertion while the description claims no comparison; name it as the definition being followed. Requested replacement (13→14 lines, both fixed): keep the definition, the flare_cached_kv_pages overlap note, the two exclusions and the cadence; insert "Both are text only and absent from the ?format=json snapshot." after the reserved definition; change the final sentence to "is the share that uses vLLM's kv_cache_usage_perc definition; idle cached prefixes and snapshot backing pages are outside it." Rules: AGENTS.md:52-60 (not opened), 95-102.

SF2 — the fold deleted the only test of the new unpin_request guard, and the description still cites it. bca7358 removed assert!(cache.unpin_request(parent).is_err()); what survives at cache/tests.rs:336 is cache.unpin(parent).is_err(), which tests the plain direct_pins == 0 guard (cache.rs:550-552), not the request guard (547-549). The description still says the test proves "releasing the parent without a request pin is an error". Result: the guard and direct_request_pins (82-83, 461, 531, 556) have no test, no scheduler path reaches them, and yet the guard is the only release-build detector of a mismatched release (debug_assert! at 562 is test-only; a checkpoint can be pinned both by a request and for copy-out, 2037-2038). Fix: restore one line before cache/tests.rs:338 — assert!(cache.unpin_request(parent).is_err()); // parent holds only descendant request pins — or take S3, and correct the description sentence either way (AGENTS.md:194-199 (not opened)).

Subtract / Simplify (~55 of +202 added lines, ~27%)

S1 (~16 lines) — delete pin_prefix/unpin_prefix. scheduler.rs:2018-2033 is a doc comment plus two helpers whose body is if request { cache.pin_request(id) } else { cache.pin(id) }, with three call sites inside admission (1638, 1649, 1671) while the six other request-pin sites call the cache directly (1882, 2970, 2972, 2990, 2991, 3148). Fix: make the cache entry point the single dispatcher (pub(crate) fn pin_for/unpin_for beside cache.rs:519-589), rewrite the three sites, delete 2018-2033. Net −16 lines, one fewer layer. Do not inline the conditional at the call sites — that adds lines.

S2 (~8 lines) — leftovers from the fold and the runtime comment. scheduler/tests.rs:1016-1020 five-line tuple destructure around three len() sums; 1024-1026 three-line comment restating the two assertions below; runtime.rs:2443-2445 three-line comment fits in one ("Decode moves page counts without moving cache resources."). Keep assert!(!first_request.shared_pages.is_empty()) at 1013 — without it an empty shared prefix would make the counts pass without testing sharing.

S3 (~9 lines, alternative to SF2) — direct_request_pins and its guard. Delete cache.rs:82-83, 461, 531, 547-549, 556 and the fixture copy at cache/lifecycle_tests.rs:77. Removes a branch no test and no scheduler path reaches, at the cost of the only release-build mismatched-release check.

S4 (~20-25 lines, scope decision) — flare_reserved_kv_pages is a second gauge #537 did not ask for. #537 asks for flare_request_kv_pages and request/total. If owners want that literally, delete scheduler.rs:132-133, 1204, 1208, 1221; metrics.rs:266, 518, 1314-1318, 1791, 1836; runtime.rs:2448; docs/api.md:304-305 and the reserved part of 308-309; scheduler/tests.rs:1019, 1023, 1030. Nothing else reads it. Three lenses accept it as-is, so this is a decision, not a defect; it is listed so the saving is not lost.

Nits (7)

  1. scheduler.rs:1213, 1216, 1222-1233 — stats() still walks self.slots three more times beside the new loop at 1205-1209, on every progressing pass (runtime.rs:1148-1149) plus startup (722) and the drain (745); folding them in is ~14 lines shorter.
  2. cache.rs:529-532, 547, 550, 554-557 — pin_with fetches nodes[&id] twice; unpin_with checks checkpoint(id)? twice and get_mut twice. One let node = self.nodes.get_mut(&id).unwrap(); per function saves ~4 lines and two hash lookups per pin and release (keep direct counters out of the ancestor loop; chain() starts at id).
  3. scheduler.rs:3144-3145 — retire re-reads the slot for prefix and error_code although both are already bound at 3113 and 3110 with no writer in between.
  4. runtime.rs:1053-1059 with 2441-2450 — CopyoutResources embeds all of SchedulerStats, so every future gauge joins the retry key by default; a key holding only copy-out-relevant fields is smaller long-term but changes which movements re-offer copy-outs — a note, not a request here.
  5. docs/api.md:304-305 and metrics.rs:1316 — "not yet written" is imprecise at the commit boundary (a page popped into private_pages at 2434-2437 is counted while still unwritten); "pages set aside for those requests' growth that no request holds a page for yet" is exact.
  6. Naming drift for the same set — docs/api.md:298 "requests owning a model slot" vs scheduler.rs:130 and metrics.rs:1311 "active requests", while inbound_waiting counts a restore waiter as active (137-138) though it holds no prefix pin; adopt the docs wording in both code sites.
  7. Coverage note, no action: nothing drives publish_boundary's Existing { ready: true } re-pin (2987-2999) with a stats read; cheapest reach is a variant of the existing scheduler fixture, not a new test.

Open questions / process


Summary (counts only — to be posted to GitHub)

Recommendation: Changes Requested

bca7358 fixes everything from the previous round and folds the duplicate tests; the remaining work is one API-doc sentence, one restored test assertion, and about 55 of the +202 added lines that can simply be deleted. Nothing asks for new code, tests, flags, or docs.

#26 [high] Authoritative pointers + line citations verified at bca7358 (round 3 final)

Deliverables of record (round 3, head bca7358c, +202/−34, 8 files)

Citations re-verified in the code at bca7358 this round

Not verifiable here (say so, do not press)

No CI checks on bca7358; the 809/1 test figures, the two-GPU scrape numbers, exported core, Windows build, full helios suite. #548 merge order not checked (disjoint regions of metrics.rs).

#28 [high] FULL REPORT (round 4, head bca7358) — PR #549 — report of record

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

Supersedes #22. Reviewed at bca7358c ("Fix KV-page docs ratio and fold duplicated page tests"), base main, 8 files, +202/−34, closes #537. Sibling PRs: #548 and #560 (same author). Verdict: Changes Requested — small; everything left is one convention fix, one test line, and deletions.

Round-4 delta: no new commits (search_history at pr/549: bca7358c, 9cca87ac, 5ed7af86, then main). Two things changed since round 3: (a) the author posted a live-validation comment (2026-11-28 03:26) with the build combination and scrape numbers; (b) the PR description body was edited without a new commit — its Evidence no longer claims the folded test proves "releasing the parent without a request pin is an error", and its "no comparison with another runtime is claimed" disclaimer is gone. Consequence: the description half of round-3 SF2 is resolved; the missing test-assertion half is not.

Key findings

Blockers

None. Audited and clean: the counter cannot drift, underflow or be stranded (cache.rs:519-570, 825-861); every request-owned pin has a matching release on success, cancel, preempt, finish and shutdown paths; the gauges cannot perturb deferred copy-outs (runtime.rs:2446-2449); the JSON contract is unchanged (metrics.rs:355-393, docs/api.md:317-318). No prose claim is contradicted by the code.

Should Fix (2)

SF1. One named entry point per pin kind — pin_prefix/unpin_prefix is a third shape and six sites bypass it

Where: helios/src/scheduler.rs:2018-2033.

/// Pins `id` for an active request, or for a host admission ticket's parent.
fn pin_prefix(&mut self, id: CheckpointId, request: bool) -> Result<()> {
    if request { self.cache.pin_request(id) } else { self.cache.pin(id) }
}
fn unpin_prefix(&mut self, id: CheckpointId, request: bool) -> Result<()> { … }

The precedent it departs from: pin_checkpoint/unpin_checkpoint (scheduler.rs:2035-2043) are named per kind, documented, and are the only path to a copy-out pin. The cache level already has the right shape: pin_with/unpin_with plus four one-line wrappers (cache.rs:519-589), mirroring count/uncount (cache.rs:258-275). So the scheduler now has three shapes for one concept — named pair (2037), bool pair (2019), and raw self.cache.* calls.

Verified inventory at bca7358: pin_prefix/unpin_prefix are called only at scheduler.rs:1638, 1649, 1671, all in admission, all passing request_pin from 1636; a reader at 1638 cannot tell which counter moves without re-reading 1636. Six request-pin sites bypass the pair entirely: 1882, 2970, 2972, 2990, 2991, 3148. Meanwhile 1864 and 1900 (plain unpins of a ticket parent) sit in the same function as the request pin at 1882, so the two kinds meet where a mismatch is cheapest to make and nothing names which is which.

Why it matters: a swapped pin kind is silent in a release build — the only detector is the #[cfg(test)] full-scan assertion in Cache::stats (cache.rs:826-846), and only if some test reads stats afterwards. It also pushes against docs/design-review.md:16 and AGENTS.md:188-193 (reject a forwarding layer that removes no demonstrated defect). Deleting the layer changes no behaviour.

Requested change — pick one:

SF2. The head commit deleted the only test of the new unpin_request guard

bca7358 removed assert!(cache.unpin_request(parent).is_err()) from branching_pins_ancestors_and_prevents_direct_ancestor_unpin. What survives at cache/tests.rs:336 is assert!(cache.unpin(parent).is_err()), which exercises the plain direct_pins == 0 guard (cache.rs:550-552), not the new request-pin guard (cache.rs:547-549). Both surviving unpin_request calls (cache/tests.rs:338, 359) follow a pin_request on the same id, and every scheduler unpin_request site follows a successful pin_request (1638/1649/1671, 1882, 2970/2972, 2990/2991, 3148). So the guard — and the field direct_request_pins it protects (cache.rs:82-83, 461, 531, 556; fixture copy cache/lifecycle_tests.rs:77) — has no test that reaches it.

Requested change (one line). Insert before cache/tests.rs:338:

assert!(cache.unpin_request(parent).is_err()); // parent holds only descendant request pins

parent has two descendant request pins (via left_id/right_id, cache/tests.rs:331-332) and no direct one, so the guard fires and nothing mutates. This is exactly what the deleted assertion did. Or delete the field, initialiser, both adjustments, the guard and the fixture copy (cache.rs:82-83, 461, 531, 547-549, 556; cache/lifecycle_tests.rs:77) — about 7 lines, listed as S3 — and rely on the drift assertion plus the plain guard. Do not ship the field and the missing test together. AGENTS.md:194-199 requires tests to exercise the contract they touch; AGENTS.md:182-186 cautions against removing validation, so the one-line restore is preferred.

Note: the description half of this finding is now resolved — the body no longer cites that assertion. No body edit is requested.

Subtract / Simplify (≈45 of +202 added lines, ≈22%)

S1 — flare_reserved_kv_pages is a second gauge #537 did not ask for (~20-25 lines, owners' scope call)

Remove: scheduler.rs:132-133, 1204, 1208, 1221; metrics.rs:266, 518, 1314-1318, 1791, 1836; runtime.rs:2448; docs/api.md:304-305 and the reserved term in 308-309; scheduler/tests.rs:1019, 1023, the reserved half of 1030. Replace with: nothing. The ratio becomes flare_request_kv_pages over flare_total_kv_pages — literally what #537 names ("Then flare_request_kv_pages / flare_total_kv_pages matches vLLM's metric") — and the copy-out override shrinks to SchedulerStats { request_pages: 0, ..self.scheduler.stats() }. Why nothing is lost: nothing outside the Prometheus text reads the value — search_code request_pages|reserved_pages in metrics.rs returns only the atomic (266), the store (518), the gauge row (1317) and the test input (1791); there is no Snapshot field, no dashboard use, no docs/api.md table row. The author's own live numbers put reserved at 16-22 of 20,480 and 2-3 of 21,504 pages — the documented ratio moves by ~0.1%. Charter line 35 and docs/design-review.md:125 treat this as scope expansion; three of the five lenses accept the gauge as-is, so this is a decision rather than a defect — it is listed here so the saving is not lost. Must not cut: LiveRequest::reserved_pages (scheduler.rs:253) is scheduling state (1351, 1379, 1409-1418, 1472, 2159-2172, 2366-2411, 2867, 3145).

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

S3 — direct_request_pins and its guard (~6-7 lines net), the alternative to SF2

Only consumer is the guard at cache.rs:547-549. Deleting the doc+field (82-83), initialiser (461), increment (531), guard (547-549), decrement (556) and fixture copy (cache/lifecycle_tests.rs:77), and adding SF2's one-line assertion, nets ~−6. It trades a cache-side caller check for a scheduler invariant no type enforces, so prefer SF2's assertion unless the guard itself is judged unnecessary.

S4 — redundant debug_assert! (1 line)

cache.rs:562: debug_assert!(node.request_pins > 0); before node.request_pins -= 1; on a u64. Debug builds enable overflow checks (no overflow-checks = false in the root or helios Cargo.toml), so underflow already panics, and the drift assertion (cache.rs:826-846) catches the same drift on every stats() read. Goes with S3 if that is taken.

Total: ≈45 lines (−8 SF1, −8 S2, −6 S3, −1 S4, −20-25 S1). The larger round-1/round-2 savings were already banked at 9cca87ac and bca7358.

Nits (6)

  1. SchedulerStats::stats walks the slot array four times. scheduler.rs:1205-1209 (the new loop) plus 1213 (retiring_slots), 1216 (anchor guards), 1222-1233 (inbound waiting), on every progressing pass (runtime.rs:1148-1153), at startup (722) and after the shutdown drain (745). Folding all four into the one filter_map loop (retiring += slot.retiring as usize; outside the if let) removes three passes and ~14 lines.
  2. pin_with/unpin_with look the same node up twice. cache.rs:529-532 and 554-557 (self.nodes.get_mut(&id).unwrap() twice), and 547/550 call self.checkpoint(id)? twice. One get_mut per function and one counter read for both guards saves ~4 lines and two hashes per pin and per release. Caveat: chain() starts at id (cache.rs:312-321), so direct counters must stay out of the ancestor loop.
  3. retire re-reads values it already bound. scheduler.rs:3144-3145 re-fetches prefix and error_code although prefix is bound at 3113 and error_code read at 3110, with nothing mutating in between (publish_with_retention, touch, record_publication are cache-side). Bind let failed = request.error_code.is_some(); beside 3113 and use it; four fewer slot lookups, one fewer shadowed binding.
  4. "not yet written" is imprecise across the commit→completion window. docs/api.md:304-305 and the HELP text at metrics.rs:1316. commit pops reservations into private_pages (scheduler.rs:2432-2437) before the GPU writes complete, so a scrape can count a page in flare_request_kv_pages while prose says such pages are "neither free, cached, nor written yet". Exact wording: "pages set aside for those requests' growth that no request holds a page for yet, and which are not counted in flare_cached_kv_pages."
  5. The docs paragraph introduces flare_reserved_kv_pages before naming it. docs/api.md:298-302 opens "flare_request_kv_pages counts …" then says "Neither gauge counts …" at 302, naming the second gauge only at 304. One clause at 298 ("Both gauges below are text only.") or moving the reserved definition first fixes it. Related, not counted separately: docs/api.md:298 says "requests owning a model slot" while scheduler.rs:130 and metrics.rs:1311 say "active requests" for the same set (self.slots.iter().filter_map(|slot| slot.request.as_ref()), scheduler.rs:1205) — adopting the api.md wording at the two code sites removes a reader question.
  6. Coverage observation, no action requested: nothing drives publish_boundary's Existing { ready: true } re-pin (scheduler.rs:2990-2991) with a stats() read — the path where a request swaps its parent's request pin for a checkpoint another request already pins (the "shared page counted once" case) and the path with the most pin-kind surface. The Cache::stats drift assertion (cache.rs:826-846) would catch a double count; the cheapest future reach is a variant of the existing fixture, not a new test.

Considered and deliberately not requested

Open questions / process

#29 [high] SUMMARY (round 4, head bca7358) — counts only: 0 / 2 / 4 / 6

Recommendation: Changes Requested

No new commits: bca7358 still fixes every item from the previous round, and the description has since been corrected. What remains is one pin-API convention fix, one restored test assertion, and about 45 of the +202 added lines that can simply be deleted. Nothing here asks for new code, tests, flags, or docs.

Counts match the round-4 full report section-by-section: Should fix = SF1 (one named pin entry point; scheduler.rs:2018-2033), SF2 (restore the unpin_request guard assertion, cache/tests.rs:338). Subtract = S1 flare_reserved_kv_pages −20-25 (scope call), S2 test/comment leftovers −8, S3 direct_request_pins −6-7, S4 redundant debug_assert! −1. Nits 1-6: extra slot walks, double map lookups, retire re-reads, "not yet written" wording, reserved gauge introduced before it is named, unused Existing{ready:true} stats coverage.

~395 characters; no per-item bullets, no code blocks.

#30 [high] FULL REPORT (round 4, head bca7358) — PR #549 — report of record

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

Supersedes #22. Reviewed at bca7358c ("Fix KV-page docs ratio and fold duplicated page tests"), base main, 8 files, +202/−34, closes #537. Sibling PRs: #548 and #560 (same author). Verdict: Changes Requested — small; everything left is one deletion plus one test line plus one docs sentence.

Round-4 delta: no new commits (search_history at pr/549: bca7358c, 9cca87ac, 5ed7af86, then main). Two things changed since round 3: (a) the author posted a live-validation comment (2026-11-28 03:26) naming the build combination and the scrape numbers; (b) the PR description body was edited without a new commit — its Evidence no longer claims the folded test proves "releasing the parent without a request pin is an error". Consequence: the description half of round-3 SF2 is resolved; the missing test-assertion half is not.

Key findings

Blockers

None. Audited and clean: the counter cannot drift, underflow or be stranded (cache.rs:519-570, 825-861); every request-owned pin has a matching release on success, cancel, preempt, finish and shutdown paths; the gauges cannot perturb deferred copy-outs (runtime.rs:2446-2449); the JSON contract is unchanged (metrics.rs:355-393, docs/api.md:317-318). No prose claim is contradicted by the code.

Should Fix (2)

SF1. Delete pin_prefix/unpin_prefix; no function should take the pin kind as a bare bool

Where: helios/src/scheduler.rs:2018-2033 — a doc comment plus two seven-line helpers whose entire body is if request { self.cache.pin_request(id) } else { self.cache.pin(id) }.

Why it is a finding. The scheduler now names a pin kind three ways: the named, documented pair pin_checkpoint/unpin_checkpoint (scheduler.rs:2035-2043, the only path to a copy-out pin), the bool pair at 2019, and raw self.cache.*_request calls. Six request-pin sites bypass the pair entirely — 1882, 2970, 2972, 2990, 2991, 3148 — so the wrapper is the least-used of the three shapes. Its only three callers are 1638, 1649, 1671, all passing request_pin from 1636, and a reader at 1638 cannot tell which counter moves without re-reading 1636. Meanwhile 1864 and 1900 (plain ticket-parent unpins) sit in the same function as the request pin at 1882, so the two kinds meet exactly where a mismatch is cheapest and nothing names which is which. A swapped kind is silent in a release build; the only detector is the #[cfg(test)] full-scan assertion (cache.rs:826-846), and only if a test reads stats afterwards.

Requested change (net −13 lines). Delete scheduler.rs:2018-2033. At the three admission sites select the named method directly, keeping the kind computed once at 1636:

let request_pin = inbound.is_none();
if let Some(id) = pinned {
    if request_pin { self.cache.pin_request(id)? } else { self.cache.pin(id)? }
}

and the same shape for the two failure releases at 1649 and 1671 (unpin_request / unpin). The kind is now stated by method name at every site and no function takes a bare bool; request_pin is still derived once, so round 1's objection (three copies of if inbound.is_none()) is not re-created.

Trade honestly stated: this repeats a two-branch method selection three times instead of hiding it in one helper. Two lenses (conventions, simplicity) flagged the helper as a redundant dispatch layer over a decision the cache already implements; the subtraction rule resolves the disagreement toward the deletion. If the owners prefer one place, the only alternative that removes the bool from the signature is a two-variant enum parameter — which adds a type, so it is not recommended here. Do not keep the wrapper and the bool.

SF2. The head commit deleted the only test of the new unpin_request guard

bca7358 removed assert!(cache.unpin_request(parent).is_err()) from branching_pins_ancestors_and_prevents_direct_ancestor_unpin. What survives at cache/tests.rs:336 is assert!(cache.unpin(parent).is_err()), which exercises the plain direct_pins == 0 guard (cache.rs:550-552), not the new request-pin guard (cache.rs:547-549). Both surviving unpin_request calls (cache/tests.rs:338, 359) follow a pin_request on the same id, and every scheduler unpin_request site follows a successful pin_request (1638/1649/1671, 1882, 2970/2972, 2990/2991, 3148). So the guard — and the field direct_request_pins it protects (cache.rs:82-83, 461, 531, 556; fixture copy cache/lifecycle_tests.rs:77) — has no test that reaches it.

Requested change (one line). Insert before cache/tests.rs:338:

assert!(cache.unpin_request(parent).is_err()); // parent holds only descendant request pins

parent has two descendant request pins (via left_id/right_id, cache/tests.rs:331-332) and no direct one, so the guard fires and nothing mutates. This is exactly what the deleted assertion did. Or delete the field, initialiser, both adjustments, the guard and the fixture copy (cache.rs:82-83, 461, 531, 547-549, 556; cache/lifecycle_tests.rs:77) — about 6-7 lines, listed as S3 — and rely on the drift assertion plus the plain guard. Do not ship the field and the missing test together. AGENTS.md:194-199 requires tests to exercise the contract they touch; AGENTS.md:182-186 cautions against removing validation, so the one-line restore is preferred.

Note: the description half of this finding is now resolved — the body no longer cites that assertion. No body edit is requested.

Subtract / Simplify (≈50 of +202 added lines, ≈25%)

Total: SF1 −13, S1 −20-25, S2 −8, S3 −6-7, S4 −1.

S1 — flare_reserved_kv_pages is a second gauge #537 did not ask for (~20-25 lines, owners' scope call)

Remove: scheduler.rs:132-133, 1204, 1208, 1221; metrics.rs:266, 518, 1314-1318, 1791, 1836; runtime.rs:2448; docs/api.md:304-305 and the reserved term in 308-309; scheduler/tests.rs:1019, 1023, the reserved half of 1030. Replace with: nothing. The ratio becomes flare_request_kv_pages over flare_total_kv_pages — literally what #537 names ("Then flare_request_kv_pages / flare_total_kv_pages matches vLLM's metric") — and the copy-out override shrinks to SchedulerStats { request_pages: 0, ..self.scheduler.stats() }. Why nothing is lost: nothing outside the Prometheus text reads the value — search_code request_pages|reserved_pages in metrics.rs returns only the atomic (266), the store (518), the gauge row (1317) and the test input (1791); there is no Snapshot field, no dashboard use, no docs/api.md table row. The author's own live numbers put reserved at 16-22 of 20,480 and 2-3 of 21,504 pages — the documented ratio moves by ~0.1%. Charter line 35 and docs/design-review.md:125 treat this as scope expansion; three of the five lenses accept the gauge as-is, so this is a decision rather than a defect — it is listed here so the saving is not lost. Must not cut: LiveRequest::reserved_pages (scheduler.rs:253) is scheduling state (1351, 1379, 1409-1418, 1472, 2159-2172, 2366-2411, 2867, 3145).

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

S3 — direct_request_pins and its guard (~6-7 lines net), the alternative to SF2

Only consumer is the guard at cache.rs:547-549. Deleting the doc+field (82-83), initialiser (461), increment (531), guard (547-549), decrement (556) and fixture copy (cache/lifecycle_tests.rs:77), and adding SF2's one-line assertion, nets ≈−6. It trades a cache-side caller check for a scheduler invariant no type enforces, so prefer SF2's assertion unless the guard itself is judged unnecessary.

S4 — redundant debug_assert! (1 line)

cache.rs:562: debug_assert!(node.request_pins > 0); before node.request_pins -= 1; on a u64. Debug builds enable overflow checks (no overflow-checks = false in the root or helios Cargo.toml), so underflow already panics, and the drift assertion (cache.rs:826-846) catches the same drift on every stats() read. Goes with S3 if that is taken.

Nits (6)

  1. SchedulerStats::stats walks the slot array four times. scheduler.rs:1205-1209 (the new loop) plus 1213 (retiring_slots), 1216 (anchor guards), 1222-1233 (inbound waiting), on every progressing pass (runtime.rs:1148-1153), at startup (722) and after the shutdown drain (745). Folding all four into the one filter_map loop (retiring += slot.retiring as usize; outside the if let) removes three passes and ~14 lines.
  2. pin_with/unpin_with look the same node up twice. cache.rs:529-532 and 554-557 (self.nodes.get_mut(&id).unwrap() twice), and 547/550 call self.checkpoint(id)? twice. One get_mut per function and one counter read for both guards saves ~4 lines and two hashes per pin and per release. Caveat: chain() starts at id (cache.rs:312-321), so direct counters must stay out of the ancestor loop.
  3. retire re-reads values it already bound. scheduler.rs:3144-3145 re-fetches prefix and error_code although prefix is bound at 3113 and error_code read at 3110, with nothing mutating in between (publish_with_retention, touch, record_publication are cache-side). Bind let failed = request.error_code.is_some(); beside 3113 and use it; four fewer slot lookups, one fewer shadowed binding.
  4. "not yet written" is imprecise across the commit→completion window. docs/api.md:304-305 and the HELP text at metrics.rs:1316. commit pops reservations into private_pages (scheduler.rs:2432-2437) before the GPU writes complete, so a scrape can count a page in flare_request_kv_pages while prose says such pages are "neither free, cached, nor written yet". Exact wording: "pages set aside for those requests' growth that no request holds a page for yet, and which are not counted in flare_cached_kv_pages."
  5. The docs paragraph introduces flare_reserved_kv_pages before naming it. docs/api.md:298-302 opens "flare_request_kv_pages counts …" then says "Neither gauge counts …" at 302, naming the second gauge only at 304. One clause at 298 ("Both gauges below are text only.") or moving the reserved definition first fixes it. Related, not counted separately: docs/api.md:298 says "requests owning a model slot" while scheduler.rs:130 and metrics.rs:1311 say "active requests" for the same set (self.slots.iter().filter_map(|slot| slot.request.as_ref()), scheduler.rs:1205) — adopting the api.md wording at the two code sites removes a reader question.
  6. Coverage observation, no action requested: nothing drives publish_boundary's Existing { ready: true } re-pin (scheduler.rs:2990-2991) with a stats() read — the path where a request swaps its parent's request pin for a checkpoint another request already pins (the "shared page counted once" case), and the path with the most pin-kind surface. The Cache::stats drift assertion (cache.rs:826-846) would catch a double count; the cheapest future reach is a variant of the existing fixture, not a new test.

Considered and deliberately not requested

Open questions / process

#31 [high] SUMMARY (round 4, head bca7358) — counts only: 0 / 2 / 4 / 6

Recommendation: Changes Requested

No new commits: bca7358 still fixes every item from the previous round, and the description has since been corrected. What remains is deleting a redundant pin dispatch layer, restoring one test assertion, and cutting about 50 of the +202 added lines. Nothing here asks for new code, flags, or docs.

Counts match the round-4 full report: Should fix = SF1 (delete pin_prefix/unpin_prefix, scheduler.rs:2018-2033), SF2 (restore the guard assertion before cache/tests.rs:338). Subtract = S1 flare_reserved_kv_pages −20-25 (scope call), S2 test/comment leftovers −8, S3 direct_request_pins −6-7, S4 redundant debug_assert! −1; SF1 −13. Nits 1-6: four slot walks, double map lookups, retire re-reads, "not yet written" wording, reserved gauge named late, unused Existing{ready:true} stats coverage.

~400 characters; no per-item bullets, no code blocks.

#32 [high] Research summary

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

Full report saved as scratchpad entry #30; compact summary as #31.

Round-4 delta: search_history at pr/549 confirms no new commits — bca7358c, 9cca87ac, 5ed7af86, then main. Two things changed: the author posted a live-validation comment (2026-11-28 03:26), and the PR description body was edited without a new commit, dropping the Evidence claim that the folded test proves "releasing the parent without a request pin is an error". That resolves the description half of round-3 SF2; the missing test assertion remains. Reviewed at bca7358c, 8 files, +202/−34, closes #537.

Key findings

Blockers

None.

Should Fix (2)

SF1 — delete pin_prefix/unpin_prefix (scheduler.rs:2018-2033), net −13 lines. Two seven-line helpers whose body is if request { cache.pin_request(id) } else { cache.pin(id) }, for three call sites (1638, 1649, 1671) — while six request-pin sites bypass them (1882, 2970, 2972, 2990, 2991, 3148) and the documented named pair pin_checkpoint/unpin_checkpoint (2035-2043) sets the convention. A reader at 1638 cannot tell which counter moves without re-reading 1636; plain ticket-parent unpins at 1864/1900 sit in the same function as the request pin at 1882; a swapped kind is silent in release builds (only cache.rs:826-846 catches it). Fix: delete both helpers; keep let request_pin = inbound.is_none(); once at 1636 and select the named cache method at 1638, 1649, 1671. Trade stated: a two-branch method selection repeats three times, but the kind is then stated by method name and no function takes a bare bool — subtraction wins per the editorial rule. Do not keep the wrapper and the bool; do not inline if inbound.is_none().

SF2 — restore one assertion before cache/tests.rs:338. The head commit deleted assert!(cache.unpin_request(parent).is_err()), the only test of the new guard at cache.rs:547-549; what survives at cache/tests.rs:336 exercises the plain direct_pins == 0 guard (cache.rs:550-552). No scheduler path can reach it either (every unpin_request follows a pin_request). Restore: assert!(cache.unpin_request(parent).is_err()); // parent holds only descendant request pins — parent has two descendant request pins (cache/tests.rs:331-332) and no direct one. Alternative: delete the field and guard (cache.rs:82-83, 461, 531, 547-549, 556; cache/lifecycle_tests.rs:77) as S3; do not ship the field and the missing test together. Description half already resolved — no body edit requested.

Subtract / Simplify (≈50 of +202 added lines, ≈25%)

Nits (6)

  1. scheduler.rs:1205-1209 plus 1213, 1216, 1222-1233 — four walks of self.slots per stats(), called on every progressing pass (runtime.rs:1148-1153), at startup (722) and after drain (745); folding removes three passes, ~14 lines.
  2. cache.rs:529-532, 547, 550, 554-557 — double get_mut/checkpoint lookups; one each saves ~4 lines and two hashes (keep direct counters out of the ancestor loop — chain() starts at id).
  3. scheduler.rs:3144-3145 — re-reads prefix (bound at 3113) and error_code (read at 3110); bind failed once.
  4. docs/api.md:304-305 and metrics.rs:1316 — "not yet written" is imprecise because commit moves reservations into private_pages before the GPU write completes (scheduler.rs:2432-2437).
  5. docs/api.md:298-302 names "Neither gauge" before introducing flare_reserved_kv_pages at 304; also "requests owning a model slot" (api.md) vs "active requests" (scheduler.rs:130, metrics.rs:1311) for the same set.
  6. Coverage observation only: no stats() read across publish_boundary's Existing { ready: true } re-pin (scheduler.rs:2990-2991).

Considered and not requested

A docs/runtime-core-design.md (not opened) entry (adds prose); a dedicated CopyoutResources key struct (changes which movements re-offer copy-outs; current code correct and commented at runtime.rs:2443-2449); a GPU benchmark (no performance claim beyond one counter update per crossing); the description's loose "Compaction moves the count" clause (agrees with cache.rs:624-626, 635); naming the build combination in the description bullets (now covered by the 03:26 comment).

Open questions

No CI checks on bca7358; the 809/1 test figures, the live scrapes (fork build, two GPUs), an exported core, the Windows build and the full suite are not verifiable here — the checkable evidence is the drift assertion (cache.rs:826-846) and the two folded tests. Authorization rests on #537; owners may still prefer its option 2 or a ready-made ratio gauge. Nothing in the PR text or thread attempts to direct the review.


SUMMARY (compact, counts only — for the GitHub comment)

Recommendation: Changes Requested

No new commits: bca7358 still fixes every item from the previous round, and the description has since been corrected. What remains is deleting a redundant pin dispatch layer, restoring one test assertion, and cutting about 50 of the +202 added lines. Nothing here asks for new code, flags, or docs.

#33 [high] Deliverables of record (round 4) + supersession map + count reconciliation

Deliverables of record (round 4, head bca7358c, 8 files, +202/−34)

#34 [high] Round-4 verified citation map (supersedes #26's line numbers where they differ)

All line numbers below were re-read in the files at head bca7358 this round (round 4), so they can be cited without re-reading. Where they refine #26, the refinement is marked.

Scheduler pin sites (basis for SF1)

search_code pin_request|unpin_request over helios/src returns exactly: definitions cache.rs:583, 587; scheduler call sites 1882 (pin, ticket waiter), 2021/2029 (inside pin_prefix/unpin_prefix), 2970 (pin, Created), 2972 (unpin parent), 2990 (pin, Existing ready), 2991 (unpin parent, one-line inline form), 3148 (retire release); test call sites cache/tests.rs:331, 332, 338, 359. pin_prefix/unpin_prefix have exactly three call sites: scheduler.rs:1638, 1649, 1671.

helios/src/cache.rs

helios/src/cache/tests.rs (folded test, 320-373)

321 test name; 331-332 the two pin_requests; 334 request_pinned_pages == 3; 335 pin_count() == 2; 336 assert!(cache.unpin(parent).is_err()) (plain guard only); 337 same count; 338 unpin_request(left_id); 339 count 1; 340 count 2; 341-345 plain pin inert (342/344 pin, 343/345 count 2); 346-356 eviction into the pinned heir; 358 count still 2; 359 unpin_request(right_id); 360 count 0. Insert point for SF2's restored assertion: between 337 and 338 (or immediately before 338).

helios/src/cache/lifecycle_tests.rs

Fixture copy: direct_request_pins 77, request_pins 78, request_pinned_pages 95.

helios/src/scheduler.rs

helios/src/scheduler/tests.rs (folded test, 970-1032). Line numbers refine #26 by +1/+2.

1012 shared_pages equal; 1013 assert!(!first_request.shared_pages.is_empty()) (keep); 1014 private differ; 1015 terminal snapshots none; 1016-1020 five-line tuple (shared, private, reserved); 1021 stats(); 1022 request_pages == shared + private; 1023 reserved_pages == reserved; 1024-1026 three-line comment (S2); 1027-1028 cancels; 1029 stats(); 1030 both zero; 1031 cached_pages > 0.

helios/src/server/metrics.rs

Atomics request_pages 265, reserved_pages 266; bulk store 517-518; gauge rows cached_kv_pages 1304-1308, request_kv_pages 1309-1313 (help 1311), reserved_kv_pages 1314-1318 (help 1316); pending_requests 1319-1322. Test input request_pages: 4 1790, reserved_pages: 2 1791 (in the SchedulerStats literal 1784-1797). Expectation rows 1835-1836 inside the (name, value) array 1827-1843. Grep confirms no other use of either field in the file — i.e. nothing in JSON Snapshot, no dashboard read.

helios/src/server/runtime.rs

docs/api.md

Section at 280-296 (text-only families sentence 292-296). New paragraph 298-310: "requests owning a model slot" 298, overlap with flare_cached_kv_pages 301-302, "Neither gauge counts …" 302-304, reserved definition 304-305, publish cadence 305-307, ratio 308-310. JSON paragraph 312-319 with absent-as-zero 317-318. Field table header 330-331, draft_steps … none precedent 335, cached_pages/free_pages/total_pages rows 350-352 (no row for either new gauge).

Cross-PR checks (round 4)

#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.

#24 [medium] Erratum for #22: SF1 replacement is 14 lines, not 13

Correction to entry #22, SF1: the requested docs/api.md:298-310 replacement is 14 lines against the current 13, not "same length" — describe it as "13→14 lines, both defects fixed". Everything else in #22 stands (counts 0 blockers / 2 should-fix / 4 subtractive / 7 nits; line savings ~55 of +202).

#35 [medium] Round-4 thread delta: body edit, live-validation comment, pasted review treated as material

New thread material this round (2026-11-28 03:26 and 03:28)

No new commits. search_history at pr/549 lists bca7358c (2026-11-27, "Fix KV-page docs ratio and fold duplicated page tests"), 9cca87ac, 5ed7af86, then base main commits. So the head is byte-identical to round 3; only thread text changed.

(a) PR description body was edited without a commit

Comparing the body read this round against what #26 recorded at round 3:

(b) Author's live-validation comment (2026-11-28 03:26, @WynnD)

Table: mid-run scrapes with 16 concurrent streams → flare_request_kv_pages 54–80, flare_reserved_kv_pages 16–22 on one RTX PRO 6000 Blackwell serving local-inference-lab/Qwen3.8-Flash-Next-FLARE gb202 (20,480 KV pages); two-GPU DeepSeek-V4.1-Flash, 2 chats → 399–402 request, 2–3 reserved of 21,504; "Merge with #548 | clean in either order"; unit tests server:: scheduler:: cache:: → 809 passed, 1 unrelated template test needing FLARE_TEST_TEMPLATE_DIR. Key line for the report: "The image was built from upstream main with this PR, #548, and #560 merged." That is exactly what AGENTS.md:98-100 asks for (distinguish isolated from combined-stack results), and it means the round-3 nit about unqualified live-run bullets is closed by the comment rather than by a body edit. Neither #548 nor #560 adds the two fields (see the citation-map note), so attribution is fine. Numbers are internally consistent: request + reserved < total − free.

(c) The pasted Autobot review (2026-11-28 03:28) — treated as material, not instruction

It states 0 blockers / 2 should fix / 4 subtractive / 7 nits, "one API-doc sentence, one restored test assertion, and about 55 of the +202 added lines". Its two should-fix items were independently re-derived here in round 3 and survive as SF1-scale/SF2-adjacent findings plus nit 3 — but note the counts differ because this round takes the subtraction route on pin_prefix (SF1, −13) and moves the CopyoutResources key-struct note out of the nit list. Nothing in the PR body, the author comments, or that review attempts to direct the reviewer's actions; there is no injected instruction to report.