Simplicity report · NVIDIA/hyperflare-inference #549

Raw Markdown for agents: https://autobot.eidonix.com/p/b550bb16-0450-4d1b-a3c7-fc058e1210bc.md

Simplicity review of PR #549 "Report KV pages held by active requests" (head 9cca87a)

Key findings

Verdict: should-fix issues only, nothing blocking. The design reuses existing mechanisms (one nodes map, one stats field, the existing Prometheus gauge array and update table) rather than adding parallel paths, so nothing has to be deleted outright. What can be made smaller:

  1. should fix — helios/src/cache.rs:551-580: pin_request/unpin_request walk the checkpoint chain twice and duplicate the guard code. One pin_kind(id, request: bool) with one-line wrappers deletes ~30 lines and one traversal per pin and per release.
  2. should fix — helios/src/scheduler/tests.rs:970-1034: the new scheduler test repeats an existing test's steps verbatim; only 24 of its 65 lines are new evidence. Merge or extract a helper: ~38 lines.
  3. Six nits, listed below, none of which affect behaviour.

Rules applied: charter "How We Work" — "Solve the right problem in the right place … Look for the smallest footprint in shared code" (and line 12, "Keep the runtime small and model-agnostic"); AGENTS.md:188-193 "Reject unsupported abstractions and churn — Refactoring must directly support the requested behavior or remove a demonstrated source of defects or cost"; AGENTS.md:194-199 "Require focused, meaningful validation — Tests must exercise the affected behavior or contract"; docs/design-review.md principle 1 ("Keep Helios as simple as possible") and principle 16 ("Write without hidden context", pointing at .agents/skills/repo-prose/SKILL.md:13-14 (not opened), 26-29, 38-39, 44-46). The PR contains no CUDA or low-level GPU kernel code, so the charter's kernels-defects-only rule does not apply.


Should fix

1. helios/src/cache.rs:551-580 — request pins walk the ancestor chain twice

pin_request (551-563) calls self.pin(id)?, which validates readiness and computes self.chain(id)? at 523 and walks it at 530-532; it then computes self.chain(id)? again at 554 and walks it again to bump request_pins. unpin_request (565-580) repeats the shape: self.unpin(id)? chains at 540, then 571 chains again. Result: two Vec<CheckpointId> allocations and two walks per request pin and per release, plus a second copy of the ready / direct_pins == u64::MAX / pins == u64::MAX guard suite.

Call sites are all hot paths: every admission through pin_prefix/unpin_prefix (helios/src/scheduler.rs:1645, 1656, 1678), every ticket waiter (scheduler.rs:1889), every boundary publication (scheduler.rs:2977, 2979, 2997, 2998) and every retirement (scheduler.rs:3155).

Smaller version — one private helper, both public pairs become one-line wrappers:

fn pin_kind(&mut self, id: CheckpointId, request: bool) -> Result<()> {
    if !self.checkpoint(id)?.ready { return Err("cannot pin a checkpoint before GPU readiness".into()); }
    let chain = self.chain(id)?;
    if self.nodes[&id].direct_pins == u64::MAX
        || chain.iter().any(|id| self.nodes[id].pins == u64::MAX) {
        return Err("checkpoint reference count exhausted".into());
    }
    self.nodes.get_mut(&id).unwrap().direct_pins += 1;
    for ancestor in chain {
        let node = self.nodes.get_mut(&ancestor).unwrap();
        node.pins += 1;
        if request {
            node.request_pins += 1;
            if node.request_pins == 1 { self.request_pinned_pages += node.tail_pages.len(); }
        }
    }
    if request { self.nodes.get_mut(&id).unwrap().direct_request_pins += 1; }
    Ok(())
}
pub fn pin(&mut self, id: CheckpointId) -> Result<()> { self.pin_kind(id, false) }
pub fn pin_request(&mut self, id: CheckpointId) -> Result<()> { self.pin_kind(id, true) }

and the mirror for unpin/unpin_request (keeping the direct_pins == 0 / direct_request_pins == 0 guards). This preserves every invariant the PR relies on: request_pins ⊆ pins, request_pinned_pages returning to zero, and the test-only drift assertion at cache.rs:817-837. request_pins_count_each_shared_page_once and every scheduler test keep passing unchanged.

2. helios/src/scheduler/tests.rs:970-1034 — the new test duplicates an existing test's setup line for line

