Key findings
Verdict: clean — no blocking, no should-fix issues. I read all eight changed files in context at head bca7358 and audited every path the change reaches. The counter cannot drift or underflow, every request-owned pin has a matching release on every success and failure path, and the two new gauges are plumbed through without changing any allocation, eviction or scheduling decision.
Four nits, all documentation/coverage-grade, listed at the end.
What I verified as correct
1. Request pin / unpin symmetry in the scheduler
Invariant checked: LiveRequest::prefix == Some(id) iff one direct_request_pins is held on id, across every path.
- Admission:
pin_prefix(id, request_pin)withrequest_pin = inbound.is_none()(helios/src/scheduler.rs:1636-1638); both failure releases use the same flag (1649,1671). - Host 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 the request. - Ticket waiters:
pin_requestper waiter (1882). - 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-2991). - Retirement:
unpin_request(prefix)(3148) now runs beforeself.slots[..].request.take()(3150), so a failed release leaves the request inspectable — this is the ordering change the PR advertises and it is correct.record_publicationstays guarded by!publish || error_code.is_some()(3144-3147), unchanged. - Cancel, preemption (
finish_early→retire), finish, and shutdown (release_after_shutdown→cancelfor each live handle,3067-3084) all reach the same release. - Preemption replaces pins via the same request API; the slot is not emptied until after the release, so no path can leak a
direct_request_pins. - Host-store copy-out and export keep the plain API:
pin_checkpoint/unpin_checkpointarecache.pin/cache.unpin(2037-2043), used fromruntime.rs:2360, 2364, 2396, 2480, 2496, 2705, 2710. Consequently the new hard error "checkpoint has no request pin to release" (helios/src/cache.rs:546-549) has no reachable caller — a plain unpin can never trip it, becauseunpin_with(id, false)short-circuits the request guard.
2. request_pinned_pages cannot drift or underflow
I checked every mutation of nodes and of the counter:
pin_with(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(538-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 (564-566), balanced by the sametail_pages.len()recorded at pin time.debug_assert!(node.request_pins > 0)(562) holds from the invariant.retire_leaf(603) andcompact_ancestor(622) are reached 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_ancestorrequiresdirect_pins == 0 && child_count == 1, assertsnode.request_pins == child.request_pins(636, debug-only), and moves the ancestor's tail pages into the heir — pages stay counted exactly once, and the count travels with the surviving checkpoint. This is the property the PR claims and it is genuinely maintained, not assumed: there is no rule that a checkpoint leavesnodesonly at zero pins, but the pin gates above supply the needed guarantee.advance_completed(796-823) touches readiness and retirement records only; it never removes a node with request pins, andrequest_pinned_pagescounts only node tails, not retiring-record pages.- The 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 checks it. This is the right place for a chain-walk-free production path plus an exhaustive test-time check.
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 countsactive_requests(scheduler.rs:1200-1209, assigned1220-1221). One extra pass-free read; no new iteration.- Only slot-holding requests contribute private/reserved pages, matching the documented "requests owning a model slot"; retired-but-unfenced pages are excluded, which the docs now state explicitly (
docs/api.md:302-304). Metrics::updatestores both fromSchedulerStats(helios/src/server/metrics.rs:517-518), and both render as gauges besidecached_kv_pages(1309-1318). They are absent fromSnapshot::snapshot()(355-393) as described, 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, plus at startup and after a drained shutdown (
runtime.rs:1148-1153,722,745). A scrape reads the last published values — a lag of up to one pass, documented.
4. The copy-out retry key is protected (the one real hazard in this design)
Adding two page counts to SchedulerStats, which is PartialEq, Eq (scheduler.rs:112), would have silently widened 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 re-offer copy-outs on every decode step.
The PR zeroes both in the key (runtime.rs:2441-2455) with a comment naming exactly this reason:
scheduler: crate::scheduler::SchedulerStats { request_pages: 0, reserved_pages: 0, ..self.scheduler.stats() }
runtime.rs:1056 is the only other SchedulerStats comparison in the tree, so there is no second place to forget. I confirmed no behavioural change remains: the key is exactly what it was before the field addition.
Nits
docs/api.md:304-305andhelios/src/server/metrics.rs:1315-1317— "not yet written" is imprecise at the commit boundary. A reserved page is genuinely not free (popped fromfree_pagesat admission,scheduler.rs:1714-1717) and not counted incached_pages(tail_pagescounts checkpoint tails only). Butcommitpops reservations intoprivate_pagesbefore the GPU writes complete (scheduler.rs:2435region), so between commit and the completion fence a page is counted inrequest_kv_pageswhile still unwritten. Suggest wording like "pages set aside for those requests' growth that no request currently holds a page for".docs/api.md:330field table gains no rows for the two gauges.cached_pageshas a row (350), butflare_request_kv_pages/flare_reserved_kv_pagesappear only in the prose at298-310. A reader of the table alone will not learn they exist. Add a row each withnonein the Prometheus column, or state that they are text-only (they are not in the JSON snapshot).- Coverage gap:
publish_boundary'sExisting { ready: true }re-pin (scheduler.rs:2987-2998) has no stats assertion. That is the path where a request swaps its own parent's request pin for a checkpoint another request already pins — the exact "shared page counted once" case at the scheduler level. TheCache::statsdrift assertion would catch a cache-side double count, but nothing drives that path with a stats read. A test assertingstats.request_pagesacross a second request's boundary publication onto an already-pinned ready checkpoint would close it. pin_prefix/unpin_prefixcarry the pin kind as a barebool(scheduler.rs:2019-2033). With one call-site pair the risk is low, but an inverted argument silently converts a request pin into a host-admission pin (or the reverse) and the failure would surface only as a drift assertion or a stranded counter. An enum or marker type would make it a compile error if the API spreads.
Open questions / process (not code defects)
- The live-scrape evidence is not reproducible from this branch. It builds on the AzallazA fork commit
5ffe4d54(per the PR description, needed for DeepSeek-V4.1-Flash engram encoding, upstream #482), which is not in this repository. The numbers themselves are internally consistent —request + reserved ≤ total − free(402 vs 5922, 404 vs 6104) holds, and subtractingcached_kv_pagesis correctly not claimed as a bound because pinned checkpoints count in both gauges (docs/api.md:301-303) — but the charter's evidence rule ("Bring real evidence") cannot be checked from the branch alone. - Not exercised here or per the PR: a GPU workload beyond that scrape, an exported core, the Windows build, and the full helios suite. The one test failure the PR reports is the known
FLARE_TEST_TEMPLATE_DIRtemplate failure, unrelated to this change. - No CI checks exist on head
bca7358. Outside this lens, but it means nothing in this review is backed by CI. - The refactor in
bca7358(one chain walk viapin_with/unpin_withinstead ofpin_request = pin + walk) is behaviour-preserving: the ordering of the guards, the mutation points, and the 0↔1 transition accounting are identical to the previous head, and the merged tests keep every assertion of the two pairs they replaced (cache/tests.rs:320-373,scheduler/tests.rs:970-1032, the latter strictly stronger).
Scope note
This review covers the correctness lens only (lifetimes, error handling, concurrency, inactive/edge paths, state transitions, compatibility). Performance of the extra slot pass, naming, and dashboard/UI presentation were left to other lenses; I only checked that adding two fields to SchedulerStats compiles at every construction site (..Default::default() or ..self.stats() in all of them) and that the dashboard reads Metrics, not Snapshot, for these names.