Review — PR #549 "Report KV pages held by active requests" (correctness lens)
Key findings
- The pin accounting itself is correct. I traced every request-owned pin and release in
helios/src/scheduler.rsand everynodesmutation inhelios/src/cache.rs; the newdirect_request_pins/request_pins/request_pinned_pagescounters match reality on admission (with and without an inbound restore), bothpublish_boundaryoutcomes, cancel, preemption, finish and shutdown release. No path pins with one API and releases with the other. The test-only full-scan assertion inCache::statsmakes this cheap to keep true. - One real, unintended reach:
SchedulerStatsderivesPartialEqand is embedded whole inCopyoutResources(helios/src/server/runtime.rs:1053-1059), whose comparison at 2441-2449 decides whether deferred host-store copy-outs are re-offered. Adding two live-request gauges to that struct changes a behavioural decision, contradicting the "No allocation, eviction, or scheduling decision changes" claim in the PR body. The effect is bounded (roughly one extra re-offer per page-boundary crossing) but the coupling is accidental and cheap to remove. - One documentation overstatement:
docs/api.md:298-305promises thatflare_request_kv_pages / flare_total_kv_pagesis "the KV share held by live requests", butSchedulerStats::request_pages(helios/src/scheduler.rs:1216-1222) only sums slots that still hold a request; pages of retired-but-unfenced slots live inself.retired(helios/src/scheduler.rs:3143-3183, released at 3027-3046) and are counted nowhere. - Nothing blocking. The gauges are additive, absent from the JSON snapshot as described, and rendered inside the existing gauge block of the Prometheus text (
helios/src/server/metrics.rs:1310-1318).
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:
- Admission
helios/src/scheduler.rs:1643-1649:pin_requestis taken only wheninbound.is_none(). When a host restore is being created, the plainpinis taken onlookup.checkpoint(the future ticket parent) and released with plainunpininfinish_inbound(1881-1883) andfail_ticket(1917-1919). The two early-error rollbacks (1658-1664 context error, 1684-1690ensure_resources) repeat the sameif inbound.is_none()choice, so a request pin is never released through the plain API and vice versa. - Ticket completion
finish_inbound(1900-1902):pin_request(id)per waiter immediately beforerequest.prefix = Some(id). Waiters retired early (!readybranch 1884-1891,fail_ticket) still haveprefix == None(phaseInbound), soretirenever unpins a prefix they do not hold. - Boundary publication
publish_boundary2966-2979 (Created) and 2988-3000 (Existing):pin_request(new)strictly beforeunpin_request(parent)and beforerequest.prefix = Some(new);new != parentbecause the proposal must strictly extend the parent, so the request never holds two pins at once (and the transient two-pin window is inside one function call, invisible tostats). - Retirement
retire3155-3159:unpin_request(prefix)for exactly the prefix the request pinned, on cancel, preemption and finish alike. - Non-request pins correctly keep the plain API:
pin_checkpoint/unpin_checkpoint(2038-2044) are used only for host-store copy-out (helios/src/server/runtime.rs:2360, 2364, 2473, 2489) and export (2698, 2703). They never touch a request's prefix, so the new "no request pin to release" error cannot fire from them.
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:
pin_request/unpin_request(551-580) walkchain(id)and add/subtracttail_pages.len()only at the 0↔1 transitions ofrequest_pins, exactly matching the full-scan assertion now instats(819-837).request_pinsis the subtree sum (incremented on every ancestor), socompact_ancestor's newdebug_assert_eq!(node.request_pins, child.request_pins)(627) holds whenever the removed ancestor hasdirect_pins == 0andchild_count == 1;request_pinned_pagesis unchanged by compaction because both nodes are counted or neither is, and the pages move into the counted heir.retire_leaf(594) andcompact_ancestor(613) only run fromevict_checkpoint(682) /cancel_publication(648), both of which requirepins == 0on the node; sincerequest_pins <= pins, a node leavingnodesalways hasrequest_pins == 0and never contributed torequest_pinned_pages, so no adjustment is needed there.eviction_candidates(658-664) enforces the same predicate.advance_completed(787-814) only flipsreadyand releases retired storage; no pin or tail-page change.- Overflow:
pinrejectsu64::MAXondirect_pinsand on every chain node'spins(524-528) andpin_requestcalls it first, sorequest_pinscannot overflow before the plain count does. Underflow:unpin_requestrejects the release whendirect_request_pins == 0(566-568) before decrementing anything, so the only route to a wrong counter is an unpair error, and I found none. SchedulerStats::request_pages(1216-1222) adds live slots'private_pagestocache.request_pinned_pages.private_pagesare drained into the checkpoint exactly whenpublish_boundary/retirepublish them (2978, 3150-3152), and that checkpoint is request-pinned at the same moment, so the same page is not counted twice across a scrape boundary.reserved_pagesare disjoint fromprivate_pages(commit pops reserved into private, 2433-2438).
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:
- The
copyout_headroom_deferralscounter does not inflate: the increment at 2465-2468 is guarded by!deferred_copyouts.contains(&publication.id), anddeferred_copyoutswas taken at 2450 before the loop, so a repeat deferral on the next pass is not counted again. The existing phase test (helios/src/server/runtime/phase_tests.rs:6357-6384, asserts the counter stays at 1 across a secondservice_store) is consistent with that. - The magnitude is bounded and small; I could not show a measurable regression, because
free_pages,cached_pagesandretiring_slotswere already in the key and already vary with page movement and fence progress, so the extra trigger is a strict superset of a pre-existing one rather than a new class of wakeups.
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
- The new scheduler test exercises two concurrent requests sharing a prefix and then
cancelon both (helios/src/scheduler/tests.rs:970-1035), i.e. theNonepublication path ofretire. No test drivespin_requestthroughpublish_boundary's shared-checkpointExistingbranch (2988-3000), which is where one request pins a checkpoint another request just published — the exact case where a double count or a missing pin would hide. Thestatsdrift assertion (819-837) would catch a cache-side error in any test that reaches that path, but none does today. - The dashboard (
helios/src/server/dashboard.rs:993, 1034) and the JSONSnapshot(helios/src/server/metrics.rs:355-393) do not show the new gauges. That matches the PR description for JSON, but the structured schema indocs/api.md(field table from line 325) also remains untouched, so an operator reading the table will not learn the fields exist; only the prose at 298-305 mentions them. - Process: the PR is a draft and CI reports no checks on head
5ed7af8. No Windows build and no full helios run are claimed (PR body, "Not run here"), and the live scrape evidence uses a third-party fork base commit5ffe4d54that is not in this repository, so the measurements cannot be reproduced from this branch alone.
Open questions / could not verify
- Whether the extra copy-out retries from finding 1 are observable in
flare_host_cache_reoffer_calls_totalin a real run; only a runtime test or a scrape during a long deferred copy-out settles it. - How far the
docs/api.mdratio dips during drain (nit 2): the window is one GPU fence, and I could not measure it against the documented scrape interval. - The PR body reports six scheduler/cache test names and 508 passing tests in
--lib -- cache:: scheduler:: server::metrics; I read the three named cache/scheduler tests and the metrics test, but did not run the suite here, so the pass count is taken on trust. helios/src/cache/lifecycle_tests.rs:53-96forksPrefixCheckpointCacheby struct literal and was updated with both new node fields andrequest_pinned_pages; it is the only such fork, so future field additions must keep it in sync. No defect today.