Prose scratchpad · NVIDIA/hyperflare-inference #549

Raw Markdown for agents: https://autobot.eidonix.com/p/506a0f8b-9a7c-4986-83b4-37bf4793e92b.md

#1 [high] Should fix: docs/api.md says the gauges are "read on each scrape" but the worker caches them

docs/api.md:298-306 (new paragraph) says: "Both are gauges read from scheduler state on each scrape."

Not what the code does. Metrics::render only loads atomics (helios/src/server/metrics.rs:666, gauges at :1280-1318); the atomics are stored from SchedulerStats by Metrics::scheduler (helios/src/server/metrics.rs:476-522, new fields at :517-518). Only the serving worker calls it, and only on iterations where it made progress: helios/src/server/runtime.rs:1148-1153 if progress { self.metrics.scheduler(self.scheduler.stats()); ... }, plus once at worker start (:722) and once after shutdown (:745).

Consequence for an operator: a scrape reports the last value the worker published, so while the worker is idle or blocked (e.g. waiting on a long graph) the gauge can be stale, and a stopped worker keeps the last value. The doc sentence tells the reader the opposite (fresh per scrape).

Fix: "Both are gauges published by the serving worker as it advances, so a scrape reports the value from the worker's most recent scheduler update." Scheduler state is not readable at scrape time (the scheduler lives on the worker thread behind the metrics atomics).

Settled by reading, no test needed.

#2 [high] Should fix: api.md exclusion sentence omits reserved pages from the ratio

docs/api.md:298-305: "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."

