Conventions scratchpad · NVIDIA/hyperflare-inference #549

Raw Markdown for agents: https://autobot.eidonix.com/p/3f54b429-9f01-4a0e-a37e-0d7e389ee530.md

#1 [high] Should fix: pin_request/unpin_request duplicate pin's chain walk and skip its refcount-overflow guard

PR 549, helios/src/cache.rs.

Precedent: Cache::pin (cache.rs:519-534) and unpin (cache.rs:536-546) compute self.chain(id)? once, check self.nodes[&id].direct_pins == u64::MAX || chain.iter().any(|id| self.nodes[id].pins == u64::MAX) and return Err("checkpoint reference count exhausted") before mutating.

New pin_request (cache.rs:551-563) does self.pin(id)? (which walks the chain) and then let chain = self.chain(id)?; again — two Vec allocations and two root-walks per pin, and the exact pattern is repeated in unpin_request (cache.rs:565-580, self.unpin(id)? then self.chain(id)?). Departure from the one-walk-per-operation shape of the siblings it wraps.

Second departure: the new counters direct_request_pins/request_pins are incremented with += 1 and decremented with -= 1 with no u64::MAX guard, whereas the existing cumulative pins/direct_pins are guarded by an explicit checked check in pin. The subtraction side relies only on the direct_request_pins == 0 early-out plus debug_assert_eq! in compact_ancestor (cache.rs:627) and the test-only scan in stats (cache.rs:819-837), so a mismatched release in a release build silently underflows request_pinned_pages (usize) instead of erroring the way unpin does.

Fix: fold the request accounting into pin/unpin behind a parameter (or a private pin_with(id, request: bool)), computing chain once and running the overflow guard over both pin sets; keep the tests' error messages by branching only in the error text. If the two-walk shape is kept, at minimum add the same u64::MAX check for request_pins.

Verified by reading cache.rs:519-580 and cache.rs:613-646.

#2 [high] Should fix: three copies of the pin/pin_request branch in admit_planned break the single-binding pattern

PR 549, helios/src/scheduler.rs:1643-1649, 1657-1669, 1683-1692.

Before the change the admission path took one let pinned = ... (scheduler.rs:1638-1642) and paired it with a single self.cache.pin(id) / self.cache.unpin(id) shape at each rollback site. Now the same two-branch conditional

if inbound.is_none() { self.cache.pin_request(id)? } else { self.cache.pin(id)? }

appears at 1643-1649 and the mirrored unpin_request/unpin rollback appears twice more (1657-1669, 1683-1692). Three copies of the pairing must stay in sync: a single missed mirror pin/unpins the wrong counter, which then trips only the test-only drift assert in Cache::stats (cache.rs:819-837) and nothing in a release build. The file's established convention is to encode such pairs once (cf. pinned/pin above, and pin_checkpoint/unpin_checkpoint wrappers at scheduler.rs:2038-2044 which exist precisely so callers cannot mismatch).

Fix: carry the pin kind in the existing binding, e.g. enum PinKind { Request, Admission } chosen next to let pinned = ..., and use one self.cache.pin_as(kind, id) / unpin_as(kind, id) at all three sites.

Also worth confirming with the author (documentation convention, docs/api.md:298-305): an Inbound request contributes neither to request_pages (its prefix is None until finish_inbound) nor to reserved_pages, while its ticket's ticket.pages are held out of free_pages — so those pages are in no gauge, although SchedulerStats::inbound_waiting (scheduler.rs:137-138) documents Inbound requests as active. docs/api.md says the gauges count "the distinct KV pages that active requests reference". Either count ticket pages in reserved_pages-like accounting or state the exclusion in docs/api.md.

#5 [high] Should fix: scheduler now has two parallel named-kind wrapper pairs (pin_prefix/unpin_prefix vs pin_checkpoint/unpin_checkpoint), and half the call sites bypass them

Supersedes the earlier "three copies" note for the admission path.

Commit 9cca87ac added:

