Code review summary report · NVIDIA/hyperflare-inference #549

Raw Markdown for agents: https://autobot.eidonix.com/p/98f8d847-7eab-48ee-82cf-ace772b5ecd0.md

Full report — PR #549 "Report KV pages held by active requests"

Verdict: Changes Requested. Scope and approach are right: the count is maintained on the pin paths so Cache::stats keeps its no-scan-nodes property, the gauges ride the existing gauge array, update table and expected-exposition rows, and there is no flag, per-model branch, or second representation — inside the charter's "smallest footprint in shared code" and the AGENTS.md (not opened) contribution-scope rules. What remains is one blocker that costs three lines, five should-fix items (three of them prose accuracy), and about 90 removable added lines.

Size: +218/−10 across 7 files (docs/api.md +9, helios/src/cache.rs +60/−1, cache/lifecycle_tests.rs +3, cache/tests.rs +24, scheduler.rs +38/−9, scheduler/tests.rs +66, server/metrics.rs +18). Closes #537; the sibling PR is #548 (which closes #536). Case file: this document plus the summary post.

Key findings

Blockers

B1. The new gauges are part of the key that decides whether deferred host copy-outs are re-offered. SchedulerStats derives PartialEq (helios/src/scheduler.rs:112) and is embedded whole in CopyoutResources (helios/src/server/runtime.rs:1053-1059):

#[derive(Clone, Copy, PartialEq, Eq)]
struct CopyoutResources {
    completed: crate::cache::Fence,
    scheduler: crate::scheduler::SchedulerStats,
    exports: usize,
    next: Option<(usize, u32, bool)>,
}

service_store rebuilds it every pass and compares (runtime.rs:2441-2449) to set retry_copyouts, which decides whether ids parked in deferred_copyouts (runtime.rs:2462-2470) get another export_fits + store.store attempt. Adding request_pages/reserved_pages (scheduler.rs:130-133) puts live-request accounting into that key, and both move with no cache-resource movement:

Change: build the key without the two live gauges — let mut scheduler = self.scheduler.stats(); scheduler.request_pages = 0; scheduler.reserved_pages = 0; with a one-line comment — or name the fields the key actually needs. Alternatively state in the description that copy-out retry cadence now follows live-request page movement. Why: copy-out re-offer timing is a scheduling decision, and the description claims there are none. The effect is bounded (extra export_fits attempts when headroom has not returned; copyout_headroom_deferrals cannot inflate because of the contains guard at runtime.rs:2465-2468), but an observability struct should not drive a control decision — and the claim is what the next reviewer will rely on. Settled by: a runtime test that leaves one copy-out deferred for headroom, advances one decode step crossing a page boundary, and asserts FakeStore saw no second store call.

Should Fix

S1. docs/api.md:302-303: "Both are gauges read from scheduler state on each scrape" is false. Metrics::render only loads atomics (the two gauges at helios/src/server/metrics.rs:1309-1318; value.load(Ordering::Relaxed) at 1394-1396) and never calls RequestScheduler::stats. The atomics are stored by the worker on iterations that made progress (helios/src/server/runtime.rs:1148-1149), at start (722) and after shutdown (745). With an idle or stopped worker a scrape reports an arbitrarily stale value — exactly the case where someone watches request pages fall to zero. Change: delete the sentence. The gauge contract is already established at api.md:287-296 and by every page row of the table; nothing needs adding in its place.

S2. docs/api.md:303-305: the ratio paragraph is wrong in three ways. Current text: "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."

Change: one rewritten sentence pair; the paragraph already has the definition it needs, so nothing should be added. Evidence knock-on: the description's live check request + reserved < total − free − cached does not validate this gauge — total − free − cached is dominated by snapshot-backing pages (metrics.rs:1294-1298) and is not a superset bound on request pages. The in-repo drift assertion comparing request_pinned_pages against a full scan of nodes on every stats read (cache.rs:817-837) is stronger evidence and already covers every cache and scheduler test. Cite that instead, or alongside.

S3. scheduler.rs:1643-1649, 1657-1664, 1682-1690: the same pin-kind conditional is written three times. inbound is immutable for the whole function, so all three sites are deterministically the same branch; the repo already decides once for exactly this reason (pin_checkpoint/unpin_checkpoint, scheduler.rs:2038-2044), and the pinned binding (1638-1642) was already the "decide once" shape. Change: carry the choice in that binding — let pin = pinned.map(|id| (id, inbound.is_none())) — and use one small pin_as/unpin_as (or a local closure) at the three sites. The branch itself must stay: the ticket-parent pin has to exist before ensure_resources evicts, so do not collapse the three to pin_request. Today a future edit that changes one site produces a pin on one counter and an unpin on the other, invisible in release builds.

S4. scheduler.rs:3143 vs 3155-3159: retire can now fail after it has already emptied the slot. self.slots[..].request.take() runs before self.cache.unpin_request(prefix)? and before retiring = true (3169) and the self.retired.push (3171). If unpin_request ever returned Err (cache.rs:565-568) the slot would hold no request, the retirement would not be recorded, the request value would be dropped and the prefix pin would leak for the life of the process. Not reachable today — the pin/release symmetry is intact on every path (see "Verified correct" below) — but the new error path turns a future unpair bug into a silent leak instead of a detected one. Change: release the pin before request.take(), or debug_assert! at the release site instead of propagating.

