Review — PR #549 "Report KV pages held by active requests" (correctness lens), head 9cca87a
Verdict: clean — no blocking or should-fix issues; five nits. Both substantive findings from my earlier pass ("Keep page gauges out of the copy-out retry key", 9cca87ac) are verified fixed in the head, and I re-audited the pin accounting and counter invariants it touched.
Key findings
- Request pin/release symmetry holds on every path. Every request-owned pin is taken through
pin_requestand released throughunpin_request; the invariant "LiveRequest::prefix == Some(id)iff onedirect_request_pinsis held onid" holds on admission (with and without an inbound restore), both ticket outcomes, bothpublish_boundaryoutcomes, cancel, preemption, finish, and retirement. No path mixes the two APIs, so the new hard error "checkpoint has no request pin to release" (helios/src/cache.rs:566-568) is unreachable today. request_pinned_pagescannot drift or underflow. It is adjusted only at the 0↔1 transitions ofrequest_pins(cache.rs:551-580), and everynodesremoval is gated onpins == 0, which impliesrequest_pins == 0. The test-only assertion inCache::stats(cache.rs:818-837) now compares it against a full scan of all checkpoints on every read, so any regression fails the whole suite rather than one test.- The "no scheduling decision changes" claim now holds. The two new
SchedulerStatsfields are explicitly zeroed when theCopyoutResourcescomparison key is built (helios/src/server/runtime.rs:2441-2454, compared at 2455), so page movement between reserved and private pages no longer re-offers deferred host copy-outs. - No correctness regressions in the gauges' plumbing: additive Prometheus gauges inside the existing gauge block (
helios/src/server/metrics.rs:1309-1318), absent fromSnapshot::snapshot()(metrics.rs:355-393) as the PR body says, and no otherSchedulerStatscomparison exists in the tree.
Previously raised findings, verified resolved
- Gauges no longer leak into the copy-out retry key.
helios/src/server/runtime.rs:2441-2454builds the key withscheduler: crate::scheduler::SchedulerStats { request_pages: 0, reserved_pages: 0, ..self.scheduler.stats() }, andself.copyout_resources != Some(resources)at 2455 is the only comparison ofSchedulerStatsanywhere (CopyoutResourcesdeclaredPartialEqat 1053-1059; other uses of the type are construction and reads at scheduler.rs:113/666/762/1200, dashboard.rs:993, metrics.rs:50/476/1497/1574/1632/1701/1784). Page-boundary movement incommittherefore no longer triggers a re-offer. retirereleases the request pin before emptying the slot.helios/src/scheduler.rs:3149-3155records the publication if needed and callsself.cache.unpin_request(prefix)?, thenself.slots[handle.slot as usize].request.take()at 3157. A failing release now leaves the request, its prefix and its pages intact and retryable instead of dropping the request value and leaking the pin. Behaviour-preserving:record_publicationandunpin_requestgo throughself.request(handle)?(3151-3152), and nostatsread happens inside the window, so a scrape cannot observe the transient state.docs/api.mdno longer overstates the ratio.docs/api.md:298-312now says request-pinned checkpoints are also counted inflare_cached_kv_pages, that neither gauge counts pages draining through retirement or an in-flight restore ticket, that reserved pages sit outside the request gauge sorequest + reservedis the vLLM-comparable figure, that the values are last-published, and it cites theCache::statsdrift assertion (cache.rs:818-837) instead of an inequality. This matchesSchedulerStats::request_pages(scheduler.rs:1216-1222, sumsprivate_pagesonly over slots whoserequestisSome) andretire's move of pages intoself.retireduntiladvance_retirement(scheduler.rs:3177-3191, 3033-3053).
Re-verified correct in this pass
pin_prefix/unpin_prefixdeduplication preserves pin kind.helios/src/scheduler.rs:2025-2040dispatches on abool; the flag isinbound.is_none()at admission (1643), true exactly when the pin belongs to the request itself, while a ticket parent (inbound.is_some() && creating, 1634-1642) keeps plainpin/unpin, matchingfinish_inbound(1871 plain unpin ofticket.parent, 1889pin_requestper waiter) andfail_ticket(1907). It is a pure deduplication of threeif inbound.is_none()blocks and cannot invert a kind.- Counter invariants.
pinrejects overflow ondirect_pinsand on every chain node'spins(cache.rs:524-528) beforepin_requesttouches anything, andunpin_requestrejects the release atdirect_request_pins == 0(cache.rs:566-568) before decrementing, so the only route to a wrong count is an unpair, which I could not find.chainincludesiditself (cache.rs:312-321), sorequest_pinsis the full subtree sum andcompact_ancestor'sdebug_assert_eq!(node.request_pins, child.request_pins)(627) holds whendirect_pins == 0andchild_count == 1;request_pinned_pagesis unchanged by compaction because the pages move into the counted heir.advance_completed(787-814) flips readiness and releases retirement storage without touching pins or tail pages. - No double counting across a scrape.
request_pagesadds live slots'private_pagestocache.request_pinned_pages; private pages are drained into a checkpoint exactly whenpublish_boundary/retirepublish it, and that checkpoint is request-pinned in the same call (2977-2984, 3164-3166), so a page is never in both terms.reserved_pagesare disjoint fromprivate_pages(commitpops reservations into private, 2433-2444). - Metrics plumbing. Both gauges are stored unconditionally in
Metrics::scheduler's array (metrics.rs:517-518), rendered as gauges besidecached_kv_pages(1309-1318), absent from the JSON snapshot (355-393), and the dashboard (dashboard.rs:993) anddocs/prefix-cache-offload.md:747(not opened) (host fields only) need no change. Test rows atmetrics.rs:1784-1840cover the names, types and values, andrequest_kv_pages_count_shared_prefix_pages_once/request_pins_count_each_shared_page_oncecover the semantics.
Nits
docs/api.md:302-303— "The worker publishes both on every scheduler pass" overstates it:self.metrics.scheduler(self.scheduler.stats())runs only whenprogressis set (helios/src/server/runtime.rs:1148-1153), plus once at startup (722) and once after a drained shutdown (745). A scrape during idle therefore reads the value of the last progressing pass. "Publishes both on scheduler passes that make progress" would be exact.- Coverage: the new scheduler test (
helios/src/scheduler/tests.rs:970-1035) drives onlyretire'sNonepublication path. Nothing exercisespublish_boundary'sExisting { ready: true }re-pin (scheduler.rs:2994-3006), the one place a request swaps its own parent's request pin for a checkpoint another request already pinned — exactly where a double count or a missing pin would hide. Thestatsdrift assertion (cache.rs:818-837) would catch a cache-side error there, but no test reaches that path. Cheap fix: assertstats.request_pagesbefore and after a second request's boundary publication onto an existing checkpoint. docs/api.mdfield table (from line 332) gains no rows for the two gauges, so a reader of only the table will not learn they exist; only the prose at 298-312 names them. Add a row each with "none" in the Prometheus column, or state that they are text-only.- Process (not a code defect): the PR is still a draft and CI reports no checks on head
9cca87a; the live-scrape evidence builds on fork commit5ffe4d54, which is not in this repository, so the measurements cannot be reproduced from this branch alone. pin_prefix/unpin_prefixcarry the pin kind as a barebool(scheduler.rs:2025-2040); with one call-site pair the risk is low, but an enum orRequestPinmarker would turn an inverted argument into a compile error if the API spreads.
Open questions / could not verify
- Nit 2 cannot be settled from the code alone: a scheduler test that publishes a second request's boundary onto an existing ready checkpoint and reads
SchedulerStats::request_pagesbefore and after would confirm the re-pin path. - The pass count in the PR body (508 tests in
--lib -- cache:: scheduler:: server::metrics) is taken on trust; I read the named tests but did not run the suite here. CI covers it on the next push. - Whether the live ratios (0.0186/0.0187) are representative of a non-fork base cannot be checked, because the fork commit
5ffe4d54is external to this repository.
Nothing in the changed code, its callers, the supported platforms, or the persisted/JSON formats is left unread for this lens. Finding nothing blocking is the finding.