Simplicity report · NVIDIA/hyperflare-inference #549

Raw Markdown for agents: https://autobot.eidonix.com/p/94924a0f-ea1a-49be-8ac5-49a732178d03.md

Key findings

Reviewing PR #549 through the simplicity lens ("what can be deleted?") against the charter (line 12: keep the runtime small and model-agnostic; line 35: what gets merged) and AGENTS.md's review rules ("Reject unsupported abstractions and churn", "Require focused, meaningful validation"). The short version: this change does not add a parallel mechanism — the two gauges ride the existing gauge renderer, the existing update table and the existing drift assertion, and the two new counters both have real consumers. So the answer to "what can be deleted" is within the diff, not the diff itself.

Two should-fix items, both local to Cache's pin API, and three nits. Nothing blocking.


should fix

1. helios/src/cache.rs:551-563 and :565-580 — the two new entry points walk the ancestor chain twice and repeat the guard code

pin_request is self.pin(id)? followed by a second self.chain(id)?:

551      pub fn pin_request(&mut self, id: CheckpointId) -> Result<()> {
552          self.pin(id)?;                                            // -> self.chain(id)? at 523
553          self.nodes.get_mut(&id).unwrap().direct_request_pins += 1;
554          let chain = self.chain(id)?;                              // second traversal, second Vec

pin itself (cache.rs:519-534) already computes self.chain(id)? at line 523 and walks it at 530-532. unpin_request has the identical shape (guard at 566, self.unpin(id)? at 569 which chains again at 540, then self.chain(id)? at 571). So every request pin costs two chain walks and two Vec<CheckpointId> allocations; every unpin the same.

Why it matters: these are not cold paths. pin_request is called on every admission (scheduler.rs:1645), for every pool-ticket waiter (1900), for every boundary publication (2971/2991), and unpin_request on every retirement (3159) plus the two error-path releases at 1660/1686. The chains are short but the allocation is per-pin per-request, and the duplicated guard suite (ready check, u64::MAX saturation check, direct_pins guard) now exists in two places that must stay in step.

Smaller version — one traversal, one guard site, no new public API:

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. That deletes roughly 30 lines and one whole chain traversal per call. The request_pins-is-a-subset-of-pins invariant and the "count returns to zero" property are preserved exactly, so request_pins_count_each_shared_page_once and the stats drift assertion at cache.rs:817-837 keep passing unchanged.

2. helios/src/cache.rs:548-550 — the doc comment describes page bookkeeping the cache does not do

/// Pins a checkpoint on behalf of an active request. Request pins also track the
/// pages the request keeps referenced: its private pages plus the pinned
/// ancestors' pages, each page counted once.

The cache has no notion of a request's private pages. request_pinned_pages is only ever changed at cache.rs:558-560 and 575-577, from node.tail_pages.len() of checkpoints whose request_pins crosses one or zero — which is exactly what the test-only full-scan check recomputes at cache.rs:830-834. The private pages are added by the scheduler, separately, at scheduler.rs:1216-1222 (request.private_pages.len() summed over slots) and only surface as SchedulerStats::request_pages. A reader of pin_request is therefore told the counter covers more than it does, and cannot tell whether adding the scheduler's private pages double counts.

Fix — state only the cache's half and point at the consumer:

/// Pins a checkpoint on behalf of an active request, adding the tail pages of every
/// checkpoint on its chain to `request_pinned_pages` while at least one request pin
/// remains. A request's private pages are not cache pages; the scheduler adds them.

(Rule cited: .agents/skills/repo-prose/SKILL.md (not opened) — comments state the invariant, not commentary about it; docs/design-review.md principle 16, write without hidden context.)


nits

3. helios/src/scheduler.rs:1216-1228 — three passes over the slot array where one suffices

stats() now walks self.slots once for active_requests (1203-1207), once for private_pages (1216-1222) and once for reserved_pages (1223-1228) — plus the pre-existing scans at 1209 and 1212. stats() is called from the runtime loop whenever anything progressed (server/runtime.rs:1148-1149).

One pass gives both new fields:

let (request_pages, reserved_pages) = self
    .slots
    .iter()
    .filter_map(|slot| slot.request.as_ref())
    .fold((cache.request_pinned_pages, 0), |(pages, reserved), request| {
        (pages + request.private_pages.len(), reserved + request.reserved_pages.len())
    });

That also makes the two fields read as the pair docs/api.md describes (private plus cache-pinned pages vs. reserved pages) instead of two independently written sums. Fold of three scans into one; no behaviour change.

4. helios/src/cache/tests.rs:335 — an assertion that does not prove a request-pin behaviour

In request_pins_count_each_shared_page_once, line 335 (assert!(cache.unpin_request(parent).is_err())) only shows that unpin_request rejects a checkpoint whose direct_request_pins == 0 — the same guard shape already asserted for the plain API at tests.rs:358 (assert!(cache.unpin(parent).is_err())). It happens to use parent only because that checkpoint has no direct request pin (it has transitive ones), so it is not evidence about the shared-page accounting the test is named for, and the surrounding comments present it as if it were.

The real evidence in this test is lines 331-334 and 336-341 (3 not 4; plain pins leave the count unchanged), which are good. Either drop line 335 or move it to a guard-specific test with a comment saying what it covers. Not a behaviour bug.

Related, minor: in helios/src/scheduler/tests.rs:1024, stats.request_pages == shared + first_private + second_private has two halves of unequal strength. The shared half is genuine evidence (both requests carry the same shared_pages, so a double count would give 2 * shared); the first_private/second_private half is read from the same LiveRequests the implementation sums, so it can only fail if stats() misreads the field. Worth a half-sentence in the comment saying which half is the claim; nothing to delete.

5. docs/api.md:298-305 — the new paragraph duplicates the metric table and narrates implementation

Two trims:

Separately: the page keeps a metric table (api.md:325-349) that lists cached_pages (345), free_pages (346) and total_pages (347), but the two new gauges appear only in prose. A reader who scans the table for page metrics will not find them. One home for the content is enough: either add request_pages/reserved_pages rows with the Prometheus names, or keep the prose and let the table stay the JSON-mirroring table it already is. Both is duplication.


Examined and deliberately kept (no finding)

Open questions / could not be verified from here