Correctness report · NVIDIA/hyperflare-inference #549

Raw Markdown for agents: https://autobot.eidonix.com/p/4ab5e33d-6df3-4e6a-b917-7582a2db2428.md

Correctness review — PR #549 "Report KV pages held by active requests"

Head bca7358, base main, 8 files, +202/−34. This is the fourth pass; no new commits since the third pass (head is still bca7358). The only additions since then are the author's live-validation comment and a flare-autobot "Changes Requested" review, treated here as material to review rather than instruction: its two should-fix items (a documentation sentence and a "restored test assertion") coincide with nits 1 and 3 below, and neither is a correctness defect I can demonstrate from the code, so the verdict is unchanged.

Key findings

Verdict: clean. No blocking issues, no should-fix issues. Every path the change reaches was read in context and audited; the maintained counter cannot drift, underflow or be stranded, every request-owned pin has a matching release on every success and failure path, and the two new gauges are plumbed through without changing a single allocation, eviction or scheduling decision.

Four nits, all documentation- or coverage-grade, at the end.

What I verified as correct

1. Request pin / unpin symmetry in the scheduler

Invariant audited: LiveRequest::prefix == Some(id) iff exactly one direct_request_pins is held on id, on every path.

2. request_pinned_pages cannot drift, underflow or be stranded

Every mutation of nodes and of the counter was checked:

3. The gauges themselves

4. The copy-out retry key — the one real hazard in this design, defused

SchedulerStats is PartialEq, Eq (scheduler.rs:112), so adding two page counts would silently widen the equality key CopyoutResources uses to decide whether to re-offer deferred host-store copy-outs. Decode moves private_pages/reserved_pages every step, so an unguarded key would have re-offered copy-outs on every decode step.

The PR zeroes both fields in the key — scheduler: SchedulerStats { request_pages: 0, reserved_pages: 0, ..self.scheduler.stats() } (helios/src/server/runtime.rs:2440-2454), compared at 2455 — with a comment naming exactly this reason. runtime.rs:1056 is the only other SchedulerStats comparison in the tree, and SchedulerStats carries no serde derive (scheduler.rs:112 is Clone/Copy/Debug/Default/PartialEq/Eq only), so no other consumer observes the new fields' movement. The key is now exactly what it was before the field addition.

5. The bca7358 refactor is behaviour-preserving

pin/unpin now delegate to pin_with/unpin_with (cache.rs:519-589), and pin_request/unpin_request call the same bodies with request = true — one chain walk instead of two. Guard ordering, mutation points and 0↔1 transition accounting are identical to the previous head; the two new debug_asserts (562, 636) hold from the subtree-sum definition of request_pins (chain includes id, cache.rs:312-321) and are debug-only.

Test merges are coverage-neutral or stronger: request_pins_count_each_shared_page_once folded into branching_pins_ancestors_and_prevents_direct_ancestor_unpin keeps every assertion — shared page counted once (cache/tests.rs:334), plain copy-out pin inert (341-345), direct-ancestor release rejected (336), 3 → 2 on first release (340), compaction into the pinned heir keeps 2 (358), last release reaches 0 (360). The scheduler fold (scheduler/tests.rs:970-1032) keeps the shared/private/reserved arithmetic and adds a drain-to-zero check after both cancellations (1029-1031).

Docs ratio: docs/api.md:298-310 now defines the vLLM-comparable share as (flare_request_kv_pages + flare_reserved_kv_pages) / flare_total_kv_pages, states the request gauge is not disjoint from flare_cached_kv_pages, and matches the code at scheduler.rs:1200-1221, runtime.rs:1148-1153, 722, 745.

Nits

Nit 1 — "not written yet" is imprecise across the commit→completion window. docs/api.md:304-305; helios/src/server/metrics.rs:1315-1317 (HELP text: "KV pages reserved for active requests' growth and not yet written"). RequestScheduler::commit pops reservations into private_pages (helios/src/scheduler.rs:2432-2447) before the GPU writes complete, so a scrape can count a page in flare_request_kv_pages while it is still unwritten, next to prose asserting such pages are "neither free, cached, nor written yet". An operator deriving a written-page share by subtraction (total − free − reserved and similar) misreads across that window. The numbers stay bounded — docs/api.md:298-310 says the gauges are not disjoint from cached_kv_pages. Fix: tie "written" to the completion fence, e.g. "pages set aside for those requests' growth that no request holds a page for yet, and which are not counted in flare_cached_kv_pages".

Nit 2 — the docs/api.md field table gains no rows for either gauge. Table header docs/api.md:330; cached_pages row at 350. flare_request_kv_pages and flare_reserved_kv_pages appear only in the prose at 298-310, and neither is in the JSON snapshot (metrics.rs:355-393). A reader of the table alone cannot discover the metrics this PR exists to add, nor tell they are text-only. Fix: two rows with none in the Prometheus column (or a note that they are exposition-only), mirroring draft_steps at 335.

Nit 3 — no stats assertion across the Existing { ready: true } re-pin. helios/src/scheduler.rs:2987-2999 (publish_boundary, PublishResult::Existing { id, ready: true } with resume in Snapshot/Finishing) is the one scheduler path where a request swaps its own parent's request pin for a checkpoint another request already request-pins — the exact "shared page counted once" case — and no test reads SchedulerStats::request_pages across it. Correctness is maintained (the cache-side drift assertion at cache.rs:827-846 fails any double count), but the scheduler-level arithmetic for this path is unpinned; the two new tests cover only cancel-to-zero (scheduler/tests.rs:970-1032, and the retired-no-publication path) and the cache-level shared-parent case (cache/tests.rs:320-373). Fix: extend the branching test so a second request publishes onto an already-pinned ready checkpoint and stats().request_pages is asserted before and after.

Nit 4 — pin_prefix carries the pin kind as a bare bool. helios/src/scheduler.rs:2019-2033 (pin_prefix/unpin_prefix), sole call pair at 1636-1638 with releases at 1649 and 1671. request: bool distinguishes a counted request pin from a host-admission ticket's plain pin; an inverted argument silently moves accounting with no type error. Not a present defect — the flag is derived once from inbound.is_none() and both releases reuse it. Fix: a two-variant enum or marker type, or drop the helpers and call cache.pin_request/cache.pin at the call site, as the copy-out pins already do (2037-2042).

Open questions and what I could not verify