Architecture & scope review — PR #549 "Report KV pages held by active requests" (head bca7358)
Key findings
- In scope, approach right. The change lives entirely in shared runtime layers — cache accounting (
helios/src/cache.rs), scheduler stats and the request-pin API (helios/src/scheduler.rs), Prometheus text (helios/src/server/metrics.rs), the deferred-copy-out key (helios/src/server/runtime.rs), anddocs/api.md. No per-model branch, flag, environment switch, optional path, or change to allocation, eviction or scheduling decisions. It satisfies charter "Keep the runtime small and model-agnostic" (charter line 12), "No per-model special cases or flags" (charter line 43), andAGENTS.md:171-200. - Need is demonstrated. It implements option 1 of issue #537 ("A gauge
flare_request_kv_pages: distinct KV pages referenced by active requests (private pages plus shared/pinned prefix pages), each page counted once"), which shows concrete numbers that cannot be computed from the shipped gauges — a demonstrated defect/missing capability underAGENTS.md:165-169and charter "What gets merged" (line 35). - The constraint that motivated the design is respected. The count is maintained on the pin/unpin paths (
cache.rs:519-570), soCache::stats(cache.rs:825-861) never scansnodes— exactly what the PR claims and what the existingstatscontract requires. - All four findings from my previous round are verified fixed at this head (ratio wording, test-only assertion removed from the operator page, publish cadence, mirrored pin-kind conditionals plus retirement ordering).
- One nit remains (
CopyoutResourcesstill embeds all ofSchedulerStats); no blocking or should-fix issues.
The one open finding
Nit — CopyoutResources embeds the whole SchedulerStats, so the new gauges had to be hand-zeroed out of the copy-out retry key. helios/src/server/runtime.rs:1053-1059 stores scheduler: crate::scheduler::SchedulerStats inside CopyoutResources, which is compared by value to decide whether deferred host copy-outs retry (runtime.rs:2455-2456). This commit zeroes the two new fields when building the key (runtime.rs:2443-2450, with an explanatory comment) because decode moves request/reserved page counts without moving cache resources. That fixes today's behaviour but leaves the structural coupling: any gauge added to SchedulerStats in the future silently perturbs copy-out scheduling unless someone remembers to extend the zeroing list — precisely the kind of implicit dependency AGENTS.md:188-193 asks reviewers to reject ("Do not add … speculative compatibility, fallback layers, or configuration switches without a concrete requirement"; refactoring must remove a demonstrated source of cost). Fix: give CopyoutResources only the cache fields copy-out actually depends on (completed, free_pages, free_snapshots, cached_pages, snapshot_backing_pages, exports, next) so metrics cannot enter the comparison key at all. Not blocking; the current behaviour is correct.
Per-file status at bca7358 (8 files, +202/−34)
docs/api.md(+14, lines 298-310) — clean. Definesflare_request_kv_pagesas distinct pages referenced by requests owning a model slot: private pages plus tail pages of pinned checkpoints, each page once (298-301); states explicitly that it is not disjoint fromflare_cached_kv_pagesbecause a pinned checkpoint stays published (301-302); states the exclusions — pages draining after retirement and a restore ticket's in-flight pages (302-304); definesflare_reserved_kv_pagesas pages that are neither free, cached, nor written (304-305); gives the publish cadence as "when a scheduler pass makes progress, and again at startup and after the shutdown drain", with a scrape reading the last published values (305-307), which matchesruntime.rs:1148-1149(if progress { self.metrics.scheduler(...) }), startupruntime.rs:722, and the shutdown drainruntime.rs:743-746; and gives one comparable share,(flare_request_kv_pages + flare_reserved_kv_pages) / flare_total_kv_pages, noting idle cached prefixes and snapshot backing pages are outside it (308-310). The "requests owning a model slot" qualifier is accurate: inbound-ticket waiters hold no prefix pin, because the request pin is taken only after the restore completes (scheduler.rs:1630-1639withrequest_pin = inbound.is_none(), and the request prefix publication atscheduler.rs:1882).helios/src/cache.rs(+73/−5) — clean.pin_with/unpin_withtake the request flag and add/subtracttail_pages.len()on the 0→1 and 1→0 request-pin crossings along the whole chain (cache.rs:519-570); the publicpin/unpinkeep their old semantics andpin_request/unpin_requestare thin entry points (cache.rs:572-589), so no existing caller changes behaviour.unpin_withrejects a release when the checkpoint holds no request pin (cache.rs:547-549), which turns a mismatched pin-kind into a hard error instead of a silent gauge drift. Compaction asserts the removed ancestor and its heir agree on request pins and moves the ancestor's tail pages into the heir, so the counted contribution stays with the survivor (cache.rs:632-641).CacheStats::request_pinned_pagesexposes the maintained value (cache.rs:851), and the#[cfg(test)]assertion compares all kept counts against a full scan ofnodeson everystatsread (cache.rs:825-846) — this is the strongest evidence in the PR and runs on every cache and scheduler test.helios/src/scheduler.rs(+49/−19) — clean. The new sums are folded into the loop that already counts live slots, so no second pass (scheduler.rs:1200-1235,request_pages: request_pages + cache.request_pinned_pagesat 1220,reserved_pagesat 1221). The pin kind is chosen once (request_pin = inbound.is_none(),scheduler.rs:1636) and dispatched throughpin_prefix/unpin_prefix(scheduler.rs:2018-2033), which removes the previous three mirrored conditionals. The plain pins that legitimately remain are the host-admission ticket parent (scheduler.rs:1637-1638) and copy-out viapin_checkpoint/unpin_checkpoint(scheduler.rs:2035-2043) — neither ever becomesrequest.prefix.retirereleases the request pin before emptying the slot, so a failed release leaves the request inspectable (scheduler.rs:3142-3150). Reserved pages are removed fromfree_pagesat admission, which is what makes the "neither free, cached, nor written" definition true.helios/src/server/metrics.rs(+18) — clean. Two atomics (metrics.rs:265-266), stored fromSchedulerStats(metrics.rs:517-518), rendered as gauges with accurate help text (metrics.rs:1309-1318), and deliberately absent from the JSONSnapshot(metrics.rs:68-129), matching the stated scope. Test expectations cover names, types and values (metrics.rs:1787-1792,1832-1834).helios/src/server/runtime.rs(+8/−1) — one nit, above. The zeroing atruntime.rs:2443-2450is sound for the current field set and correctly explained; the coupling atruntime.rs:1053-1059/2455-2456is what should eventually go.helios/src/cache/tests.rs,helios/src/cache/lifecycle_tests.rs,helios/src/scheduler/tests.rs— clean. Two overlapping tests are folded into one each:branching_pins_ancestors_and_prevents_direct_ancestor_unpin(shared parent over pages 0-2 counted as 3 not 4, plain copy-out pin leaves it unchanged, release without a request pin errors, count survives compaction into the pinned heir) andbranching_requests_own_distinct_tail_pages_and_terminal_snapshots(request_pagesequals shared plus both private sets,reserved_pagesequals both reserved sets, both zero after cancellation while cached pages remain). The lifecycle fixture mirrors the new fields so the test-only drift assertion runs there too (AGENTS.md:194-199, "require focused, meaningful validation").
Positive architectural checks
- Layer roles preserved. Cache owns page bookkeeping; the scheduler owns requests and sums live slots; metrics only renders published values; docs describe operator-visible behaviour. No layer reaches into another's internals, and no scanning was added to a hot read path.
- Count is exact under the tricky transitions. Tail pages of a node exclude its ancestors' pages, so shared pages are counted once however many requests reference them; leaf retirement only happens at zero pins (
cache.rs:667-673), so a retired checkpoint never contributed; compaction carries both the pins and the pages into the heir under an assertion (cache.rs:632-641). - No behavioural change to serving.
SchedulerStatsgained fields,CacheStatsgained a field,pin/unpinare unchanged for all pre-existing callers; the only altered execution order isretirereleasing the pin before dropping the slot (scheduler.rs:3142-3150), which is a strict improvement in error visibility. - Cost is bounded and stated. One chain walk per pin/release (unchanged asymptotically), a couple of counts per node, two
u64per checkpoint, oneusizeon the cache, and one extra addition perstatscall. No allocation. This matches the "cost, read from the code" claim in the PR body; no performance claim is made, so no benchmark is required under charter "Bring real evidence".
Open questions / what I could not verify
- Authorization. The need rests on issue #537, filed by a user (Napuh), not an explicit maintainer request. Under
AGENTS.md:165-169a demonstrated defect is sufficient, and #537 does demonstrate one, so this is in scope — but owners may want to confirm they want the vLLM-compatible gauge rather than #537's option 2 (splittingflare_cached_kv_pagesinto pinned/idle) or a ready-made ratio gauge. - Evidence quality in the PR body (report note, not a code finding). The body's live check
request + reserved < total − free − cacheddoes not attest the gauge:total − free − cachedis dominated by snapshot-backing pages (metrics.rs:1294-1298), so the inequality holds regardless of the request count. The bound the definitions do imply,request + reserved ≤ total − free, is stated correctly, and the in-repo drift assertion (cache.rs:825-846) is the real evidence — the body should cite that instead. - Not reproducible here: the author's live two-GPU scrape figures, the exported-core and Windows checks, and the full helios suite. The author discloses these gaps, which satisfies
AGENTS.md:194-199. Also note the sibling-PR cross-reference in the description ("#536") does not match the related-items list, which pairs this PR with #548 by the same author — likely a stale number, worth correcting for reviewers.