Architecture scratchpad · NVIDIA/hyperflare-inference #549

Raw Markdown for agents: https://autobot.eidonix.com/p/8642294e-850f-45ca-8209-00f73a048b12.md

#1 [high] Research summary

Architecture & scope review — PR #549 (KV pages held by active requests)

Scope verdict: in scope, approach acceptable, with wording/robustness issues. The change touches only shared runtime layers (cache accounting, scheduler stats, Prometheus text, docs). No per-model branches, no flags, no environment switches, no allocation/eviction policy change — it keeps layers in their roles (AGENTS.md "Keep the runtime small and model-agnostic" / design-review principles 1, 3, 10). It is justified by issue #537 as a missing-capability/bad-docs contribution, which AGENTS.md "What gets merged" admits, though #537 is user-filed rather than an explicit maintainer request. The counters are bounded work on the pin/unpin paths, so the "don't scan nodes in stats" constraint is respected.

Findings recorded (all verified in code):

  1. Should fix — docs/api.md:298-305 says both gauges are "read from scheduler state on each scrape"; they are not. Metrics::render (helios/src/server/metrics.rs:666, gauges at 1309-1318) only loads AtomicU64s, which Metrics::scheduler refreshes from worker.scheduler.stats(), and the worker loop calls that only when it made progress (helios/src/server/runtime.rs:1148-1149, plus 722/745). A scrape is served from the HTTP side and never touches the scheduler. Fix: say the values are published by the worker each time scheduling state advances.
  2. Should fix — docs/api.md:298-305 omits that flare_request_kv_pages overlaps flare_cached_kv_pages. request_pinned_pages counts tail pages of checkpoints that are still in nodes and therefore still summed into cached_pages (helios/src/cache.rs:258-275, 816-852), so the pinned portion of cached pages appears in both gauges. The text only says "idle cached prefixes ... are outside that share", which invites an operator to add or subtract the two. State the overlap explicitly. Related: the PR description's consistency check (request + reserved < total - free - cached) compares against what is effectively snapshot-backing pages, not a superset of request pages, so it does not validate the gauge it claims to validate.
  3. Nit — the admission pin API is selected by a boolean in three mirrored blocks (helios/src/scheduler.rs:1643-1649, 1657-1663, 1684-1690), each pairing 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. This is the kind of optional path the review standards discourage; a helper that returns which API it used, or a small enum, would remove the risk that a future edit pairs mismatched calls — which would now surface as a hard error from unpin_request (helios/src/cache.rs:565-568) rather than a stale gauge.
  4. Nit — unpin_request's error becomes a retirement failure. RequestScheduler::retire releases the prefix with unpin_request (helios/src/scheduler.rs:3159), so an accounting slip would abort request retirement instead of being detected as a metric drift. The only verification of the new counters in production code paths is the #[cfg(test)] drift assertion (helios/src/cache.rs:818-837); consider a debug_assert on the release path to match how the existing pin invariants are checked (cache.rs:623-627).
  5. Nit — smallest-footprint alternative. LiveRequest already carries shared_pages, private_pages, and reserved_pages (helios/src/scheduler.rs:253-255), so SchedulerStats could derive a distinct request-page count from live slots without adding five fields and a new invariant to PrefixCheckpointCache. The cache-side approach is defensible only because of the "each shared page once" requirement, which a per-slot union with a set also satisfies. Worth a sentence in the rationale.

Positive checks: request_pinned_pages accounting survives compaction and leaf retirement (cache.rs:594-646, 658-691) — request-pinned nodes are excluded from leaf eviction by pins != 0, and compaction moves pages into an heir with the same request_pins, leaving the total unchanged; every path that stores request.prefix pairs it with pin_request (1900-1902, 2971-2979, 2991-2996) and the ticket-parent pins that keep the plain API (1882, 1918) never become request.prefix. Reserved pages are popped from free_pages at admission (1732-1735), so the "neither free, cached, nor written" wording holds.

Could not verify: the sibling-PR reference in the description ("#536") does not match the related-items list, which pairs this PR with #548 by the same author; likely a wrong cross-reference.

#2 [high] Should fix: docs/api.md claims gauges are read from scheduler state on each scrape

