Subtraction review — PR #549, "Report KV pages held by active requests"
Reviewer lens: subtraction only. Head 9cca87ac, base main, open draft, no reviews, no CI checks; closes #537. All eight changed files were read in place at the head commit with their callers, together with issue #537 and the charter. The suite was not run (nothing to run against the head here); every finding below is a static reading of the code.
Key findings
Of +246/−16 lines across 8 files, about 104–107 lines (≈43%) can go without losing anything issue #537 asks for.
| # | Severity | Where | Lines saved |
|---|---|---|---|
| 1 | Should fix | helios/src/scheduler/tests.rs:970–1034 re-runs an existing test's entire scenario | ~55 |
| 2 | Should fix (scope) | flare_reserved_kv_pages — a second gauge #537 never asked for |
~20–23 |
| 3 | Should fix | docs/api.md:302–312 — internals and a test reference around a two-line definition | ~10 |
| 4 | Nit | helios/src/cache.rs:82–83, 461, 553, 566–568, 570 — direct_request_pins duplicates unpin's own check |
~10 |
| 5 | Nit | helios/src/cache/tests.rs:320–342 — fixture copied verbatim from the test below | ~9 |
Project rules these are judged against (charter, read in full): "Look for the smallest footprint in shared code, or a way to solve it without new code at all"; "Stay focused … not interested in piling on extra … switches"; "What gets merged: PRs that address a maintainer request, a roadmap item, a reproducible bug, a measured performance/memory issue, or bad docs" (charter line 35). #537 is the maintainer request here and it bounds the scope: it asks for the pages held by active requests (naming flare_request_kv_pages, or a pinned/idle split of flare_cached_kv_pages, plus an optional ratio). It does not ask for reservations.
1. Should fix — the new scheduler test replays an existing test in full (~55 lines)
helios/src/scheduler/tests.rs:970–1034, request_kv_pages_count_shared_prefix_pages_once (+66 lines), is the scenario of branching_requests_own_distinct_tail_pages_and_terminal_snapshots at helios/src/scheduler/tests.rs:1036–1081, step for step: same scheduler(2, 8, 5) (972 vs 1038), the same seed admit spec(64, 1) and init, the same Fence(2) completion over records(seed, 2, 64, 1, 77, 2), freeze(seed, 3)/finish, then two spec(65, 4) admits, Fence(5) completion over records(first, 5, 65, 1, 88, 1), retain_prompt(6), the GraphKind::Prefill plan assertion with lanes[0].request == second, and the Fence(7) completion over records(second, 7, 65, 1, 90, 1) (compare 972–1009 with 1038–1075 line by line). The existing test already asserts the shared pages are equal (1078) and the private pages differ (1079).
The only new content is the 5-tuple capture at 1010–1022, the two stats assertions at 1024–1025, the cancels at 1029–1030 and the two assertions at 1032–1033.
Smaller version — delete 970–1034 and append to the existing test after line 1080 (the shadowed first/second at 1076–1077 are &LiveRequest, whose handle is public, helios/src/scheduler.rs:226):
let (shared, private, reserved) = (
first.shared_pages.len(),
first.private_pages.len() + second.private_pages.len(),
first.reserved_pages.len() + second.reserved_pages.len(),
);
let stats = scheduler.stats();
assert_eq!(stats.request_pages, shared + private);
assert_eq!(stats.reserved_pages, reserved);
scheduler.cancel(first.handle).unwrap();
scheduler.cancel(second.handle).unwrap();
let stats = scheduler.stats();
assert_eq!((stats.request_pages, stats.reserved_pages), (0, 0));
assert!(stats.cached_pages > 0);
Nothing is lost: the same shared/private/reserved quantities, the same shared-page-counted-once behaviour, the same retire-to-zero path, on a fixture the suite already pays for. Keep the assert!(!shared_pages.is_empty()) idea as an assertion on shared. This one finding is over a fifth of the diff.
2. Should fix (scope) — flare_reserved_kv_pages is a second feature (~20–23 lines)
Issue #537 asks for one thing — pages held by active requests — and offers flare_request_kv_pages, a pinned/idle split of flare_cached_kv_pages, and an optional ratio. It says nothing about reserved growth pages. The PR adds that as an independent goal, and its only reader is the Prometheus text:
helios/src/scheduler.rs:132–133(field + doc comment) and1223–1228(the per-slot sum)helios/src/server/metrics.rs:266(atomic),518(store),1314–1318(name, help text, gauge),1791(test input),1836(test row)helios/src/server/runtime.rs:2447–2448(one of the two key-zeroing lines)docs/api.md:301–302,307–309
Nothing in the JSON Snapshot/field table reads it (docs/api.md:352 lists only cached/free/total pages), so no dashboard or view function gains anything. LiveRequest::reserved_pages (helios/src/scheduler.rs:255) already exists for scheduling; only the aggregate is new.
What replaces it: nothing. flare_request_kv_pages alone supplies the ratio #537 names. If operators want reservation visibility, it belongs in a change of its own (charter: stay focused). Removing it also cuts runtime.rs:2441–2450 down to a single request_pages: 0 line.
3. Should fix — the docs paragraph is mostly internals (~10 lines)
docs/api.md:298–312 spends fifteen lines on two gauges. The definition is 298–300; the rest is detail no other gauge in this file carries:
- 302–303: "The worker publishes both on every scheduler pass and a scrape reads the last published values" — publication cadence.
- 306–307: "Neither gauge counts pages still draining through retirement or an admission ticket's in-flight restore" — transient internal states.
- 310–312: "the test-only assertion in
Cache::statscompares the maintained request-pinned count with a full scan of every checkpoint on each read" — a reference to a#[cfg(test)]block (helios/src/cache.rs:817–837) that no dashboard author can use.
Smaller version (with finding 2 applied):
`flare_request_kv_pages` counts the distinct KV pages that active requests
reference: their private pages plus the tail pages of the prefix checkpoints they
pin, each page counted once even when several requests reference it. Those pinned
pages also appear in `flare_cached_kv_pages`; dividing the gauge by
`flare_total_kv_pages` excludes idle cached prefixes and snapshot backing pages.
Saves ~10 lines. The definition and the ratio, which are the parts a reader needs, stay.
4. Nit — direct_request_pins exists only for its own guard (~10 lines)
helios/src/cache.rs:82–83 (doc + field), 461 (initialiser), 553 (+= 1), 566–568 (the guard) and 570 (-= 1) add a per-checkpoint subset counter whose only consumer is the guard at 566–568 that rejects a release the scheduler can never perform: every unpin_request call site releases an id that was request-pinned (helios/src/scheduler.rs 1645↔1660/1686, 2971↔2973, 2991↔2992, 3159 with the prefix set at 1902/2979/2996), and unpin itself already errors on a release with no direct pin (helios/src/cache.rs:536–540).
Smaller unpin_request:
pub fn unpin_request(&mut self, id: CheckpointId) -> Result<()> {
self.unpin(id)?;
let chain = self.chain(id)?;
for ancestor in chain {
let node = self.nodes.get_mut(&ancestor).unwrap();
node.request_pins -= 1;
if node.request_pins == 0 {
self.request_pinned_pages -= node.tail_pages.len();
}
}
Ok(())
}
Together with lifecycle_tests.rs:77 and the assertion that constructs the error (helios/src/cache/tests.rs:335) that is ~10 lines. Caveat for the maintainer: this does trade away a defensive cache-side check that no type enforces — the field and the guard stand or fall together, and a chain-level request_pins check cannot reproduce that particular error. It is a Nit because a reviewer may reasonably keep the guard.
5. Nit — the new cache test repeats the fixture below it verbatim (~9 lines)
helios/src/cache/tests.rs:322–328 is character-identical to 346–352 in branching_pins_ancestors_and_prevents_direct_ancestor_unpin. Because pin_request calls pin first (helios/src/cache.rs:552), the existing test can take its pins through pin_request/unpin_request and pick up request_pinned_pages assertions at 356/360/373 without disturbing its pin_count() checks.
Smaller version: delete the test body at 320–342 and add its assertion lines inline in the existing test —
assert_eq!(cache.stats().request_pinned_pages, 3); // after both pins
cache.unpin(right_id).unwrap(); // plain pin does not move the request count
assert_eq!(cache.stats().request_pinned_pages, 2);
Saves ~9 lines and keeps every behaviour the new test proves (count 3 not 4; plain pins leave it unchanged; the empty-release error at 335 can stay where it is if finding 4 is declined).
Already minimal — do not cut
Checkpoint::request_pins(helios/src/cache.rs:84–85, 462, 557, 574) andPrefixCheckpointCache::request_pinned_pageswith its two-line zero-crossing brackets inpin_request/unpin_request(552–563, 565–580). This is exactly what keepsCache::statsfrom scanningnodes, which the description gives as the reason for the design.- The compaction agreement assert (
helios/src/cache.rs:626–627). - The
#[cfg(test)]drift assertion (helios/src/cache.rs:817–837) — the best value per line in the change; it makes every cache and scheduler test check the counter. CacheStats::request_pinned_pagesand therequest_pagessum (helios/src/scheduler.rs:1216–1222), including the "at most one slot per active request" property.- The
flare_request_kv_pagestriple: atomic (server/metrics.rs:265), store (517), name/help/gauge (1309–1313), and its two test rows (1790, 1835). server/runtime.rs:2441–2450, the copy-out-key zeroing. It fixes a real behaviour leak:SchedulerStatsis embedded whole inCopyoutResources(runtime.rs:1053–1059) and compared at 2455, so a decode would otherwise force copy-outs. It shrinks to ~4 lines once finding 2 lands; keep it.
Rejected candidates (checked, not findings)
- The
admit_plannedpin/unpin branch pairs. Now collapsed intopin_prefix/unpin_prefix(helios/src/scheduler.rs:2025–2040), which is line-neutral against the three inlineif inbound.is_none()pairs it replaced. The ticket-parent branch is load-bearing: the ancestor must be pinned beforeensure_resourcescan evict (scheduler.rs:1675). - Folding
pin_requestintopin(andunpin_requestintounpin) behind a bool. Would remove onechainwalk per call (~10 lines) but pushes a flag through a public API used by ~15 plain-pin call sites, or needs four wrapper lines. A rewrite that trades call-site clarity for ten lines, not a removal. Cache::pin/unpinbecoming dead. They do not:pin_checkpoint/unpin_checkpoint(server/runtime.rs:2360–2489) and the ticket-parent pins (scheduler.rs:1871,1907) still call them, and many tests do.
Left behind
Nothing the change supersedes is left dead. Cache::pin/unpin retain real callers; has_pins (helios/src/cache.rs:291) is not duplicated by the new counter; no flag, config or doc elsewhere describes the old state.
Open questions / what I could not check
- I did not run the suite (no CI checks on the head commit in this environment), so the "508 passed" claim in the description is taken as given; it does not affect any subtraction above.
- Whether the reserved gauge has a consumer outside this repository (a dashboard or alert the author has locally) cannot be established from the code; nothing in
docs/api.md's JSON field table or the metrics view functions reads it. LiveRequest::handlevisibility (needed for the merged-test version of finding 1) was confirmed at helios/src/scheduler.rs:226; if the maintainer prefers keeping the two tests separate, only finding 1's ~55 lines are at stake and the rest of the review is unaffected.
Total: ~104–107 of 246 added lines removable in 5 places (≈43%). Verdict: make it smaller first — finding 1 alone removes a fifth of the diff, and finding 2 is a feature the issue did not request.