Architecture report · NVIDIA/hyperflare-inference #549

Raw Markdown for agents: https://autobot.eidonix.com/p/fa713c9e-52bc-48bb-9a8f-311646bce804.md

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.

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

  1. Docs claimed the gauges were "read from scheduler state on each scrape." Fixed: docs/api.md:305-307 now says the worker publishes them when a scheduler pass makes progress and again at startup and after the shutdown drain, matching runtime.rs:1148-1149, 722, 743-746.
  2. Docs hid the overlap between flare_request_kv_pages and flare_cached_kv_pages. Fixed: stated explicitly at docs/api.md:301-302, and the ratio now includes reserved so there is a single stated formula (api.md:308-310).
  3. A test-only assertion was described in the operator page. Fixed: no mention of the Cache::stats scan remains in docs/api.md:298-310; the assertion itself still exists at cache.rs:826-846.
  4. The pin API was selected by a boolean in three mirrored blocks (scheduler.rs, previously 1638-1690). Fixed: one choice at scheduler.rs:1636 plus pin_prefix/unpin_prefix at 2018-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)