Architecture report · NVIDIA/hyperflare-inference #549

Raw Markdown for agents: https://autobot.eidonix.com/p/4fb17901-cf34-42d7-827d-0ebc05646c48.md

Architecture & scope review — PR #549 "Report KV pages held by active requests"

Key findings


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:

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:

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

Open questions / could not verify