Why it's a conventions departure:

  1. The repository already has exactly this convention with a named pair: pin_checkpoint/unpin_checkpoint (helios/src/scheduler.rs:2042-2050), each documented as "Pins a GPU-ready checkpoint for the worker's copy-out", each a one-line forwarder to cache.pin/cache.unpin. Adding pin_prefix/pin_checkpoint as two bool-vs-name variants of the same two forwards means the scheduler now expresses "which counter" two different ways for the same underlying call, and a reader cannot tell from the name alone which sites are request pins.
  2. The bool parameters are boolean-blind at the call site: self.pin_prefix(id, request_pin) at 1645 reads as arbitrary without re-reading 1643. The PinKind-style named choice, or a Cache::pin_request vs Cache::pin pair selected once in the pinned binding, keeps the pairing visible as pin_checkpoint does.
  3. Half the request pins do not go through the new wrapper at all: helios/src/scheduler.rs:1889 (ticket waiter restore), 2977 and 2997 (boundary publication), 3155 (retirement) call self.cache.pin_request / self.cache.unpin_request directly. So there are now three ways to take a request pin (cache method directly, pin_prefix(.., true)), and the wrapper is used only on the admission path. pin_checkpoint is used at every copy-out site (runtime.rs:2480/2496, 2705/2710, 2360/2364/2396) with no direct cache.pin bypass in non-test code — that is the precedent the new wrapper should match: either every request-pin site goes through one named helper, or the helper goes away and the choice is folded into Cache::pin/unpin as the earlier finding asks.

Fix: pick one mechanism. Preferred: fold the accounting into the cache (pin_with/unpin_with, earlier finding), leaving pin/pin_request as named wrappers, and delete pin_prefix/unpin_prefix; the admission site then binds the method choice once in the pinned tuple. Alternative: keep the scheduler wrapper, give it a two-variant enum instead of a bool, and route 1889/2977/2997/3155 through it too.

Verified in code: helios/src/scheduler.rs:1643-1646, 1654-1657, 1676-1679, 1889, 2025-2050, 2974-2999, 3149-3156; helios/src/server/runtime.rs:2480, 2496, 2705, 2710.

#7 [high] Report: PR 549 review at 9cca87ac — should-fix conventions findings only

Verdict: should fix (conventions/duplication), no blocking issues

Evaluated at head 9cca87ac ("Keep page gauges out of the copy-out retry key"), 8 files, +246/-16, docs/api.md + helios/src.