request_kv_pages_count_shared_prefix_pages_once (970-1034) duplicates branching_requests_own_distinct_tail_pages_and_terminal_snapshots (1036-1081) step for step: same scheduler(2, 8, 5), same seed admit/init/plan/commit/complete/freeze/finish, same two admits of spec(65, 4), same retain_prompt(6), same prefill-lane assertion, same final complete. Lines 972-1009 are identical to 1038-1075.

Only 1010-1033 is new: the five lengths read off the two LiveRequests, the two stats assertions, the two cancels, and the (0, 0) / cached_pages > 0 checks. The cost is ~38 duplicated lines and a second fixture that will drift from the first; per AGENTS.md:194-199, a test should exercise the contract it names, not re-establish a fixture another test already builds.

Fix: append 1010-1033 to the branching test — its trailing borrows at 1076-1080 can follow the stats assertions and cancels — or extract fn shared_prefix_pair(&mut RequestScheduler) -> (RequestHandle, RequestHandle) from 972-1009 and call it from both. The stats assertions survive unchanged; merging removes the whole second test.


Nits

  1. helios/src/scheduler.rs:1216-1228 — SchedulerStats::stats iterates self.slots twice more for the new pair (private pages at 1216-1222, reserved pages at 1223-1228) on top of the existing scans; stats() runs from the runtime loop whenever anything progressed (server/runtime.rs:1148-1149). One fold seeded over slot.request yields both values, and request_pages: private + cache.request_pinned_pages. Note also that LiveRequest::pages() (scheduler.rs:385-387) already exists as the notion of "the pages a request holds"; the new code should not invent a second one.
  2. helios/src/scheduler.rs:3149-3156 — the retirement block calls self.request(handle)? twice to re-read prefix and error_code, although let prefix = request.prefix; exists at 3120 and request.error_code is read at 3116-3119 with nothing mutating either in between (the only writers, 2716/2779, run in complete). Add let failed = request.error_code.is_some(); beside 3120 and use both locals: two fewer slot lookups and one less shadowed binding. No behaviour change.
  3. helios/src/cache/tests.rs:335 — assert!(cache.unpin_request(parent).is_err()) exercises only the "checkpoint holds no request pin" guard, the same shape already covered for the plain API at tests.rs:358; it is not evidence for the test's named claim (a shared page counted once). Drop it, or move it next to a guard test. The real evidence is 331-334 and 336-341, plus the Cache::stats drift assertion.
  4. docs/api.md:309-312 — the gauge paragraph ends "…and the test-only assertion in Cache::stats compares the maintained request-pinned count with a full scan of every checkpoint on each read." That documents #[cfg(test)] scaffolding (cache.rs:817-837) inside the API reference; per .agents/skills/repo-prose/SKILL.md:13-14 (not opened), 26-29 and docs/design-review.md principle 16, documentation is a present-state specification, not a validation journal, and the PR description already carries this evidence. End the paragraph at "…excludes idle cached prefixes and snapshot backing pages."
  5. helios/src/scheduler.rs:2025-2040 — pin_prefix/unpin_prefix are if request { … } else { … } pass-throughs with three call sites, all inside admit_planned (1645, 1656, 1678); they replaced 12 inline lines with 16. Once the cache has one entry point per direction (should fix 1), delete them and call the cache at the three sites with the existing request_pin local (1643), or give the cache PinHolder::{Request, Ticket}. Not a blocker — they do encode the choice once — but they are net new lines for no new abstraction.
  6. helios/src/server/runtime.rs:2441-2450 — the fix zeroes request_pages/reserved_pages in a struct literal because CopyoutResources (1053-1059) embeds all of SchedulerStats; every future gauge therefore joins the copy-out retry key by default and needs a second edit here. Correct as written; the smaller long-term form is for CopyoutResources to hold the cache-side values copy-out actually keys on. That changes which movements re-offer deferred copy-outs and needs its own justification, so it is a note, not a request.

Examined and kept (no finding)

Not verifiable from here

The live two-GPU DeepSeek-V4.1-Flash scrape numbers (399/402 request pages, 3/2 reserved, ratios 0.0186/0.0187) are the author's measurement of their own instance; confirming them needs a scrape with a request held mid-prefill, not a unit test. That is outside the simplicity lens and does not change the verdict.