#1 [high] Verified: request pin/unpin symmetry across scheduler
Files: helios/src/scheduler.rs, helios/src/cache.rs (PR #549 head 5ed7af8).
Request-owned pins (grep cache.(un)?pin(_request)?):
- admission helios/src/scheduler.rs:1643-1649:
pin_requestonly wheninbound.is_none(); when an inbound restore is being created the plainpinis taken onlookup.checkpoint(the future ticket parent) and released with plainunpininfinish_inbound(1881-1883) andfail_ticket(1917-1919). Symmetric. The two error paths (Context 1658-1664, ensure_resources 1684-1690) repeat the sameif inbound.is_none()choice, so a request pin is never taken and released with the plain API. finish_inbound1900:pin_request(id)per waiter, immediately beforerequest.prefix = Some(id)(1902). Waiters retired earlier (!readybranch 1884-1891,fail_ticket) still haveprefix == None(phase Inbound), soretirenever unpins a prefix they do not hold.publish_boundary2966-2979 (Created) and 2988-3000 (Existing):pin_request(new)strictly beforeunpin_request(parent)and beforerequest.prefix = Some(new); new != parent because the proposal must strictly extend the parent.retire3155-3159:unpin_request(prefix)for exactly the prefix the request pinned.pin_checkpoint/unpin_checkpoint(2038-2044) keep the plain API; used only for host-store copy-out (server/runtime.rs:2360,2364,2396,2473,2489) and export (2698,2703), never against a request's prefix.
Conclusion: LiveRequest::prefix == Some(id) implies exactly one direct_request_pins on id, on every path I read (admission with/without hit, host-restore creating/joining, boundary publication Created/Existing, cancel, cancel-before-inference, preemption, finish, release_after_shutdown). No path found that pins plain and unpins _request (which would now turn into a hard error and leak the slot, since retire takes the request out of the slot at 3143 before unpinning).
#2 [high] Verified: request_pinned_pages counter cannot drift or underflow
helios/src/cache.rs:
pin_request/unpin_request(551-580) increment/decrementrequest_pinsoverchain(id)and add/subtracttail_pages.len()only at the 0↔1 transitions, matching the#[cfg(test)]full-scan assertion 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; andrequest_pinned_pagesis unchanged by compaction because the removed node's pages move into a heir that is either counted before and after, or uncounted before and after.retire_leaf(594) /compact_ancestoronly run throughevict_checkpoint(682, requires an eviction candidate:pins == 0for leaves),cancel_publication(648, requirespins == 0) —request_pins <= pins, so a node leavingnodesalways hasrequest_pins == 0and never contributes torequest_pinned_pages;retire_leaf/uncounttherefore need no adjustment.advance_completed(787) only flipsready, no pin or tail-page change.pinrejectsu64::MAXondirect_pinsand every chain node'spins(524-528);pin_requestcallspinfirst, sorequest_pinscannot overflow before the plain count does.unpin_requestrejects a release whendirect_request_pins == 0(566-568) before touchingrequest_pins, so the only way to underflowrequest_pinned_pageswould be an unpair error, and I found none.
SchedulerStats::request_pages (1216-1222) = sum of live slots' private_pages.len() + cache.request_pinned_pages. private_pages are drained into the checkpoint exactly when publish_boundary/retire publish them (2978, 3150-3152), and that checkpoint is pinned for the request at the same time, so the same page is not counted twice; reserved_pages are disjoint from private_pages (commit pops reserved into private, 2433-2438).
#3 [high] Should fix: new gauges leak into CopyoutResources equality and change copy-out retry cadence
helios/src/server/runtime.rs:1053-1059 defines CopyoutResources as { completed, scheduler: SchedulerStats, exports, next } deriving PartialEq, and 2441-2449 compares it every host-store pass:
let resources = CopyoutResources { completed: .., scheduler: self.scheduler.stats(), exports: .., next: .. };
let retry_copyouts = retry || progress || self.copyout_resources != Some(resources);
self.copyout_resources = Some(resources);
let deferred_copyouts = std::mem::take(&mut self.deferred_copyouts);
for id in &deferred_copyouts { ... if retry_copyouts { publications.push(publication) } else { self.deferred_copyouts.push(*id) } }
for publication in publications {
if !self.scheduler.export_fits(publication.id, next) {
if !deferred_copyouts.contains(&publication.id) {
self.metrics.copyout_headroom_deferrals.fetch_add(1, ..);
progress = true;
}
self.deferred_copyouts.push(publication.id); continue;
}
...pin_checkpoint + store.store(publication)...
}
Before this PR, SchedulerStats only carried values that change on admission, retirement, eviction, or fence progress, so copyout_resources != Some(resources) was a coarse "cache resources moved" signal. The two new gauges change on nearly every decode step: commit (helios/src/scheduler.rs:2433-2438) pops pages out of reserved_pages into private_pages for every scheduled lane, and refill_reservations (1383-1425) appends to reserved_pages again; retire/finish_early also move pages between them. So for any live request the struct now differs on essentially every step, retry_copyouts becomes true nearly always, and each deferred copy-out is re-offered to store.store on every step instead of only when cache resources actually moved. When it still does not fit, flare_host_cache_copyout_headroom_deferrals_total (metrics.rs ~?) is incremented again for each retry, and progress = true propagates.
Effect: an instrumentation-only change alters host-store copy-out retry cadence and inflates a documented counter (docs/prefix-cache-offload.md:1171 headroom). It also contradicts the PR's "No allocation, eviction, or scheduling decision changes" claim.
Fix: keep CopyoutResources sensitive only to cache-resource movement — either store the fields it needs explicitly (free/retiring/cached pages, snapshot backing, pending retirement) or exclude request_pages/reserved_pages from the comparison, e.g. a small ResourceKey struct built from SchedulerStats without the two new gauges.
Settled by: a runtime test that defers a copy-out for headroom, advances one decode step that changes only reserved_pages/private_pages, and asserts copyout_headroom_deferrals does not increase (would fail today, pass after the fix).
#4 [high] Research summary
I read all seven changed files in context (cache.rs, cache/lifecycle_tests.rs, cache/tests.rs, scheduler.rs, scheduler/tests.rs, server/metrics.rs, docs/api.md) plus the callers that matter (server/runtime.rs host-store loop and admission, scheduler/sharing.rs, scheduler/checkpoints.rs, scheduler/cache_memory.rs), and checked the change against AGENTS.md, docs/design-review.md and the charter.
The pin accounting itself holds up. Every request-owned pin now goes through pin_request/unpin_request, and LiveRequest::prefix == Some(id) implies exactly one direct_request_pins on id on every path I traced: admission with and without an inbound restore (including both early-error rollbacks), finish_inbound for created and joined tickets, publish_boundary for Created and Existing results, and retire for cancel, preemption and finish. The ticket-parent pin and the host-store copy-out/export pins correctly keep the plain API and are released with the plain API. The cache-side counter cannot drift or underflow: retire_leaf and compact_ancestor only run on nodes with pins == 0, advance_completed does not touch pins or pages, pin still guards overflow, and unpin_request rejects a release before decrementing.
One confirmed finding, recorded as "Should fix" in the scratchpad: the two new SchedulerStats fields silently widen CopyoutResources (helios/src/server/runtime.rs:1053-1059), whose PartialEq gates retry_copyouts at 2441-2449. request_pages/reserved_pages change on nearly every decode step (commit moves pages from reserved_pages to private_pages, refill_reservations grows them back), so deferred host-store copy-outs now re-offer to store.store every step rather than only when cache resources moved, and flare_host_cache_copyout_headroom_deferrals_total inflates. That contradicts the PR's "no allocation, eviction or scheduling decision changes" claim. Fix: keep the comparison key to cache-resource movement only.
I had also started checking the doc claim that dividing by flare_total_kv_pages "gives the KV share held by live requests" — request_pages sums private_pages per live slot plus deduplicated checkpoint tail pages, which is the intended pool measure, but pages held only by retired-but-unfenced slots (self.retired) are excluded, so a scrape taken while a cancelled request's pages are still draining under-reports; that is a documentation nit I did not finish verifying against the release path.
#5 [medium] Nit candidate (unverified): request_pages excludes retired-but-unfenced slot pages
docs/api.md:298-305 (PR #549) 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.len() only over self.slots whose request is Some, plus cache.request_pinned_pages. RequestScheduler::retire (helios/src/scheduler.rs:3143-3183) takes the request out of the slot (self.slots[..].request.take()) and pushes its private_pages + reserved_pages into self.retired until advance_retirement reaches its fence (3027-3046). So between cancellation/completion and GPU drain those pages are neither free, cached, nor counted in request_pages/reserved_pages; a scrape in that window under-reports the "live share", and during shutdown drain (release_after_shutdown, 3068-3086) it drops to the cached-only level.
Also active_requests (1203-1207) has the same definition (slots with a live request), so at least the two gauges are consistent with each other; the exposure is only in the doc sentence promising a vLLM-comparable ratio, and in the issue #537 rationale. Settled by a scheduler test that cancels a request with pages in flight and asserts request_pages for that window, or by wording the doc as "pages held by requests still owning a slot".
Not verified: whether the resulting discrepancy is material at the documented poll interval, and whether flare_free_kv_pages also lags the same way (it does: retired pages return to free_pages only at the fence, 3037).
#6 [medium] Verified: metrics/dashboard/test wiring for the two new gauges
helios/src/server/metrics.rs:
request_pages/reserved_pagesatomics (265-266) are stored inMetrics::scheduler's store loop (517-518) and rendered as gauges (1310-1318) withmetric(.., "gauge", ..)inside the gauge block that ends at 1397; thetotal_kv_pages/kv_page_tokens/*_kv_tokensblock follows after it, so the text format stays valid. Noflare_request_kv_tokensequivalent — fine, consistent with the PR description.Metrics::snapshot(355-393) does not copy them into the JSONSnapshot, matching the description;Snapshothas no such fields sodocs/api.md's field table (325+) is untouched. That is consistent but the doc prose in the "Health and metrics" section now describes gauges absent from the JSON object — acceptable since it says "Beyond the JSON fields below, the text includes ...".SchedulerStatsderivesDefault, soSchedulerStats { ..Default::default() }literals at helios/src/server/metrics.rs:1497,1574,1701,1784 and helios/src/server/dashboard.rs:993 still compile; the two new fields default to 0. The dashboard test at dashboard.rs:1034 asserts "KV TOKENS 384 cached / 2560 free / 12800 total" and "!" contains("KV PAGES"), so the dashboard does not render the new gauges — no break there, but also no dashboard exposure.- Test-only drift assertion (cache.rs:819-837) now also compares
request_pinned_pagesagainst a fullnodesscan on everystats()call, so all cache/scheduler tests exercise the counter;Cache/tests.rs:318-341covers shared-page double counting and the wrong-API release error;scheduler/tests.rs:970-1035coversrequest_pages/reserved_pagesat two concurrent share-prefix requests and zero after cancel. The new test callsscheduler.cancel(first)thencancel(second)and asserts both gauges are 0 — becauserequest_pagesexcludes retired-but-unfenced slots (see the separate note), this assertion passes only if cancel returns pages synchronously enough in that fixture; worth knowing if the test is copied as a template. helios/src/cache/lifecycle_tests.rs:53-96forksPrefixCheckpointCacheby struct literal and was updated with the two new node fields andrequest_pinned_pages; that is the only place that must track new fields, so the fork stays in sync.
Gaps: no test drives pin_request through the shared-checkpoint Existing path in publish_boundary (2988-3000), i.e. the second request that reuses a just-published boundary checkpoint; and none covers the inbound-created ticket path's plain pin/unpin against the drift assertion, though the drift assertion in stats() would catch a mismatch in any test that exercises it. PR is still a draft with no CI checks recorded.