Correctness report · NVIDIA/hyperflare-inference #549

Raw Markdown for agents: https://autobot.eidonix.com/p/1de9f4a7-8734-4747-ac71-49e21b39e98d.md

Review — PR #549 "Report KV pages held by active requests" (correctness lens)

Key findings

Verified-correct: request pin/unpin symmetry

Every request-owned pin goes through pin_request and every release through unpin_request, so the invariant "LiveRequest::prefix == Some(id) iff one direct_request_pins is held on id" holds on all paths:

I found no path that takes a plain pin and releases _request (which would now be a hard error and, in retire, would leak the prefix pin because the request has already been taken out of the slot at 3143 — see the nit below).

Verified-correct: the counter cannot drift or underflow

helios/src/cache.rs:

Should fix

1. CopyoutResources equality now depends on the new gauges, so copy-out retry cadence changes

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)>,
}

and helios/src/server/runtime.rs:2441-2449

let resources = CopyoutResources { .., scheduler: self.scheduler.stats(), .. };
let retry_copyouts = retry || progress || self.copyout_resources != Some(resources);
self.copyout_resources = Some(resources);

SchedulerStats derives PartialEq (helios/src/scheduler.rs:112-149), so request_pages and reserved_pages become part of the key that decides whether a copy-out deferred for headroom (self.deferred_copyouts, filled at 2464-2470) is re-offered to store.store on this pass.

Why it matters: those two fields change when pages move between a request's reserved_pages and private_pages — commit at 2433-2438 — which happens whenever a decode crosses a page boundary, without free_pages or cached_pages moving at that instant (the pages were already popped from free_pages into the reservation by refill_reservations, 1417-1425). So a deferred copy-out is now retried roughly once per page-boundary crossing per live request instead of only when cache resources actually moved, and each retry goes through pin_checkpoint + store.store (2473-2474) and the host_reoffer_* counters (2475-2487). The PR body claims "No allocation, eviction, or scheduling decision changes"; this is one.

Two things I checked and that are not problems, so they should not be cited as such:

Fix: keep the comparison key to cache-resource movement — build a small ResourceKey from the fields CopyoutResources actually needs (completed fence, free/retiring/cached pages, snapshot backing, pending retirement, exports, next admission) or compare a SchedulerStats copy with the two new gauges zeroed. Settled by: a runtime test that leaves one copy-out deferred for headroom, advances one decode step that crosses a page boundary (moving pages from reserved_pages to private_pages while free_pages and cached_pages are unchanged), and asserts FakeStore saw no second store call — it would fail today and pass after the fix.

Nits

2. docs/api.md promises a KV-share ratio the gauge does not compute during drain

docs/api.md:298-305 says flare_request_kv_pages "counts the distinct KV pages that active requests reference" and that "Dividing flare_request_kv_pages by flare_total_kv_pages gives the KV share held by live requests". SchedulerStats::request_pages (helios/src/scheduler.rs:1216-1222) sums private_pages only over slots whose request is Some(..). RequestScheduler::retire (3143-3183) takes the request out of the slot first and pushes its private_pages + reserved_pages into self.retired, which returns them to free_pages only at the GPU fence (advance_retirement, 3027-3046). A scrape taken between cancellation/completion and the drain therefore counts those pages in neither request_pages nor reserved_pages, while flare_free_kv_pages also still excludes them — so both gauges under-report consistently and the ratio dips. The wording "live requests" is what overclaims; active_requests (1203-1207) uses the same definition, so the gauges agree with each other. Fix: say "pages held by requests still owning a slot", or say the ratio excludes pages still draining. Settled by: a scheduler test that cancels a request with pages in flight and inspects request_pages for that window.

3. retire returns the ? error from unpin_request after it has already emptied the slot

helios/src/scheduler.rs:3143 (self.slots[..].request.take()) runs before 3159 (self.cache.unpin_request(prefix)?) and before 3169 (retiring = true) and 3171 (self.retired.push(..)). If unpin_request ever returned Err (the new "checkpoint has no request pin to release", 566-568), retire would propagate it with the request value dropped, the prefix pin leaked (the checkpoint stays pinned forever even though no request references it) and the slot left non-retiring with no request. This cannot fire given the symmetry verified above, but the new error path makes the failure mode worse than before, when a plain unpin on an unpinned checkpoint was equally impossible. Consider taking the pin before request.take(), or keeping the request in the slot until the release succeeds, so a future unpair bug is a leak rather than silent data loss.

4. Coverage and surface gaps

Open questions / could not verify