Architecture & scope review — PR #549 "Report KV pages held by active requests"
Reviewed at head 9cca87a (8 files, +246/−16: helios/src/{cache,scheduler,server/metrics,lifecycle_tests,tests}.rs, docs/api.md).
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, and no allocation, eviction, preemption, or readmission decision changes. That matches charter line 12 ("Keep the runtime small and model-agnostic. … Helios (the runtime) handles scheduling, caches, and requests"), charter line 34 ("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), anddocs/design-review.mdprinciples 1, 3, 12, 15, 16. - Approach: right. The stated constraint —
Cache::statsmust not scannodes— is respected: the count is maintained on the pin/unpin paths (helios/src/cache.rs:548-580) and the scheduler adds per-slot counts (helios/src/scheduler.rs:1216-1228). Work is bounded per pin operation, so no steady-state cost class changes and principle 8 (budget across the lifecycle) holds. - One should-fix documentation defect remains in
docs/api.md:307-310, plus three nits. Four findings from earlier rounds are fixed at this head (see "Previously reported, now fixed"). - No blocking issues found.
Should fix — docs/api.md:307-310 contradicts itself and gives no workable ratio
File: docs/api.md:307-310, current text:
"Reserved pages are outside the request gauge, so
flare_request_kv_pages + flare_reserved_kv_pagesis the figure comparable to another runtime's used KV cache. Dividing either gauge byflare_total_kv_pagesexcludes idle cached prefixes and snapshot backing pages"
Two incompatible instructions in adjacent sentences:
- Line 308 says the sum
request + reservedis the comparable figure. Line 309 then says dividing either gauge by total gives the share. Both cannot be true. By the author's own live scrapeflare_reserved_kv_pagesis 2–3 pages of 21504 (description, two concurrent streaming chats), soreserved / totalcarries no information about KV in use; the comparable ratio is(request + reserved) / total. - "Dividing … by
flare_total_kv_pagesexcludes idle cached prefixes and snapshot backing pages" misattributes the exclusion to the division. The denominator istotalfor every such division; what the numerator leaves out is a property of the numerator. Combined with line 298-300 ("tail pages of the prefix checkpoints they pin"), the sentence invites a reader to believe the whole ofcachedis excluded, which the preceding sentence at 303-306 correctly denies (pinned checkpoint pages appear in both gauges).
Why it matters: Issue #537 asks for a vLLM-style KV-usage figure. This is the only prose in the repository defining the ratio the metric exists to enable, and it is internally inconsistent, so an operator cannot tell whether to use request/total or (request + reserved)/total, and will mis-state what the numerator excludes. AGENTS.md:165-166 requires every contribution to address inaccurate documentation, and the repo-prose skill (.agents/skills/repo-prose/SKILL.md:26-29 (not opened)) requires documentation to be a present-state specification without contradictory claims; principle 16 requires prose a reviewer can reconstruct the argument from without the diff.
Fix: state exactly one ratio, (flare_request_kv_pages + flare_reserved_kv_pages) / flare_total_kv_pages, and state once what the numerator leaves out: idle cached prefixes, snapshot backing pages, pages draining through retirement, and an admission ticket's in-flight restore (all of which lines 301-307 already establish). Drop "either gauge".
Nits
Nit 1 — docs/api.md:311-312 documents a #[cfg(test)] assertion in the operator-facing API page.
The text reads "…and the test-only assertion in Cache::stats compares the maintained request-pinned count with a full scan of every checkpoint on each read." The claim itself is true (helios/src/cache.rs:816-837: a #[cfg(test)] assert_eq! comparing request_pinned_pages with a nodes scan). But it is validation evidence, which belongs in the PR description under design-review principle 16, not in a present-state API specification (SKILL.md:26-29: "Documentation is a present-state specification, not a changelog… do not write … defect reports, or run journals into any document"; SKILL.md:35-37 places evidence in the evidence channel). Drop it here and keep it in the PR body.
Nit 2 — docs/api.md:302 "on every scheduler pass" overstates the publish cadence.
The worker publishes only when a pass reports progress: helios/src/server/runtime.rs:1148-1149, if progress { self.metrics.scheduler(self.scheduler.stats()); } (plus startup at runtime.rs:722 and the post-shutdown drain at runtime.rs:745). Say "when scheduling state advances" so the freshness statement matches the code; a stalled scheduler legitimately leaves the gauge at its last published value.
Nit 3 — metric fields still feed a scheduling decision key.
CopyoutResources embeds the whole SchedulerStats (helios/src/server/runtime.rs:1053-1059) and is compared to decide whether deferred host copy-outs retry (runtime.rs:2455-2465). The head commit zeroes the two new fields when building the key (runtime.rs:2443-2450, with a comment explaining that decode moves request and reserved page counts without moving cache resources), which fixes today's behaviour but leaves the coupling intact: any gauge added to SchedulerStats later silently changes copy-out scheduling unless someone remembers to extend the zeroing list. Design-review principle 15 and AGENTS.md:188-193 discourage optional-path coupling of this kind. Fix: give CopyoutResources only the cache fields copy-out actually depends on (free_pages, free_snapshots, cached_pages, snapshot_backing_pages, …) so metrics cannot enter the key at all.
Previous findings at this head (fixed — do not re-raise)
- Fixed: the page used to say both gauges are read from scheduler state on each scrape.
docs/api.md:302-303now says the worker publishes and a scrape reads the last published values, which matchesmetrics.rs:1309-1318(plainloadof atomics) andMetrics::scheduler(metrics.rs:476). - Fixed: the overlap between
flare_request_kv_pagesandflare_cached_kv_pageswas hidden.docs/api.md:303-306now states that request-pinned checkpoint pages also appear inflare_cached_kv_pages. - Fixed: the three mirrored
inbound.is_none()pin-API blocks becamepin_prefix/unpin_prefix(helios/src/scheduler.rs:2025-2040) selected viarequest_pin(scheduler.rs:1643). - Fixed:
retirereleases the request pin before emptying the slot (helios/src/scheduler.rs:3149-3157), so theunpin_requesterror no longer fires afterrequest.take(). - Patched: the new gauges no longer leak into the host copy-out retry key (
runtime.rs:2443-2450) — though see Nit 3 for the residual coupling.
Checks that came out positive
- Reserved pages are genuinely "neither free, cached, nor written": popped from
free_pagesat admission (helios/src/scheduler.rs:1721-1724) and consumed intoprivate_pagesat commit (scheduler.rs:2439-2444);reserved_pagesis a plain sum over live slots, at most one slot per active request (scheduler.rs:1223-1228). - Retirement and in-flight ticket pages are outside both gauges:
finish_inboundpins waiters only after the restore completes (scheduler.rs:1887-1899); retired pages live inself.retired(scheduler.rs:3177-3191). - Request pin/unpin pairing covers every place that assigns
request.prefix(scheduler.rs:1891,2985,3002), and the ticket-parent pins that legitimately keep the plain API (scheduler.rs:1871,1907) never becomerequest.prefix.unpin_requestrejects a checkpoint with no request pin (cache.rs:565-568), making the API choice checkable rather than silent. - 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). - The new gauges stay out of the JSON
Snapshot(helios/src/server/metrics.rs:70-129), matching the description; they are rendered only as Prometheus text (metrics.rs:1309-1318).
Evidence critique (not a code defect)
The description's live consistency check request_kv_pages + reserved_kv_pages < total_kv_pages - free_kv_pages - cached_kv_pages does not attest the new 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, including pending GPU retirement"), so it is not a tight superset bound on request pages and would hold even if the counter were badly wrong. The invariant that does attest it is the in-repo drift assertion (helios/src/cache.rs:816-837), which compares the maintained count with a full scan of nodes on every stats read, so every cache and scheduler test exercises it. The PR body would be stronger citing that, plus request_pinned_pages <= cached_pages, instead of the live inequality. Under principle 16 the current evidence is connected to the claim only loosely.
Open questions / could not verify
- Sibling-PR cross-reference. The description refers to "#536" as the PR that adds a different region of
helios/src/server/metrics.rs; the related-items list pairs this PR with #548 ("Add request latency histograms and process metrics", same author). Likely a wrong reference in the description — a process defect, not a code one. A maintainer can settle it by checking which metrics PR is intended; both touch disjoint regions besidecached_pagesvs. the completion counter, so merge order is not a risk either way. - Authorization path.
AGENTS.md:165-169admits contributions that address "a demonstrated defect… or inaccurate documentation", which #537 does, but #537 appears user-filed rather than an explicit maintainer request. Whether that is sufficient authorization (AGENTS.md:201-205) is for the owners to confirm, not for me. - Live measurements (request 399/402, reserved 3/2, cached 2037/2043 of 21504, ratio 0.0186/0.0187) cannot be reproduced here; they are attributed in the description to a specific local two-GPU instance, explicitly scope-limited as non-comparative, and consistent with principle 12's honesty requirements.
- Not run here: Windows build and the full helios suite (CI covers them).