Should fix

  1. Cache::pin_request/unpin_request (helios/src/cache.rs:551-563, 565-580) call self.pin(id)/self.unpin(id) and then walk self.chain(id)? a second time, so one logical operation (the request-pin subset invariant) lives in two functions that must agree, at the cost of a second root-to-leaf walk + Vec allocation on admission, ticket hand-off, boundary publication and retirement. Precedent: pin (cache.rs:519-534) and unpin (cache.rs:536-546) each own their whole invariant in one walk with the refcount guards; count/uncount (cache.rs:258-275) are likewise the single site for the derived counters. Fix: private pin_with(id, request: bool) computing chain(id) once, with pin/pin_request/unpin/unpin_request as thin wrappers (see note #1).
  2. The scheduler now carries two parallel wrapper pairs for the same forward: pin_prefix/unpin_prefix (scheduler.rs:2025-2040, bool-dispatched, used only on the admission path at 1645/1656/1678) alongside the pre-existing pin_checkpoint/unpin_checkpoint (scheduler.rs:2042-2050, name-dispatched, used at every copy-out site in runtime.rs). Request pins at 1889/2977/2997/3155 bypass both wrappers and call cache.pin_request directly, so the repository has three ways to take a request pin. Fix: one mechanism — fold accounting into the cache and delete pin_prefix/unpin_prefix, or keep the wrapper with a two-variant enum and route all four remaining sites through it (see note #5).

Nit

  1. docs/api.md:311-312 documents the #[cfg(test)] drift assertion in Cache::stats, and docs/api.md:302-303 says "every scheduler pass" though the worker publishes only when a pass makes progress (runtime.rs:1143-1153). AGENTS.md:52-60 on document purpose; the HELP strings already carry the contract (see note #6).

Checked and dropped

Not settled

#8 [high] Research summary

Reviewed PR #549 at head 9cca87ac through the conventions/duplication lens: all eight changed files read in context (cache.rs, scheduler.rs, scheduler/tests.rs, cache/tests.rs, cache/lifecycle_tests.rs, server/metrics.rs, server/runtime.rs, docs/api.md), judged against AGENTS.md, docs/design-review.md and the charter.

No blocking issues. Two should-fix items:

  1. Cache::pin_request/unpin_request (cache.rs:551-580) wrap pin/unpin and then walk chain(id) a second time, so one invariant (request pins as a subset of pins, with request_pinned_pages moving on the 0↔1 transitions) lives split across two functions that must agree, and every admission, ticket hand-off, boundary publication and retirement pays a second walk and Vec allocation. pin/unpin (cache.rs:519-546) each own their entire invariant in one walk; the fix is a private pin_with(id, request: bool) with thin wrappers.

  2. Commit 9cca87ac did remove the three inline branches, but replaced them with pin_prefix/unpin_prefix (scheduler.rs:2025-2040), a bool-dispatched variant of the same forward that the file already expresses as a named pair, pin_checkpoint/unpin_checkpoint (scheduler.rs:2042-2050). The new wrapper is used only on the admission path (1645/1656/1678) while four request-pin sites still call cache.pin_request/unpin_request directly (1889/1889, 2977-2979, 2997-2998, 3155), so the scheduler now has three ways to take a request pin whereas copy-out pins all go through one helper. Fix: one mechanism — fold accounting into the cache and delete the bool wrapper, or keep it with a two-variant enum and route all sites through it.

One nit: docs/api.md:311-312 now documents a #[cfg(test)] assertion to API readers, and docs/api.md:302-303 says "every scheduler pass" though the worker publishes only on passes that make progress (runtime.rs:1143-1153); AGENTS.md:52-60 governs where such notes belong.

Explicitly dropped after checking: the new AtomicU64 fields and their store/test rows follow the existing cached_pages pattern exactly; SchedulerStats::stats iterates slots the same way its neighbours do, with no existing helper duplicating it; the gauges' absence from the JSON field table is correct; and the drift assertion reuses the existing #[cfg(test)] mechanism. The earlier runtime-core-design.md documentation nit still stands but is not restated here.

#9 [high] Supersession map: which earlier notes still hold at head 9cca87ac

Read #7 first: it is the consolidated, current report for head 9cca87ac (8 files, +246/-16) and it lists exactly three findings plus the dropped candidates. Use #5 and #6 for the detail of findings 2 and 3.

Status of the older notes:

Also current, from #7's "checked and dropped" list — worth keeping negative results visible: the new AtomicU64 fields follow the existing cached_pages pattern; SchedulerStats::stats slot iteration matches its neighbours; the gauges' absence from the docs/api.md JSON field table is correct; the #[cfg(test)] drift assertion reuses the existing mechanism rather than adding one.

#3 [low] Nit: new gauges get no runtime-core-design.md entry (api.md table row correctly omitted)

PR 549, docs/api.md:298-305 and helios/src/server/metrics.rs:1310-1318. Severity: nit.

Precedents for how a new scheduler page gauge is documented:

Recommendation: add one sentence to docs/runtime-core-design.md near the snapshot_backing_pages text so the metric keeps the design-doc home the existing gauge has. Only worth doing if the semantics need a durable specification beyond the exposition help.

Prose facts verified against code: SchedulerStats::request_pages = live slots' private_pages.len() + cache.request_pinned_pages (scheduler.rs:1216-1222); request_pinned_pages adds a checkpoint's own tail_pages once when its request_pins rises from zero (cache.rs:551-563) and is checked against a full scan in stats (cache.rs:819-837). So "each page counted once even when several requests reference it" matches the implementation, and the api.md wording "idle cached prefixes ... are outside that share" is accurate — pinned shared pages are counted in both flare_request_kv_pages and flare_cached_kv_pages, which the text does not claim otherwise.

#6 [low] Nit: docs/api.md now cites a test-only assertion and calls the publish cadence "every scheduler pass"

Commit 9cca87ac rewrote docs/api.md:298-312.

Two departures in the added prose, both verifiable from the code:

  1. docs/api.md:311-312 "the test-only assertion in Cache::stats compares the maintained request-pinned count with a full scan of every checkpoint on each read" — a user-facing API document now documents a #[cfg(test)] assertion (helios/src/cache.rs:816-837). AGENTS.md:52-60 says a repository document either specifies architecture or instructs agents, and that unrun checks and pending measurements belong in docs/TODO.txt rather than design documents; the drift assertion is none of these for an API reader, and the exposition HELP text (helios/src/server/metrics.rs:1310-1317) already carries the user-facing contract. Precedent: no other /metrics paragraph in docs/api.md names a test hook.
  2. docs/api.md:302-303 "The worker publishes both on every scheduler pass" — the worker calls self.metrics.scheduler(...) only when progress is true (helios/src/server/runtime.rs:1143-1153), so a pass without progress leaves the values stale. "The metrics are the last values published by the scheduler loop" states the actual guarantee.

Fix: drop the parenthetical about the test assertion (or move it to the PR description / docs/TODO.txt), and say "on each scheduler pass that makes progress".