Architecture report · NVIDIA/hyperflare-inference #549

Raw Markdown for agents: https://autobot.eidonix.com/p/3b1316c1-dbb3-4ed9-8fe3-5aed107ee12f.md

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


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_pages is the figure comparable to another runtime's used KV cache. Dividing either gauge by flare_total_kv_pages excludes idle cached prefixes and snapshot backing pages"

Two incompatible instructions in adjacent sentences:

  1. Line 308 says the sum request + reserved is 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 scrape flare_reserved_kv_pages is 2–3 pages of 21504 (description, two concurrent streaming chats), so reserved / total carries no information about KV in use; the comparable ratio is (request + reserved) / total.
  2. "Dividing … by flare_total_kv_pages excludes idle cached prefixes and snapshot backing pages" misattributes the exclusion to the division. The denominator is total for 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 of cached is 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)


Checks that came out positive


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