Conventions report · NVIDIA/hyperflare-inference #549

Raw Markdown for agents: https://autobot.eidonix.com/p/971c355e-a910-474c-82cc-e55da5f64b30.md

Key findings

Two should-fix items, both duplication/precedent departures, no blocking issues.

  1. pin_request/unpin_request re-implement the body of pin/unpin around it (helios/src/cache.rs:551-580). They call the existing method and then walk the checkpoint chain a second time, so one logical operation is now split across two functions that must agree, instead of extending the function that already owns the invariant. Fix: a private fn pin_with(&mut self, id, request: bool) that computes self.chain(id)? once and does both counter sets, with pin/pin_request/unpin/unpin_request as thin wrappers.
  2. The "which counter" branch is copied three times in admit_planned_with_checkpoint_accounting (helios/src/scheduler.rs:1643-1649, 1657-1669, 1683-1692). The file already encodes exactly this kind of pairing once, in pin_checkpoint/unpin_checkpoint (scheduler.rs:2038-2044), so the reviewer's expectation is set by the repo's own convention.
  3. Nit: the two new gauges are documented only in docs/api.md prose plus HELP strings; the existing page gauge also has a design-document home (docs/runtime-core-design.md:873).

I read every changed file in context (cache.rs, scheduler.rs, server/metrics.rs, docs/api.md, plus the two test files' assertions via the diff) and checked the rules in AGENTS.md and the charter. Nothing in the diff is a duplicated helper that already exists elsewhere (no existing "pages held by live requests" helper — search_code for held_pages|live_pages|pages_held|request_pages returns only the new items), so the duplication findings are about shape, not about reinventing a mechanism.


Should fix 1 — pin_request/unpin_request shell out to pin/unpin and walk the chain a second time

Where: helios/src/cache.rs:551-563 and 565-580; precedents at cache.rs:519-534 (pin) and 536-546 (unpin).

pin computes the chain once and runs the readiness and refcount guards against it:

// cache.rs:519-534
pub fn pin(&mut self, id: CheckpointId) -> 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 { self.nodes.get_mut(&ancestor).unwrap().pins += 1; }
    Ok(())
}

The new method repeats that walk instead of participating in it:

// cache.rs:551-563
pub fn pin_request(&mut self, id: CheckpointId) -> Result<()> {
    self.pin(id)?;                                        // walks chain, checks chain
    self.nodes.get_mut(&id).unwrap().direct_request_pins += 1;
    let chain = self.chain(id)?;                          // walks chain again
    for ancestor in chain { /* request_pins += 1, request_pinned_pages += tail_pages */ }
    Ok(())
}

unpin_request (cache.rs:565-580) has the same shape: self.unpin(id)? then a second self.chain(id)? to decrement request_pins.

Why it matters. Two chains per pin means two Vec<CheckpointId> allocations and two root-to-leaf walks on a path that runs per admission, per pool-ticket hand-off (scheduler.rs:1897), per boundary publication (scheduler.rs:2968, 2988) and per retirement (scheduler.rs:3156). More importantly for this lens, the invariant "request_pins is a subset of pins and both move together along the same chain" is now enforced by two separate loops in two functions that can drift; the only detector of drift is the test-only assertion in Cache::stats (cache.rs:819-837), which does not exist in a release build, and compact_ancestor's debug_assert_eq!(node.request_pins, child.request_pins) (cache.rs:627) which is also debug-only.

Fix. One private worker, one walk:

fn pin_with(&mut self, id: CheckpointId, request: bool) -> Result<()> { /* existing pin body + request accounting in the same loop */ }
pub fn pin(&mut self, id) -> Result<()> { self.pin_with(id, false) }
pub fn pin_request(&mut self, id) -> Result<()> { self.pin_with(id, true) }

and the mirror for unpin. This also gives the request_pins == 1 / == 0 transitions a single site, which is where request_pinned_pages must be updated.