S5. cache.rs:548-550: the doc comment claims bookkeeping the cache does not do. "Request pins also track the pages the request keeps referenced: its private pages plus the pinned ancestors' pages, each page counted once." request_pinned_pages only ever moves from node.tail_pages.len() at the 0↔1 transitions of request_pins (cache.rs:553-561, 572-578); private pages are added by the scheduler (scheduler.rs:1216-1222). A reader cannot tell whether adding them double counts. Change: state the cache's half in one line and point at the consumer, e.g. "adding the tail pages of every checkpoint on its chain to request_pinned_pages while at least one request pin remains. A request's private pages are not cache pages; the scheduler adds them."

Subtract / Simplify

Could remove ~90 of +218 added lines without changing behaviour (up to ~112 if flare_reserved_kv_pages also goes). Nothing in the diff adds a parallel mechanism — the gauges reuse the existing gauge array, update table and expected-exposition rows — so the removable weight is inside the diff, not in its design.

Keep, checked and not cuttable: Checkpoint::request_pins; PrefixCheckpointCache::request_pinned_pages and its 0↔1 brackets (this is what lets stats avoid scanning nodes); the compaction assertion (cache.rs:626-627) that lets pages move into the heir without touching the counter; the extended #[cfg(test)] drift assertion (cache.rs:817-837) — the highest test value per line in the change; the request_pages sum in SchedulerStats::stats (this is the requested number); the atomic/store/render triple and its two table rows; docs/api.md:298-300. In particular do not delete Checkpoint::direct_request_pins (cache.rs:82-83): a checkpoint can be pinned both by a request and for host-store copy-out (pin_checkpoint, scheduler.rs:2038-2044), so the guard at cache.rs:565-568 is the only release-build detector of a mismatched release.

Nits

  1. scheduler.rs:1203-1228: stats() now walks self.slots three times (active_requests 1203-1207, private_pages 1216-1222, reserved_pages 1223-1228). One fold yields both new fields and makes them read as the pair the docs describe: let (request_pages, reserved_pages) = self.slots.iter().filter_map(|s| s.request.as_ref()).fold((cache.request_pinned_pages, 0), |(p, r), q| (p + q.private_pages.len(), r + q.reserved_pages.len()));. No behaviour change; stats() runs per progress, not per scrape.
  2. cache.rs:626: "Both nodes are counted or neither is, and the pages move into the counted heir" — "counted" does two jobs; "the ancestor's request pins equal its heir's, and its pages move into that heir" says it once.
  3. docs/api.md:298-306: one home for the content. The paragraph partly restates the HELP text (metrics.rs:1310-1317) and the page table (api.md:325-348) lists cached_pages/free_pages/total_pages but not the two new Prometheus-only gauges — consistent, since that table mirrors JSON fields, so do not add rows unless the JSON snapshot gains them. If a JSON note is wanted, one clause ("Neither appears in the JSON snapshot") suffices; if a design-doc home is preferred, docs/runtime-core-design.md:873 already carries the flare_snapshot_backing_pages rule and could hold these — but only as a replacement for the api.md prose, not in addition.
  4. Coverage, optional and free: no test drives pin_request through publish_boundary's Existing branch (scheduler.rs:2988-3000) — the one place where a second request pins a checkpoint another just published, where a double count or a missed pin would hide. The merged test from the first subtraction item is the cheapest place to reach it; no new test needed.
  5. Description only, fold into one bullet: (a) "a checkpoint leaves nodes only at zero pins" is wrong for compaction — compact_ancestor requires direct_pins == 0 && child_count == 1 (cache.rs:662, 686-690) and the new assert at 627 permits nonzero pins carried into the heir, so say that folding an ancestor into its heir loses no request pin; (b) "A page shared through a pinned ancestor therefore counts once for every request that references it" contradicts the code and the PR's own test — it is counted once in total (cache.rs:553-561), and request_pins_count_each_shared_page_once asserts 3, not 4 (cache/tests.rs:331-334); (c) the sibling PR is #548, not #536 (#536 is the issue #548 closes).

Verified correct — do not press these

Open questions and what could not be verified

  1. Is request + reserved the intended operator figure? If yes, flare_reserved_kv_pages stays and the fourth subtraction item is withdrawn; the omission in the ratio paragraph, not the choice, is the defect.
  2. Intended semantics of the inbound ticket pages (scheduler.rs:1704-1723) and of pages in self.retired: either the prose names the exclusions or the counters cover them. A test asserting both gauges during RequestPhase::Inbound and during retirement drain would settle the phase boundaries exactly, and would also decide whether the doc or the accounting is wrong.
  3. Whether the extra copy-out retries from B1 are observable in flare_host_cache_reoffer_calls_total — only the runtime test sketched under B1 or a scrape during a long deferral settles it.
  4. The docs/api.md ratio dips during drain by one GPU fence's worth of pages; I could not measure that against the documented scrape interval.
  5. The live scrape numbers (request 399/402, reserved 3/2, cached 2037/2043 of 21504 pages, ratio ≈0.0186/0.0187 on the two-GPU DeepSeek-V4.1-Flash instance) cannot be reproduced here. The in-repo drift assertion is what attests the gauge independently of that instance, and it is verified.
  6. Not verified here: CI status, the Windows build, and the --lib pass count (the description's 508 tests in --lib -- cache:: scheduler:: server::metrics is taken on trust; I read the named tests in source).
  7. Note for the author: whether #537 was filed by a maintainer affects the merge path under AGENTS.md (not opened) ("addresses a maintainer request"); the owners should confirm, not the reviewer. I also could not apply the repo prose skill (.agents/skills/repo-prose/SKILL.md (not opened)) itself — its requirements are reflected in the prose findings above, but an owner should do the style pass.