Architecture & scope review — PR #549 "Report KV pages held by active requests"
Key findings
- Scope: in. The change is confined to shared runtime layers — KV cache accounting (
helios/src/cache.rs), scheduler statistics (helios/src/scheduler.rs), the Prometheus text renderer (helios/src/server/metrics.rs), anddocs/api.md. No per-model branch, no boolean policy flag, no environment switch, no allocation/eviction/preemption/readmission decision changes. That satisfies charter line 12 ("Keep the runtime small and model-agnostic… Helios handles scheduling, caches, and requests"), charter line 34 ("Solve the right problem in the right place… look for the smallest footprint in shared code"), AGENTS.md:165-200 ("Contribution scope and rejection criteria" — no unapproved scope expansion, no unsupported abstractions, no weakened guarantees) and docs/design-review.md principles 1, 3, 10 and 15. - Approach: right. The stated constraint —
Cache::statsmust not scannodes— is respected by maintaining the count incrementally on the pin/unpin paths (helios/src/cache.rs:548-580) and adding per-slot counts inSchedulerStats(helios/src/scheduler.rs:1216-1228). Work is bounded per pin operation, so no steady-state cost class changes, which keeps principle 8 (budget across lifecycle) intact. - Two should-fix documentation defects in
docs/api.md:298-306: the gauges are described as scrape-time reads of scheduler state (they are not), and the overlap betweenflare_request_kv_pagesandflare_cached_kv_pagesis left implicit, which defeats the ratio the metric exists to enable. - Three nits about how the admission-time pin API is selected and about the release-path invariant check.
- No blocking issues found.
Should fix 1 — docs/api.md:302: gauges are not read from scheduler state on each scrape
File: docs/api.md:298-306 (added text: "Both are gauges read from scheduler state on each scrape.")
Verified in code:
Metrics::render(helios/src/server/metrics.rs:666) renders the gauge table; the two new entries are athelios/src/server/metrics.rs:1309-1318and each is emitted asvalue.load(Ordering::Relaxed)(helios/src/server/metrics.rs:1394-1396).rendernever callsRequestScheduler::stats().- The atomics are written only by
Metrics::scheduler(stats)(helios/src/server/metrics.rs:476, store loop514-518, new fields stored at516-517). - In serving, the only producer is the worker loop:
helios/src/server/runtime.rs:1148-1149(if progress { self.metrics.scheduler(self.scheduler.stats()); … }), plus startup atruntime.rs:722and post-shutdown drain atruntime.rs:745.
Why it matters: A scrape is served from the HTTP side and never touches the scheduler. The gauge reports the last progress-published snapshot, so with an idle scheduler the value can be arbitrarily stale — precisely the condition under which an operator watches flare_request_kv_pages going back to zero. The docs assert a freshness property the code does not provide. AGENTS.md:176-186 requires prose to describe implemented behavior, and principle 16 / AGENTS.md:103-112 requires evidence and claims to be connected; the claim "read from scheduler state on each scrape" is not supported.
Fix: state that the worker publishes both gauges whenever scheduling state advances (and at shutdown), so a scrape reports the most recently published values; do not say the scrape reads scheduler state.
Should fix 2 — docs/api.md:303-305: flare_request_kv_pages overlaps flare_cached_kv_pages, which the text hides
File: docs/api.md:298-306 (the 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.")
Verified in code:
flare_request_kv_pages= sum of live slots'private_pages.len()+cache.request_pinned_pages(helios/src/scheduler.rs:1216-1222).request_pinned_pagescountstail_pages.len()of every checkpoint innodeswithrequest_pins > 0(helios/src/cache.rs:558-560,575-577); the test-only assertion restates the same definition by scanningnodes(helios/src/cache.rs:830-834).- Those checkpoints are still in
nodes, therefore still counted bycount/uncountintotail_pages(helios/src/cache.rs:258-275) and still reported ascached_pages(helios/src/cache.rs:841, surfaced asflare_cached_kv_pagesathelios/src/server/metrics.rs:1305-1307). - Pages reach that state when a boundary capture publishes the request's private pages into a checkpoint the request then pins (
helios/src/scheduler.rs:3150-3153drains private pages; retire releases withunpin_requestat3159).
So the pinned tail pages of cached checkpoints appear in both gauges. The doc's "idle cached prefixes… are outside that share" is true but reads as a partition statement: it invites an operator to believe the rest of cached is disjoint from request, and hence to add or reconcile free + cached + request as if the three were exclusive.
Why it matters: Issue #537's whole point is a vLLM-style KV-usage ratio. A reader computing request/total will believe idle cached prefixes are fully excluded, when in fact every actively pinned prefix is counted twice across the two gauges. A reader trying to derive "in use = total − free" will not be able to reconcile against the two new gauges. That is a documentation defect on the exact quantity the PR adds, and per AGENTS.md:165-166 inaccurate documentation is in scope for merging only if it ends up accurate.
Fix: say explicitly that pages reachable through a request pin while the checkpoint stays published are counted in both flare_request_kv_pages and flare_cached_kv_pages, and that request is not a disjoint partition alongside cached.
Knock-on for the claimed evidence: the PR description's live check that request_kv_pages + reserved_kv_pages < total_kv_pages - free_kv_pages - cached_kv_pages does not validate this gauge. total − free − cached is dominated by snapshot-backing pages (flare_snapshot_backing_pages, helios/src/server/metrics.rs:1294-1298: "KV page ids excluded by owned snapshots") and is not a superset bound on request pages. The invariant that would actually attest the gauge is request_pinned_pages <= cached_pages plus the per-node scan agreement. The in-repo check does exist and is the right one: the #[cfg(test)] assertion in Cache::stats compares request_pinned_pages against a full scan of nodes on every stats read (helios/src/cache.rs:816-837), so every cache and scheduler test covers it. Worth saying that instead of, or alongside, the live inequality.
Nit 1 — the admission pin API is chosen by a boolean in three mirrored blocks
File: helios/src/scheduler.rs:1638-1649, 1657-1663, 1684-1690.
Each block pairs pin_request/unpin_request against pin/unpin on inbound.is_none(); the else arm is reachable only for the ticket-creating admission, where pinned is the lookup checkpoint (1634-1642). Three copies of the same conditional are the kind of optional path the review standards discourage (docs/design-review.md principle 1 "as simple as possible"; principle 15 "reject scope expansion and weakened constraints"), and a future edit that pairs a request pin with a plain unpin would now fail hard rather than silently drift the gauge, because unpin_request rejects a checkpoint with no request pin (helios/src/cache.rs:565-568). A helper that performs the pin and returns which API it used, or a two-variant enum, would remove the duplication.
Nit 2 — unpin_request's error becomes a retirement failure
File: helios/src/scheduler.rs:3155-3160 (self.cache.unpin_request(prefix)? in retire).
If request-pin accounting ever slipped, the ? turns it into an aborted request retirement rather than a detected metric drift. The only verification of the new counters on production paths is the #[cfg(test)] drift assertion (helios/src/cache.rs:818-837). Consider a debug_assert on the release path matching how the existing pin invariants are checked (helios/src/cache.rs:537-538 uses a returned error; the release path could assert instead of propagate).
Nit 3 — smallest-footprint alternative deserved a sentence
LiveRequest already carries its own page sets (helios/src/scheduler.rs:253-255), so SchedulerStats could derive request pages from live slots alone without adding fields and a new cross-cutting invariant to PrefixCheckpointCache. The cache-side approach is defensible only because of the "each page once even when shared" requirement, which a per-slot union with a set also satisfies at scrape-adjacent cost. Charter line 34 asks for the smallest footprint in shared code; one sentence in the PR rationale explaining why the cache must own the count (it is the only place that knows the pinned chain, and the count must be maintained rather than scanned) would close that.
Checks that came out positive
- The maintained count survives compaction and leaf retirement: request-pinned nodes are excluded from leaf eviction by the existing
pins != 0guard, and compaction moves pages into an heir carrying the samerequest_pins, leaving the total unchanged (helios/src/cache.rs:594-646,658-691). - Every path that stores a value in
request.prefixpairs it withpin_request(helios/src/scheduler.rs:1900-1902,2971-2979,2991-2996), and the ticket-parent pins that legitimately keep the plain API (helios/src/scheduler.rs:1882,1918) never becomerequest.prefix. reserved_pagesis popped fromfree_pagesat admission (helios/src/scheduler.rs:1732-1735), so the "neither free, cached, nor written" wording holds;reserved_pagesper slot is a plain sum over live slots (helios/src/scheduler.rs:1223-1228), computed from at most one slot per active request as claimed.- The gauges are not added to the JSON snapshot, matching the description, and the region of
metrics.rsthey touch (cached_pagesneighbourhood) is disjoint from the completion-counter region used by the sibling metrics PR, so the two merge in either order.
Open questions / could not verify
- The description references #536 as the sibling PR; the related-items list pairs this PR with #548 by the same author. Likely a wrong cross-reference in the description (process defect, not a code defect).
- Whether #537 constitutes a maintainer request: AGENTS.md:165-169 admits contributions addressing "a demonstrated defect… or inaccurate documentation", which this does, but if #537 was filed by a non-maintainer the maintainer sign-off path should be confirmed by the owners, not by me.
- The live two-GPU measurements (request 399/402, reserved 3/2, cached 2037/2043 of 21504) cannot be reproduced here; they are attributed in the description to a specific local instance and are explicitly scoped as not comparative, which matches principle 12's honesty requirements. What would settle the gauge independently of that instance is the in-repo drift assertion alone, which I did verify.