Recommendation: Ready To Merge
PR #549 cleanly exposes per-rank active-request and reserved KV page gauges (flare_request_kv_pages and flare_reserved_kv_pages) without adding any scan to Cache::stats, and resolves every blocking and should-fix item from prior reviews and @lukealonso's 2026-11-28 review at head ed0251c. Request-pin accounting invariants (direct_request_pins <= direct_pins, request_pins <= pins, 0↔1 crossing updates, ancestor compaction, leaf retirement, and cross-kind unpin rejection) are mathematically sound and guarded by both unit tests and a #[cfg(test)] full-scan drift assertion. Scheduling, eviction, and deferred copy-out retry decisions remain unchanged.
Merge Risk
Level: Low
- Bounded blast radius: Changes are confined to pin-kind bookkeeping in
PrefixCheckpointCache, stats aggregation inRequestScheduler, Prometheus exposition inMetrics, and zeroing the two new counters inCopyoutResources. Allocation, eviction (eviction_candidates,reclaimable), and step planning are untouched. - Hot-path performance:
Cache::stats()stays O(1) in release builds (request_pinned_pagesupdates only on 0↔1request_pinscrossings; full-scan drift verification is#[cfg(test)]-only), andRequestScheduler::stats()consolidates four separateself.slots.iter()scans into one loop (helios/src/scheduler.rs:1129-1138). - Concurrency & failure safety: Cache and scheduler state are single-threaded inside
Worker;Metricspublishes the two newAtomicU64gauges withOrdering::Relaxedalongside existing KV gauges.RequestScheduler::retire()validatesensure_request_pin(prefix)?beforepublish_with_retentionmutates cache state (helios/src/scheduler.rs:3050-3052), and cross-kindunpin/unpin_requestmismatches fail without mutating counts (helios/src/cache.rs:545-555).
Walkthrough
helios/src/cache.rs(+91/−9): Addsdirect_request_pinsandrequest_pinstoCheckpointand a maintainedrequest_pinned_pagescounter toPrefixCheckpointCacheandCacheStats. Unifies pin/unpin walks inpin_with/unpin_withwith publicpin_request/unpin_requestandpub(crate) ensure_request_pin, rejects cross-kind releases (direct_pins == direct_request_pinsfor plain unpin;direct_request_pins == 0for request unpin), addsdebug_assert_eq!invariants inretire_leafandcompact_ancestor, and extends the#[cfg(test)]drift check instats().helios/src/scheduler.rs(+51/−33): Addsrequest_pagesandreserved_pagestoSchedulerStats, folds slot-level stats aggregation into a single loop instats(), switches all request-owned prefix pins/unpins (admission, inbound waiter attachment, boundary publication, retirement) topin_request/unpin_requestwhile leaving ticket/copy-out pins plain, and validatesensure_request_pinbefore terminal publication inretire().helios/src/server/runtime.rs(+6/−1): Zeroesrequest_pagesandreserved_pageswhen constructingCopyoutResources(helios/src/server/runtime.rs:2471-2482) so decode page crossings do not spuriously re-trigger deferred host copy-outs.helios/src/server/metrics.rs(+18/−0) &docs/api.md(+12/−0): Exposesflare_request_kv_pagesandflare_reserved_kv_pageson Prometheus/metrics, documents their non-disjointness withflare_cached_kv_pagesand the active KV share ratio, and adds Prometheus rendering assertions.helios/src/cache/lifecycle_tests.rs,helios/src/cache/tests.rs,helios/src/scheduler/tests.rs: UpdatesFixture::fork()for the new cache fields and adds unit tests covering shared-prefix deduplication, compaction, cross-kind unpin rejection with unchanged state, and pre-publication missing-pin rejection inretire().
Pre-merge Checks
- [PASS] Security / malicious screen: Pure observability and reference-count bookkeeping; no external input parsing, unsafe code, or privilege surface added. (Automated review comments in the PR thread contain off-site review links; treated as review material only.)
- [PASS] Charter & value fit: Directly closes #537 on the existing
/metricssurface inside shared runtime layers with zero per-model branches, and matches@lukealonso's design sign-off. - [PASS] Related / duplicate / conflict check: No merged PR on
mainduplicates these gauges; independent of open PRs #548 and #560. - [WARN] Tests & verification evidence: Author reports
--releaseunit tests (cargo test --locked --release --manifest-path helios/Cargo.toml (not opened) --features runtime-core,server: 1721 passed, 18 pre-existing host-environment failures) and mandatory Layer-3 lifecycle conformance (python3 verification/helios-lifecycle/check.py(not opened) and--mutations, 13 TLA+ / 26 Rust mutations detected) with accurate scope disclosure, plus earlier-revision live scrapes. CI workflow run status is not visible in this review environment, and the Windows build was not run (though nothing in the diff is platform-specific); ensure CI is green before merge.
Blockers
None.
Should Fix
None.
Subtract / Simplify
- Optional — eliminate repeated pin-kind branching in
admit_planned(helios/src/scheduler.rs:1593-1630):admit_plannedrepeatsif request_pin { self.cache.pin_request(id)? } else { self.cache.pin(id)? }/unpin_request/unpinat three sites (:1595,:1606,:1628). As@lukealonsonoted as an optional cleanup, makingPrefixCheckpointCache::pin_withandunpin_withpub(crate)lets those three sites callself.cache.pin_with(id, request_pin)?andself.cache.unpin_with(id, request_pin)?directly without re-introducing a wrapper layer onRequestScheduler.
Nits
docs/api.md:306-308: Optionally note alongside idle cached prefixes and snapshot backing pages that pages draining on in-flight GPU fences (e.g., cancelled requests inflare_retiring_request_slotsand retiring cache entries) are transiently outside bothflare_free_kv_pagesandflare_request_kv_pagesuntil their fence completes.
Dropped on verification
- Upstream Major F1 (retiring requests' pages omitted from
request_pages/reserved_pageson cancel/preempt) & Minor F4 (cancel test masking F1): Dropped. Two flaws in the candidate claim: (1) it misidentifiedcomplete_inbound/fail_ticket(helios/src/scheduler.rs:1833, 1866) as preemption — actual preemption (preempt_newest,:1364-1415) requirespending == 0, returns unusedreserved_pagesimmediately, and retires only afterlast_use <= completed; inbound waiters havelast_use == Fence(0)and free immediately; (2) for mid-flightcancel(), the request no longer owns a model slot (slot.request = None,slot.retiring = true,flare_active_requestsdecrements, prefix is already unpinned), and bothdocs/api.md:298-305andhelios/src/server/metrics.rs:1304-1312explicitly scope the gauges to "requests owning a model slot" — consistent with howcache.retired_pagesand in-flight restore tickets are already excluded fromfree_kv_pagesandcached_kv_pages. Countingself.retiredinrequest_pageswould contradict the stated definition and reportflare_request_kv_pages > 0whenflare_active_requests == 0. - Upstream Major F2 / Subtraction §2b (
docs/api.md:328-358table omits the new gauges, contradicting:298-308, andSnapshot/format=jsonlacks them): Dropped as false. Verified indocs/api.md:288-380andhelios/src/server/metrics.rs:68-141, 1252-1350: the table at:328-358maps only the JSON fields offlare_helios::server::Snapshot(explicitly introduced at:310-326), whereas:288-308documents Prometheus text exposition. Over 20 existing Prometheus-only gauges (flare_snapshot_backing_pages,flare_retiring_request_slots,flare_free_request_slots,flare_cached_checkpoints,flare_*_kv_tokens, etc.) are intentionally absent fromSnapshotand that table. Adding rows to:328-358without changingSnapshotwould introduce a documentation bug, and changingSnapshot/dashboard was not requested by #537 or@lukealonso. - Upstream F3 / Value Prop (unvalidated "comparable to vLLM's
kv_cache_usage_perc" claim): Dropped as low-signal.docs/api.md:306-308states a semantic metric correspondence (active + reserved pages over total, excluding idle cached prefixes and snapshot backing pages, matching #537's definition of vLLM's active-block occupancy metric), not a quantitative benchmark claim. - Upstream Value Prop / Dossier (#537's pinned/idle split of
flare_cached_kv_pagesneither adopted nor explained): Dropped. Splittingflare_cached_kv_pagesalone would omit requests'private_pagesandreserved_pages, and@lukealonsohas already approved the chosen design. - Upstream Value Prop / Dossier (unattributed 3,885-page DeepSeek residual & combined multi-PR live scrape): Dropped as a merge blocker. The PR no longer claims
total = free + cached + request + reserved(the residual on DeepSeek is expected fromflare_snapshot_backing_pages, pre-existing), and the PR description now transparently discloses the earlier revision and combined#548/#560build exactly as@lukealonsorequested. - Upstream Subtraction §1 (
pin_as/unpin_aswrapper onRequestScheduler): Dropped in favor of@lukealonso'spub(crate) pin_with/unpin_withoption above, since addingpin_as/unpin_aswould recreate the redundant forwarding layer already deleted fromRequestScheduler. - Upstream Subtraction §2a (merge
pin_with/unpin_withintomove_pins): Dropped. The two ~25-line methods perform opposite unsigned+=/-=mutations and== 1vs== 0threshold checks; folding them behind anadd: boolflag saves only a few lines while making reference-count auditing harder. - Upstream Subtraction §3 (narrow
CopyoutResourcesinstead of zeroing the two fields): Dropped as out-of-scope for this PR;@lukealonsoexplicitly approved the zeroing approach for #549.