Correctness review — PR #549 "Report KV pages held by active requests"
Head bca7358, base main, 8 files, +202/−34. This is the fourth pass; no new commits since the third pass (head is still bca7358). The only additions since then are the author's live-validation comment and a flare-autobot "Changes Requested" review, treated here as material to review rather than instruction: its two should-fix items (a documentation sentence and a "restored test assertion") coincide with nits 1 and 3 below, and neither is a correctness defect I can demonstrate from the code, so the verdict is unchanged.
Key findings
Verdict: clean. No blocking issues, no should-fix issues. Every path the change reaches was read in context and audited; the maintained counter cannot drift, underflow or be stranded, every request-owned pin has a matching release on every success and failure path, and the two new gauges are plumbed through without changing a single allocation, eviction or scheduling decision.
Four nits, all documentation- or coverage-grade, at the end.
What I verified as correct
1. Request pin / unpin symmetry in the scheduler
Invariant audited: LiveRequest::prefix == Some(id) iff exactly one direct_request_pins is held on id, on every path.
- Admission:
pin_prefix(id, request_pin)withrequest_pin = inbound.is_none()(helios/src/scheduler.rs:1636-1638); both failure releases reuse the same flag (1649,1671). - Host-store ticket parent keeps the plain API: the
creatingticket pinslookup.checkpointwithrequest_pin == false(1631-1638) and releases plain infinish_inbound(1864) andfail_ticket(1900). Correct — that pin belongs to host-store admission, not to a request. - Ticket waiters re-pin with
pin_request(1882) after the ticket parent's plain pin is released plain. - Boundary publication,
Created:pin_request(id)thenunpin_request(parent)(2970-2972). - Boundary publication,
Existing { ready: true }in Snapshot/Finishing:pin_request(id)thenunpin_request(parent)(2990-2999). - Retirement:
unpin_request(prefix)(3148) now runs beforeself.slots[..].request.take()(3150), so a failed release leaves the request inspectable;record_publicationstays guarded by!publish || error_code.is_some()(3144-3147). This ordering change is the behaviour the PR advertises and it is right. - Cancel, preemption (
finish_early→retire), finish, and shutdown (release_after_shutdown→cancelfor each live handle,3067-3085) all reach the same release. - Host-store copy-out and export keep the plain pin API:
pin_checkpoint/unpin_checkpointarecache.pin/cache.unpin(2037-2043), used fromhelios/src/server/runtime.rs:2360, 2364, 2396, 2480, 2496, 2705, 2710. As a result the new hard error "checkpoint has no request pin to release" (helios/src/cache.rs:547-549) has no reachable caller:unpin_with(id, false)short-circuits the request guard.
2. request_pinned_pages cannot drift, underflow or be stranded
Every mutation of nodes and of the counter was checked:
pin_with(helios/src/cache.rs:519-544): all validation precedes mutation —ready(520),direct_pins == u64::MAXor any chainpins == u64::MAX(524-528) — so a rejected pin mutates nothing.direct_request_pins <= direct_pinsandrequest_pins <= pinsare invariants of the two entry points, so the request counters cannot overflow beforepinsdoes. The counter moves only on the 0→1 crossing ofrequest_pins(536-541).unpin_with(546-570): the request guard (547-549) precedes thedirect_pinsguard (550-552) and both precede any decrement, so a mismatched release leaves the cache untouched. The counter moves only on the 1→0 crossing (561-567), balanced by the sametail_pages.len()recorded at pin time.debug_assert!(node.request_pins > 0)(562) holds from the invariant.- Only
nodes.insert(478) andnodes.remove(604,623) mutate the node map.count/uncount(258-275) do not touch the request counter, which is correct because a newly created node hasrequest_pins == 0. retire_leaf(603) andcompact_ancestor(622) are reachable only throughcancel_publication/eviction_candidates, which requirepins == 0on the leaf rule (659,670). A node withrequest_pins > 0therefore never leavesnodes, so no counted tail pages can be stranded.compact_ancestoradditionally requiresdirect_pins == 0 && child_count == 1, assertsnode.request_pins == child.request_pins(636, debug-only), and leaves the pages in the heir — counted exactly once, travelling with the surviving checkpoint, which is the property the PR claims.advance_completed(796-823) touches readiness and retirement records only; it never removes a node with request pins, andrequest_pinned_pagescounts node tails, not retiring-record pages.cache/lifecycle_tests.rs:77-78, 95copies the new fields inFixture::fork, so the exhaustive cache-model test keeps checking the counter.- Test-only drift assertion (
cache.rs:827-846) compares the kept counter against a full scan ofnodes.values().filter(|n| n.request_pins > 0)on everystats()call, so every cache and scheduler test that reads stats validates it. This is the right split: no chain walk in production, exhaustive check at test time.
3. The gauges themselves
SchedulerStats::request_pages = Σ slot.private_pages.len() + cache.request_pinned_pages;reserved_pages = Σ slot.reserved_pages.len(), summed in the same loop that already countsactive_requests(helios/src/scheduler.rs:1200-1221). No new iteration, no change to any scheduling decision.- Only slot-holding requests contribute private/reserved pages, matching the documented "requests owning a model slot"; retired-but-unfenced pages are excluded, which
docs/api.md:303-304now states explicitly. Metrics::updatestores both fromSchedulerStats(helios/src/server/metrics.rs:514-518); both render as gauges besidecached_kv_pages(1309-1318) and have text/value test rows (1832-1833).- They are deliberately absent from
Snapshot::snapshot()(metrics.rs:355-393) as the PR says, andSnapshotdeserializes absent fields as zero (docs/api.md:317-318), so the JSON contract is unchanged for existing consumers. - Publication timing matches the docs: values are published only when a scheduler pass makes progress (
runtime.rs:1148-1153), plus at startup (722) and after a drained shutdown (745). A scrape reads the last published values — up to one pass of lag, documented atdocs/api.md:305-307. docs/prefix-cache-offload.md:747(not opened) listsSchedulerStatshost fields only, so no change is needed there.
4. The copy-out retry key — the one real hazard in this design, defused
SchedulerStats is PartialEq, Eq (scheduler.rs:112), so adding two page counts would silently widen the equality key CopyoutResources uses to decide whether to re-offer deferred host-store copy-outs. Decode moves private_pages/reserved_pages every step, so an unguarded key would have re-offered copy-outs on every decode step.
The PR zeroes both fields in the key — scheduler: SchedulerStats { request_pages: 0, reserved_pages: 0, ..self.scheduler.stats() } (helios/src/server/runtime.rs:2440-2454), compared at 2455 — with a comment naming exactly this reason. runtime.rs:1056 is the only other SchedulerStats comparison in the tree, and SchedulerStats carries no serde derive (scheduler.rs:112 is Clone/Copy/Debug/Default/PartialEq/Eq only), so no other consumer observes the new fields' movement. The key is now exactly what it was before the field addition.
5. The bca7358 refactor is behaviour-preserving
pin/unpin now delegate to pin_with/unpin_with (cache.rs:519-589), and pin_request/unpin_request call the same bodies with request = true — one chain walk instead of two. Guard ordering, mutation points and 0↔1 transition accounting are identical to the previous head; the two new debug_asserts (562, 636) hold from the subtree-sum definition of request_pins (chain includes id, cache.rs:312-321) and are debug-only.
Test merges are coverage-neutral or stronger: request_pins_count_each_shared_page_once folded into branching_pins_ancestors_and_prevents_direct_ancestor_unpin keeps every assertion — shared page counted once (cache/tests.rs:334), plain copy-out pin inert (341-345), direct-ancestor release rejected (336), 3 → 2 on first release (340), compaction into the pinned heir keeps 2 (358), last release reaches 0 (360). The scheduler fold (scheduler/tests.rs:970-1032) keeps the shared/private/reserved arithmetic and adds a drain-to-zero check after both cancellations (1029-1031).
Docs ratio: docs/api.md:298-310 now defines the vLLM-comparable share as (flare_request_kv_pages + flare_reserved_kv_pages) / flare_total_kv_pages, states the request gauge is not disjoint from flare_cached_kv_pages, and matches the code at scheduler.rs:1200-1221, runtime.rs:1148-1153, 722, 745.
Nits
Nit 1 — "not written yet" is imprecise across the commit→completion window. docs/api.md:304-305; helios/src/server/metrics.rs:1315-1317 (HELP text: "KV pages reserved for active requests' growth and not yet written"). RequestScheduler::commit pops reservations into private_pages (helios/src/scheduler.rs:2432-2447) before the GPU writes complete, so a scrape can count a page in flare_request_kv_pages while it is still unwritten, next to prose asserting such pages are "neither free, cached, nor written yet". An operator deriving a written-page share by subtraction (total − free − reserved and similar) misreads across that window. The numbers stay bounded — docs/api.md:298-310 says the gauges are not disjoint from cached_kv_pages. Fix: tie "written" to the completion fence, e.g. "pages set aside for those requests' growth that no request holds a page for yet, and which are not counted in flare_cached_kv_pages".
Nit 2 — the docs/api.md field table gains no rows for either gauge. Table header docs/api.md:330; cached_pages row at 350. flare_request_kv_pages and flare_reserved_kv_pages appear only in the prose at 298-310, and neither is in the JSON snapshot (metrics.rs:355-393). A reader of the table alone cannot discover the metrics this PR exists to add, nor tell they are text-only. Fix: two rows with none in the Prometheus column (or a note that they are exposition-only), mirroring draft_steps at 335.
Nit 3 — no stats assertion across the Existing { ready: true } re-pin. helios/src/scheduler.rs:2987-2999 (publish_boundary, PublishResult::Existing { id, ready: true } with resume in Snapshot/Finishing) is the one scheduler path where a request swaps its own parent's request pin for a checkpoint another request already request-pins — the exact "shared page counted once" case — and no test reads SchedulerStats::request_pages across it. Correctness is maintained (the cache-side drift assertion at cache.rs:827-846 fails any double count), but the scheduler-level arithmetic for this path is unpinned; the two new tests cover only cancel-to-zero (scheduler/tests.rs:970-1032, and the retired-no-publication path) and the cache-level shared-parent case (cache/tests.rs:320-373). Fix: extend the branching test so a second request publishes onto an already-pinned ready checkpoint and stats().request_pages is asserted before and after.
Nit 4 — pin_prefix carries the pin kind as a bare bool. helios/src/scheduler.rs:2019-2033 (pin_prefix/unpin_prefix), sole call pair at 1636-1638 with releases at 1649 and 1671. request: bool distinguishes a counted request pin from a host-admission ticket's plain pin; an inverted argument silently moves accounting with no type error. Not a present defect — the flag is derived once from inbound.is_none() and both releases reuse it. Fix: a two-variant enum or marker type, or drop the helpers and call cache.pin_request/cache.pin at the call site, as the copy-out pins already do (2037-2042).
Open questions and what I could not verify
- Live-scrape evidence is not reproducible from this branch. The numbers (RTX PRO 6000 Blackwell, 16 streams, 54–80 request / 16–22 reserved of 20,480 pages; two-GPU DeepSeek-V4.1-Flash, 399–402 / 2–3 of 21,504) are internally consistent —
request + reserved < total − freeholds, and the description correctly does not claimtotal − free − requestas a bound — but the image was built from a fork combination (main + #549 + #548 + #560), and the earlier fork commit5ffe4d54is not in this repository. The charter's evidence rule cannot be checked from the branch alone. - No CI checks exist on head
bca7358, and there are still no reviews from maintainers. Not a code defect, but nothing in this review is backed by CI. - Not exercised by me: a GPU workload beyond that scrape, an exported core, the Windows build, or the full helios suite. The one reported test failure is the known
FLARE_TEST_TEMPLATE_DIRtemplate test, unrelated to this change. - Out of scope for this lens: cost of the extra slot pass (performance), naming, and dashboard/UI presentation. I only confirmed that adding two fields to
SchedulerStatscompiles at every construction site (..Default::default()or..self.stats()everywhere) and that the dashboard readsMetrics, notSnapshot, for these names.