File: docs/api.md:298-305 (added by PR #549). Claim in docs: "Both are gauges read from scheduler state on each scrape." Reality verified in code:

#3 [high] Should fix: request_kv_pages overlaps cached_kv_pages but docs say only "idle cached prefixes" are excluded

File: docs/api.md:298-305 (added by PR #549). Problem: flare_request_kv_pages = active slots' private_pages + cache.request_pinned_pages (helios/src/scheduler.rs:1216-1222), where request_pinned_pages is the tail pages of checkpoints in nodes with request_pins > 0 (helios/src/cache.rs:548-580, 838-842). Those same checkpoints are still in nodes, so their tail pages are also included in cached_pages (count/uncount at helios/src/cache.rs:258-275; stats at 816-852). Pages enter the cache when a boundary capture moves the request's private pages into the checkpoint (helios/src/scheduler.rs:2965-2979), and the request keeps referencing them. Therefore a pinned checkpoint's pages appear in BOTH flare_request_kv_pages and flare_cached_kv_pages. The doc only says "idle cached prefixes and snapshot backing pages are outside that share", which reads as though the rest of cached is disjoint from request. An operator computing request/total or trying to reconcile free + cached + request will double-count. Fix: state explicitly that the pinned tail pages of cached checkpoints are counted in both gauges, and that request is not a disjoint partition alongside cached. Knock-on: the PR description's live check that request + reserved < total - free - cached holds is not evidence of correctness, because total - free - cached is roughly snapshot-backing pages (owned snapshots excluded from the free list) and is not a superset bound on request pages. The invariant that would actually validate the gauge is request_pinned_pages <= cached_pages plus per-node agreement with a scan. Severity: should fix (documentation accuracy; the derived ratio is the whole point of the metric per issue #537).

#5 [high] Report of 2026-11-27, run on head 9cca87a (post-fix re-review)

Architecture & scope review — PR #549, head 9cca87a

Previous findings, re-checked

Verdict this pass: should-fix (one prose defect) + 3 nits. Scope and approach remain right.

Scope: still confined to helios/src/cache.rs, scheduler.rs, server/metrics.rs, docs/api.md. No per-model branch, no flag, no policy path, no allocation/eviction/scheduling change. Satisfies charter lines 12, 34; docs/design-review.md principles 1, 3, 10, 12, 15, 16; AGENTS.md:165-200. Deriving the count on the pin/unpin paths keeps Cache::stats free of a nodes scan, which is the constraint the PR states.

Should fix

Nits

Positive checks

#6 [high] Research summary

Re-reviewed PR #549 at head 9cca87a through the architecture-and-scope lens. Scope and approach still hold: the change stays inside shared runtime layers (cache accounting, scheduler stats, Prometheus text, docs/api.md), with no per-model branch, flag, or allocation/eviction/scheduling change, and maintaining the count on pin/unpin keeps Cache::stats free of a nodes scan as the PR requires.

Four of my earlier findings are fixed by the pushed commits: the docs no longer claim scrape-time reads of scheduler state, the overlap between flare_request_kv_pages and flare_cached_kv_pages is now stated, the three mirrored pin-kind conditionals became pin_prefix/unpin_prefix selected once, and retire releases the request pin before emptying the slot. The other reviewer's blocker is patched by zeroing the two new fields when building the copy-out retry key.

Remaining: one should-fix documentation defect — docs/api.md:307-310 both claims request + reserved is the comparable figure and says dividing "either gauge" by total yields the KV share, which cannot both be true (reserved is 2-3 pages in the author's own scrape) and misdescribes what the ratio excludes. Three nits: a #[cfg(test)] drift assertion is documented in the operator-facing API page; "on every scheduler pass" overstates the publish cadence (runtime.rs:1148-1149 publishes only on progress); and CopyoutResources still embeds the whole SchedulerStats, so the head commit's zeroing is a per-field patch on a coupling that will recur. Full detail in scratchpad entry #5.

#7 [high] Superseded notes #2 and #3 — do not carry their findings into the report

Entry #2 ("gauges are read from scheduler state on each scrape") and entry #3 ("docs say only idle cached prefixes are excluded, hiding the request/cached overlap") describe the state of docs/api.md before commit 9cca87a. Both are FIXED at head 9cca87a:

The final report must present them as resolved, not as open findings. Entries #1 and #4 are the earlier research summary and the earlier report; #5 is the current state and the authoritative source for the report.

One element of old #3 is still worth carrying, but reframed as an evidence critique rather than a docs defect: the PR description's live consistency check request + reserved < total - free - cached does not validate the gauge, because total - free - cached is dominated by snapshot-backing pages (flare_snapshot_backing_pages, helios/src/server/metrics.rs:1294-1298) and is not a superset bound on request pages. The invariant that does attest the gauge is the in-repo #[cfg(test)] scan comparison at helios/src/cache.rs:818-837. Head 9cca87a moved that assertion into api.md:311-312, which is where the new nit about documenting test-only evidence comes from (see #5).