Architecture & scope review — PR #549 "Report KV pages held by active requests"
Head reviewed: bca7358 (8 files, +202/−34). Link: https://github.com/NVIDIA/hyperflare-inference/pull/549
Key findings
Verdict: clean — no blocking issues, no should-fix issues, one nit.
- The change belongs in this repository and in these layers. It is confined to shared runtime code — KV cache accounting (
helios/src/cache.rs), scheduler statistics and the request-pin API (helios/src/scheduler.rs), the Prometheus text renderer (helios/src/server/metrics.rs), the deferred copy-out key (helios/src/server/runtime.rs), and one operator-facing paragraph indocs/api.md. No per-model branch, no flag, no environment switch, no optional policy path, and no change to allocation, eviction, preemption, or readmission decisions. That satisfies charter line 12 ("Keep the runtime small and model-agnostic… Helios (the runtime) handles scheduling, caches, and requests"), the charter's "Solve the right problem in the right place… smallest footprint in shared code",AGENTS.md:171-181(reject unapproved scope expansion / architectural violations), andAGENTS.md:182-187(reject weakened guarantees —pin/unpinsemantics are unchanged for every pre-existing caller). - Need is demonstrated. Issue #537 describes exactly this gap —
/metricsreports free and cached pages but not pages held by live requests, so the KV share cannot be computed — and the PR implements #537's option 1 (aflare_request_kv_pagesgauge counting each page once) verbatim. UnderAGENTS.md:165-169("a demonstrated defect… or inaccurate documentation") and charter line 35 ("What gets merged: PRs that address a maintainer request, a roadmap item, a reproducible bug, a measured performance/memory issue, or bad docs"), scope is authorized. - The approach respects the constraint the PR itself states.
Cache::statsmust not scan the checkpoint graph, and it does not: the count is maintained on the pin/unpin paths (helios/src/cache.rs:519-589) and verified against a fullnodesscan by a test-only assertion (cache.rs:826-846). Work added per operation is onetail_pages.len()add/subtract on the 0→1 and 1→0 request-pin crossings, and the stats side folds two sums into the live-slot loop that already ran (scheduler.rs:1200-1236) — no new cost class, keeping design-review principle 8 (budget across the lifecycle) intact. - One nit, no more:
CopyoutResourcesstill embeds all ofSchedulerStatsand the two new fields are hand-zeroed when building the copy-out retry key, so the next gauge added toSchedulerStatswill silently perturb copy-out scheduling again (helios/src/server/runtime.rs:1053-1059,2443-2450,2455-2456).
Every changed file was read in its surrounding code at head. All four findings from my earlier rounds against this PR are fixed at bca7358 (details in "Prior findings, verified fixed" below); entries #2 and #3 of my scratchpad are explicitly superseded and their contents do not appear in this report as findings.
The one nit
Nit — CopyoutResources embeds all of SchedulerStats, and the fix is a per-field patch on that coupling.
helios/src/server/runtime.rs:1053-1059 defines the key as { completed: Fence, scheduler: SchedulerStats, exports: usize, next: Option<(usize, u32, bool)> }, compared by value at runtime.rs:2455-2456 (let retry_copyouts = retry || progress || self.copyout_resources != Some(resources);) to decide whether deferred host copy-outs are retried. Because decode moves the new page counts without moving cache resources, bca7358 zeroes request_pages and reserved_pages when building the key (runtime.rs:2443-2450, with a correct explanatory comment). That is right for today's field set, but the coupling remains: any future metric field added to SchedulerStats changes the comparison unless someone remembers to extend the zeroing list. AGENTS.md:188-193 rejects abstractions and coupling without a concrete requirement, and design-review principle 15 rejects scope expansion and weakened constraints. 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. Not blocking — behaviour today is correct and commented.
Per-file status at bca7358 (all read in context)
docs/api.md (+14, lines 298-310) — clean
Lines 298-301 define flare_request_kv_pages as the distinct pages requests owning a model slot reference (private pages plus the tail pages of pinned prefix checkpoints, each page once). Lines 301-302 now state the non-disjointness explicitly: "It is not disjoint from flare_cached_kv_pages: a pinned checkpoint stays published, so its tail pages count in both gauges." Lines 302-304 state what neither gauge counts (pages draining after retirement, a restore ticket's in-flight pages). Lines 304-305 define flare_reserved_kv_pages as pages reserved for growth that are "neither free, cached, nor written" — which matches the code, since reservations are popped from free_pages at admission and only written when used. Lines 305-307 state the publish cadence, which matches runtime.rs:1148-1149 (if progress { self.metrics.scheduler(...) }), startup at runtime.rs:722, and the shutdown drain at runtime.rs:743-746. Lines 308-310 give one ratio, (request + reserved) / total, comparable to vLLM's kv_cache_usage_perc, with idle cached prefixes and snapshot backing pages outside it.
The qualifier "requests owning a model slot" is accurate: inbound-ticket waiters hold no prefix pin — request pins are taken only in finish_inbound after the restore completes (helios/src/scheduler.rs:1880-1892).
helios/src/cache.rs (+73/−5) — clean
pin_with/unpin_with (cache.rs:519-570) walk one chain and add or subtract a checkpoint's tail_pages.len() on the 0→1 and 1→0 request-pin crossings; because a node's tail pages exclude its ancestors' pages, each page is counted once even when several requests pin it. unpin_with hard-errors on a release with no request pin (cache.rs:547-549), which makes a mismatched pin/unpin pair a loud failure instead of silent gauge drift. The public pin/unpin are unchanged for existing callers (cache.rs:572-578), and pin_request/unpin_request are thin wrappers (cache.rs:583-589). Compaction keeps the count exact: debug_assert_eq!(node.request_pins, child.request_pins) then the ancestor's tail pages move into the heir (cache.rs:632-641), leaving the survivor's contribution unchanged. uncount only subtracts tail_pages (cache.rs:268-275) and retire_leaf is reached only at zero pins (cache.rs:667-673), so a retired node never held a counted contribution. The test-only drift assertion compares request_pinned_pages with a full nodes scan on every stats() read (cache.rs:826-846); CacheStats::request_pinned_pages is exposed at cache.rs:851.
helios/src/scheduler.rs (+49/−19) — clean
The two new sums are folded into the existing live-slot pass (scheduler.rs:1200-1236: request_pages at 1220, reserved_pages at 1221), so the stats call adds no second traversal. The pin kind is chosen once (request_pin = inbound.is_none(), scheduler.rs:1636) and dispatched through pin_prefix/unpin_prefix (scheduler.rs:2018-2033), removing the three mirrored conditionals I flagged in the first round. Request pins are taken where request.prefix is stored (scheduler.rs:1882, 2970, 2990); the plain API is retained only where it is correct — the host-admission ticket parent (1864, 1900, request_pin=false) and copy-out pins via pin_checkpoint/unpin_checkpoint (2035-2043). retire releases the request pin before the slot is emptied (scheduler.rs:3142-3149), so the count cannot outlive the reservation.
helios/src/server/metrics.rs (+18) — clean
Two atomics (metrics.rs:265-266), stored by Metrics::scheduler (metrics.rs:517-518), rendered as gauges with accurate help text (metrics.rs:1309-1318), deliberately absent from the JSON Snapshot (metrics.rs:68-129) as the description states, and covered by test expectations (metrics.rs:1787-1792, 1832-1834).
helios/src/server/runtime.rs (+8/−1) — one nit (above)
The zeroing at 2443-2450 is correct for today's field set and explained in-place; the underlying key shape at 1053-1059 is the nit.
helios/src/cache/tests.rs, helios/src/cache/lifecycle_tests.rs, helios/src/scheduler/tests.rs — clean
cache/tests.rs:320-360 covers the shared-prefix case (three distinct pages count 3, not 4), plain-pin neutrality, the release-without-request-pin error, and the count surviving compaction. scheduler/tests.rs:970-1032 checks request_pages == shared + private, reserved_pages, and both returning to zero after cancellation while cached_pages > 0. The lifecycle fixture mirrors the new fields (cache/lifecycle_tests.rs:74-95) so the test-only drift assertion runs there too. These exercise behaviour rather than source text, satisfying AGENTS.md:194-199.
Prior findings, verified fixed at bca7358
- Docs claimed the gauges were "read from scheduler state on each scrape." Fixed:
docs/api.md:305-307now says the worker publishes them when a scheduler pass makes progress and again at startup and after the shutdown drain, matchingruntime.rs:1148-1149,722,743-746. - Docs hid the overlap between
flare_request_kv_pagesandflare_cached_kv_pages. Fixed: stated explicitly atdocs/api.md:301-302, and the ratio now includesreservedso there is a single stated formula (api.md:308-310). - A test-only assertion was described in the operator page. Fixed: no mention of the
Cache::statsscan remains indocs/api.md:298-310; the assertion itself still exists atcache.rs:826-846. - The pin API was selected by a boolean in three mirrored blocks (
scheduler.rs, previously 1638-1690). Fixed: one choice atscheduler.rs:1636pluspin_prefix/unpin_prefixat2018-2033.
Checks across the supported matrix (charter line 42)
The change adds no per-model branch, cache-scheme branch, parallel-layout branch, or hardware-target branch, so the model/hardware matrix is untouched by construction; the accounting is in shared runtime layers only. CUDA-graph and state transitions are not involved: no graph kind, capture path, or state machine was modified — only counters and their publication. Exported cores are unaffected: the new fields live in SchedulerStats/CacheStats and in Prometheus text, not in prepared metadata, and the JSON snapshot shape is unchanged (metrics.rs:68-129). The gauges are absent from the JSON Snapshot, so existing JSON consumers see identical output. pin/unpin signatures and semantics are preserved, so data and artifacts load unchanged.
Report-only notes (not findings)
- The PR body's live inequality does not attest the gauge.
request + reserved < total − free − cachedis dominated by snapshot-backing pages, whichflare_snapshot_backing_pagesdocuments as "KV page ids excluded by owned snapshots" (metrics.rs:1294-1298);total − free − cachedis not a superset bound on request pages. The bound the definitions do imply,request + reserved <= total − free, is stated correctly in the body. The real evidence is in the repository and should be cited there instead: the#[cfg(test)]drift assertion compares the maintained count against a fullnodesscan on everyCache::statsread (cache.rs:826-846). - Authorization rests on a user-filed issue. #537 demonstrates a concrete metric gap with numbers, which
AGENTS.md:165-169and charter line 35 admit; owners may still want to confirm the chosen gauge over #537's option 2 (splittingflare_cached_kv_pages) or a ready-made ratio gauge, since that is a product choice rather than an architectural one. - Not reproducible in this review: the author's live scrape figures (54-80 request pages / 16-22 reserved on one GB202 box; 399-402 / 2-3 of 21,504 on a two-GPU DeepSeek deployment), the exported-core check, the Windows build, and the full helios suite. The author discloses each gap explicitly, satisfying
AGENTS.md:194-199and design-review principle 12 (report evidence honestly). - Sibling PR: the description pairs this with #548 and says the two merge in either order. The regions touched are disjoint (
metrics.rsgauge table versus the completion-counter region), so that holds on inspection; the shared files are listed in the related-items map, not a conflict.