The share also excludes flare_reserved_kv_pages, which the two preceding sentences introduce as pages "reserved for active requests' future growth that are neither free, cached, nor written yet". Code: helios/src/scheduler.rs:1216-1229 — request_pages = sum of live private_pages + cache.request_pinned_pages; reserved_pages is summed separately and never enters request_pages. So the documented ratio understates the KV an active request actually holds by exactly the reserved set, which is the point of the new second gauge (#537 asked for vLLM kv_cache_usage_perc semantics, and vLLM counts the blocks it has already allocated to running requests).

The sentence enumerates every exclusion except the most relevant one, and a reader computing the ratio to compare with vLLM will be low by the reserved amount without any hint. Fix: add "reserved pages for live requests' growth are also outside it; flare_request_kv_pages plus flare_reserved_kv_pages is the figure that covers both." (Verify the sum is the intended operator guidance before stating it; that phrasing is the author's call, but the omission of reserved pages must be repaired.)

#3 [high] Should fix: api.md and PR description overstate coverage — inbound restore pages are in neither gauge

docs/api.md:298-300 says flare_request_kv_pages "counts the distinct KV pages that active requests reference", and the PR description claims "the KV pages held by active requests ... become scrapeable". That is false while an admitted request is in RequestPhase::Inbound (waiting for a host-store restore).

Code: helios/src/scheduler.rs:1699-1730 pops inbound.pages page ids out of self.free_pages into the Ticket (pages), and the live request is created with shared_pages = Vec::new(), private_pages = Vec::new() (helios/src/scheduler.rs:1736-1737, 1802-1803). SchedulerStats::request_pages (helios/src/scheduler.rs:1216-1222) sums only live slots' private_pages plus cache.request_pinned_pages; reserved_pages (1223-1228) is a disjoint set. The ticket's pages are in neither gauge, yet they are neither free (popped), nor cached (not a checkpoint), nor written (restore in flight). So both new gauges read zero for the restore destination pages of an active request, for as long as the host restore runs — which for a large prefix is the biggest block the request holds.

The gauge and help text describe the checkpoint-pinned and private pages correctly for every other phase; the doc sentence needs the exception, e.g. "...flare_request_kv_pages excludes pages of a host-store restore still in flight, which are held by the restore ticket until the request starts from them." Same repair applies to the description's "the KV pages held by active requests become scrapeable".

Verified by reading scheduler.rs:1699-1741 and 1216-1229; a test could settle the exact phase boundary (assert both gauges during RequestPhase::Inbound).

#4 [high] Should fix: description contradicts its test — "counts once for every request" vs counted once in total

PR description, helios/src/cache.rs bullet: "A page shared through a pinned ancestor therefore counts once for every request that references it."

That is the opposite of the implemented and tested behavior. request_pinned_pages adds a node's tail_pages.len() only when its request_pins rises from 0 (helios/src/cache.rs:553-561), so a shared ancestor page is counted once in total no matter how many requests reach it. The PR's own test asserts exactly this: request_pins_count_each_shared_page_once (helios/src/cache/tests.rs:320-341) pins two children over a shared parent and asserts request_pinned_pages == 3, "rather than 4". Read literally, the description states 4.

Per AGENTS.md:96-102 and docs/design-review.md:125-150 the description must state the resulting behavior precisely; a reviewer who trusts this sentence will expect the gauge to grow with sharing (per-request accounting, as vLLM's num_running blocks would) and read the small observed values as a bug.

Fix: "A page in a shared ancestor's tail is counted once in the total, however many requests pin checkpoints below it; the per-request count comes from summing private pages separately."

#7 [high] Research summary

Prose review of PR #549 ("Report KV pages held by active requests"). I read the charter, AGENTS.md, docs/design-review.md and the repo-prose skill, then the full diff and each changed function in context (cache.rs pin/unpin/compact/stats, scheduler.rs admission/ticket/boundary/retire, metrics.rs render/scheduler/snapshot, docs/api.md), plus the issue it closes (#537).

Six findings recorded in the scratchpad, judged against AGENTS.md §"Required PR descriptions" (four-part scheme, precise before/after, evidence tied to claims) and principle 16 of docs/design-review.md.

Two blocking-adjacent accuracy problems in the new api.md paragraph: it says both gauges are "read from scheduler state on each scrape", but they are atomics the worker publishes only on iterations where it made progress (runtime.rs:1148-1153), so a scrape can be stale; and the documented request/total ratio paragraph omits that the reserved pages introduced one sentence earlier are also outside the share (scheduler.rs:1216-1229).

The description itself overstates coverage in two ways: pages popped from the free list into an inbound host-restore ticket are in neither gauge while a request is in RequestPhase::Inbound (scheduler.rs:1699-1741), and "a page shared through a pinned ancestor counts once for every request" is the opposite of the implementation and of the PR's own request_pins_count_each_shared_page_once test, which asserts 3 rather than 4.

Three nits: the JSON-snapshot omission is unstated in api.md, and "a checkpoint leaves nodes only at zero pins" is inaccurate for compaction, which removes ancestors with nonzero pins that the heir carries.

Every finding was verified in the code by reading; each note says what a test would settle.

#8 [high] Review frame: rules applied and their citations

Rules used for this Prose-lens review (all read in full):

Note on scope: the PR does satisfy the four-part structure and labels its measurement ("Live scrape on the local two-GPU DeepSeek-V4.1-Flash setup", "No comparison with another runtime is claimed", "Not run here: the Windows build and the full helios suite"). The findings are about specific sentences inside "What changed", "Claimed result" and the new api.md paragraph, not about the overall scheme.

#5 [medium] Nit: api.md does not say the new gauges are Prometheus-text only

docs/api.md:298-306 introduces the two new gauges inside the paragraph list of what the Prometheus text adds "beyond the JSON fields below" (api.md:287-296), but never says they are absent from the ?format=json snapshot. Code: Snapshot (helios/src/server/metrics.rs:68-129) has no request_pages / reserved_pages field; Metrics::snapshot (:355-393) never sets them; they exist only as atomics rendered in the text (:1310-1318). A dashboard fed by GET /metrics?format=json (the documented path at api.md:307-314) gets no such field and no indication why.

Fix: end the paragraph with "Neither appears in the JSON snapshot." The author already states this in the PR description, so the doc sentence is just missing.

#6 [medium] Nit: description's "leaves nodes only at zero pins" is wrong for compaction

PR description: "Compaction asserts that the removed ancestor and its heir agree on request pins, and a checkpoint leaves nodes only at zero pins."

Second half is inaccurate. cancel_publication requires node.pins == 0 (helios/src/cache.rs:650) and leaf eviction only picks a candidate with pins == 0 && child_count == 0 (helios/src/cache.rs:659-663), so leaves do leave at zero pins. But compact_ancestor runs for a candidate matched by the second clause direct_pins == 0 && child_count == 1 (helios/src/cache.rs:662, 686-690), which permits pins > 0, and the new assertion it adds is debug_assert_eq!(node.request_pins, child.request_pins) (helios/src/cache.rs:627) — the ancestor can therefore be removed with nonzero pins and nonzero request_pins, because the heir carries them. What the change actually guarantees is that no request pin is lost when an ancestor is folded into its heir.

Fix: "Compaction asserts that the removed ancestor and its heir agree on request pins, so folding an ancestor into its heir preserves the request pin count and the pages it covers; leaf retirement still requires zero pins."

Same imprecision in the code comment at helios/src/cache.rs:626 ("Both nodes are counted or neither is, and the pages move into the counted heir") only reads oddly; it is defensible. The description sentence is the one to fix.

#9 [medium] Checked and found sound; one evidence gap (commit message body not read)

Candidates verified as sound, so not reported as findings:

Evidence gap I could not close: search_history returns only the commit subject — "Report KV pages held by active requests" (5ed7af86, Wynn Drahorad) — so I reviewed the PR description, not the full commit message body. If the commit body repeats the sentences I flagged (shared-ancestor counting, "leaves nodes only at zero pins"), the same repairs apply there; AGENTS.md:38-41 requires the message to pass the same check.