Verdict: worth merging, with small changes
The change is small, in the right layer, backed by real evidence, and closes a documented observability gap (#537). Nothing in it touches a charter non-goal. My requested changes are documentation/API-completeness plus one hardening point on the new dual pin API — not a redesign.
Does it fit the charter?
- Right problem, right place. #537 is a reproducible, version-cited defect report ("KV cache usage cannot be computed with vLLM semantics"), with a concrete demonstration that the existing gauges only give upper and lower bounds (≈16% and ≈0% vs ≈9% on vLLM). That is exactly the kind of item the charter says gets merged ("PRs that address … a reproducible bug"). The fix lands in the two layers that own the quantity —
helios/src/cache.rsfor cache-side pins,helios/src/scheduler.rsfor slot state — and surfaces it inserver/metrics.rs. No new flags, no per-model branch, no env switch, no backend abstraction. - Respects an existing invariant rather than working around it.
PrefixCheckpointCachealready keepsready_checkpoints/unready_checkpoints/tail_pagesas maintained counters precisely sostatsnever scansnodes(cache.rs:217-224), andScheduler::statsis called on every progress pass of the runtime loop (runtime.rs:1148-1149), not only on scrapes. Maintainingrequest_pinned_pageson pin/unpin — with the same O(chain) costpinalready pays — is the cheapest correct design; the obvious alternative (scanning checkpoints per scrape) is what the existing comment forbids. That is the "smallest footprint in shared code" the charter asks for: ~100 lines of runtime code across 5 files, rest tests/docs. - No duplication, no simpler route. The issue's alternative (split
cached_kv_pagesinto pinned/idle) costs the same bookkeeping and yields a less directly usable number; a ready-made ratio gauge would be simpler for the operator but strictly less flexible and would hide the reserved term. Two counters that compose into the ratio is the right grain, and the existing gauges cannot produce the value (that is the whole point of #537). - Benefit and who gets it. Operators migrating vLLM/Grafana dashboards, and specifically the open monitoring example #541, whose review flagged that "request-held pages appear in no gauge — issue #537" and whose KV panel therefore can only show bounds. Qual qualification scripts also sum these gauges (
scripts/qualify_worker_failure.py:143(not opened)), and #351 already established the "free + backing + cached = pool" identity this extends.reserved_kv_pagesadds attribution that was previously invisible: those pages leavefree_pagesat admission (scheduler.rs:1732-1735) and appear in no other gauge. The live evidence shows the reserved term is small (2-3 pages) under streaming load, so the request gauge is the valuable half; the reserved gauge is cheap enough to justify, but its payoff is modest and should not be oversold. - Cost: negligible and bounded. One extra
u64perCheckpointand twou64on the cache struct (a type that is alreadyCloned for snapshot quotes — cache_memory.rs:290 — so the extra words ride along), one integer add/sub per pin along a chain that is already walked for aVecallocation, and a per-stat loop over ≤ slot-count live requests. No GPU, no allocation, no scheduling decision changes. - Complexity risk: the honest one. The new API is a parallel pin flavor:
pin/unpinandpin_request/unpin_requestmust be paired, and mispairing fails at runtime with an error string (cache.rs:566-568). Becauseretirepropagates that with?(scheduler.rs:3159), a bookkeeping mistake inside what is otherwise a metrics-only feature can fail a request retirement — which slightly undercuts the "no scheduling decision changes" claim. I traced every call site: admission (1645/1647 ↔ 1660/1686/3159), ticket-parent (1647 ↔ 1882/1918),finish_inboundwaiters (1900 ↔ retire), boundary publications (2971/2991 ↔ 2973/2992), and the plain-pin sites that legitimately stay plain (pin_checkpoint/unpin_checkpointfor host copy-out/export). The pairing is currently complete and internally consistent; the risk is the next contributor adding a request pin via plainpinand silently undercounting.
Correctness of the counter
I checked the places tail_pages mutates for the maintained count to drift: creation (cache.rs:448-465, starts at 0), count/uncount (258-275), and compact_ancestor (613-645). Compaction is handled correctly and asserted: the ancestor may have request_pins > 0 (a descendant's request pin bumps ancestor pins without a direct pin), and the added debug_assert_eq!(node.request_pins, child.request_pins) plus the "pages move into the counted heir" comment covers the both-counted-or-neither case, so the union length is preserved. Leaf retirement cannot strand pages because request_pins > 0 ⇒ pins > 0, and eviction requires pins == 0. Private pages are disjoint from request-pinned cache pages because publication drains them into tail_pages (2978, 3150-3152). The parent/child test asserting 3 rather than 4 (cache/tests.rs:320-341) is the right test for the "shared page counted once" property.
The strongest guard is the extension of the existing test-only drift assertion (cache.rs:819-837), which compares the maintained count with a full scan on every stats() read across the whole suite. That is proportionate for a counter whose only consumer is a gauge, and it is the same pattern the surrounding counters already use.
Known gaps (all small, all should be stated, not necessarily fixed): retiring slots' pages (retire.rs (not opened) path at scheduler.rs:3170-3183, returned to free_pages only after the fence at 3037), in-flight ticket pages reserved for an inbound restore (1704-1706), and snapshot backing pages remain outside both gauges. The evidence in the description is consistent with this: request + reserved stayed below total − free − cached.
Evidence
Meets the charter's bar: four-part description, Discord: line, no invented evidence, and an explicit statement of what was not run (Windows build, full helios suite → CI). The live scrape is the right shape — idle shows 0/0, two concurrent streams show 399/402 request pages, 3/2 reserved, 2037/2043 cached of 21504 total, plus the sanity inequality — and it correctly disclaims comparison with another runtime and notes the agent's own traffic is included. No performance claim is made, which is correct: this is visibility only, so the "benchmark against main" rule does not apply.
Changes I would ask for before merge
- Decide the JSON story.
Snapshot(metrics.rs:68-129) is the documentedformat=jsonsurface, and docs/api.md:325-355 is the JSON↔Prometheus table; the PR adds two Prometheus-only gauges and documents them only in prose. Either add both fields toSnapshot(two lines each, and the terminal dashboard inflare/src/dashboard.rs:382could then show them) or say explicitly indocs/api.mdthat these two gauges are Prometheus-only and why. Silent divergence between the two formats is the kind of doc drift the repo's own prose rules push against. - Fix the ratio sentence. docs/api.md:303-305 says dividing
flare_request_kv_pagesbyflare_total_kv_pages"gives the KV share held by live requests". That excludesflare_reserved_kv_pages, so it understates what live requests actually hold — which is precisely the vLLM comparison #537 was opened for. Say so, and state which sum is intended (request + reserved). - Harden the dual pin API against silent undercount. Cheapest option that matches house style: a
#[cfg(debug_assertions)](or test-gated) cross-check inScheduler::stats/Cache::statsthat every live request withprefix: Some(_)is backed by a request pin, mirroring the existing drift assertion. Alternatively make the flavor a type (Pin/RequestPin) so mixing cannot compile. Without one of these, the invariant lives only in comments and one unit test. - Say what the gauges exclude. One sentence on retiring slot pages, in-flight ticket pages, and snapshot backing pages, in the HELP text or docs/api.md. The evidence already shows these regions exist; leaving them implicit invites the same "which number is the truth" confusion #537 complained about.
None of these changes the design; 1-4 are ~20 lines plus prose. #549 and #548 (#536) touch disjoint regions of metrics.rs (page gauges beside cached_pages there, histograms beside the completion counter here), so merge order does not matter.
Bottom line
Worth it with changes. A focused, well-evidenced, correctly-layered observability addition to a gap a user reported with reproduction detail, at a complexity cost the cache was explicitly designed to absorb. Request items 1-4, then merge; the Windows build and full helios suite should pass before landing, as the description itself flags.