Secondary point on the same lines, stated honestly. The new counters use bare += 1 / -= 1 with no u64::MAX guard, unlike direct_pins/pins. In practice this cannot overflow: request_pins is documented and implemented as a subset of pins (cache.rs:82-85 fields, cache.rs:555-557 increment), and pin rejects at u64::MAX before the request count grows. So the missing guard is defence-in-depth, not a live defect — I flag it only as the reason to merge the two loops rather than as an independent bug. The request_pinned_pages -= node.tail_pages.len() at cache.rs:576 is usize subtraction guarded only by the direct_request_pins == 0 early-out at cache.rs:566 plus the subset invariant; if a test-only assertion ever fires there, a release build would wrap instead of erroring. Folding into one loop does not by itself fix that; a saturating_sub or a debug assert on the transition would. I did not find a path that reaches it with the invariant intact.


Should fix 2 — three copies of the request-pin-vs-plain-pin branch in admit_planned_with_checkpoint_accounting

Where: helios/src/scheduler.rs:1643-1649 (take), 1657-1669 (context-limit rollback), 1683-1692 (resource rollback).

Before the change the function had one pinned binding and each rollback site called self.cache.unpin(id)? (see the diff hunk at scheduler.rs:1638-1669 in pr_diff). The change replaces those single calls with the same two-branch conditional three times:

if let Some(id) = pinned {
    if inbound.is_none() { self.cache.pin_request(id)?; } else { self.cache.pin(id)?; }
}
...
if let Some(id) = pinned {
    if inbound.is_none() { self.cache.unpin_request(id)?; } else { self.cache.unpin(id)?; }
}
return Err(...Context...);
...
if let Some(id) = pinned {
    if inbound.is_none() { self.cache.unpin_request(id)?; } else { self.cache.unpin(id)?; }
}
return Err(error);

Why it matters. inbound is moved-in and immutable for the whole function, so all three sites are deterministically the same branch; the repetition buys nothing and creates three places that must agree. A later edit that changes one of them (say, adding a third pin kind, or pinning the ticket parent on the creating path too) produces a pin and an unpin on different counters, which is invisible in release builds — the only detector is the test-only full-scan assertion in Cache::stats (cache.rs:819-837). The repository's own precedent is to bind the choice once: pin_checkpoint/unpin_checkpoint (scheduler.rs:2038-2044) exist precisely so call sites cannot mismatch, and the pinned binding itself (scheduler.rs:1638-1642) was already the "decide once, use everywhere" shape that the change then undid at the call sites.

Fix. Carry the kind in the binding that already exists:

#[derive(Clone, Copy)] enum PinKind { Request, Admission }
let pin = pinned.map(|id| (id, if inbound.is_none() { PinKind::Request } else { PinKind::Admission }));

then one self.cache.pin_as(kind, id) at scheduler.rs:1643 and one unpin_as(kind, id) at each of 1657-1669 and 1683-1692 — or simply a local closure let release = |cache: &mut PrefixCheckpointCache, id| ... used at both rollback sites. Either restores one visible pairing.

Note for the author: the sites at scheduler.rs:1897 (pin_request for pool-ticket waiters), 2968/2988 (boundary publications, which correctly pair pin_request with unpin_request(parent)) and 3156 (retirement unpin_request) are not part of this finding — each is a single unconditional call, and they are internally consistent with each other. The plain-API pins left alone for host-store copy-out/export (pin_checkpoint/unpin_checkpoint, scheduler.rs:2036-2044) match the PR description and are the right call.


Nit 3 — the new gauges have no docs/runtime-core-design.md entry

Where: docs/api.md:298-305 and helios/src/server/metrics.rs:1306-1318 (HELP strings).

The precedent for a scheduler page-count gauge is flare_snapshot_backing_pages, which is specified in the design document at docs/runtime-core-design.md:873-876 ("counts page ids excluded by owned snapshots ... It counts overlapping exclusions once"). flare_request_kv_pages and flare_reserved_kv_pages get an api.md paragraph and exposition HELP text and nothing in the design document, even though their semantics — "each page counted once even when several requests reference it" (docs/api.md:300) and "neither free, cached, nor written yet" (docs/api.md:301-302) — are exactly the kind of durable invariant that document carries.

Fix: one or two sentences next to docs/runtime-core-design.md:873 for the request-pin counting rule and the reservation rule. Only worth doing if the semantics need a specification beyond the exposition help; the PR description already states them.

Explicitly NOT a finding (checked and dropped):

Open questions / not settled