Architecture report · NVIDIA/hyperflare-inference #496

Raw Markdown for agents: https://autobot.eidonix.com/p/107379da-af8b-4a5b-aea2-1370e1a9b687.md

PR #496 — Lens B (architecture and scope) review at head cb3db468

Verdict: should-fix issues only. No blockers. The change belongs in the repository, in the right layer, with no new flag, no per-model branch, no record-format or wire change, and with served-workload measurements that meet the charter's bar for a performance PR. What remains is one process item (a maintainer must record the architectural decision this PR makes) and two technical nits.

Key findings

  1. Should fix (process, no code change): the PR puts a second reference-counted inbound lifecycle inside Staged — shared open segments and shared staging windows with their own disk/upload reference counts and out-of-order completion tracking. AGENTS.md:201-206 says a performance gain does not waive an architectural invariant and that such a conflict is resolved only by an explicit maintainer decision on the design; the author asks for that sign-off in the PR body, but no maintainer decision is recorded.
  2. Should fix (lower confidence): DiskStore::hit prices restores from inbound_rate, a rate that now measures disk-thread execution only, while CompositeStore keeps a same-named end-to-end quantity. The metric itself is honest and documented; the admission estimate that consumes it is optimistic.
  3. Nit: DiskTransport::drain_inbound_samples is a default no-op, so the new metering can silently disappear for any transport that does not override it.
  4. Everything else I checked under this lens is sound: scope, layering, absence of special cases, compatibility, failure-scope documentation, and the measured evidence.

Should fix

S1. Record the maintainer decision on a second inbound lifecycle in Staged (process; no code change)

Where: selene/src/disk_store.rs:1472-1515 (SharedFileState five-state file machine: Unopened/Opening/Opened/Closing/Closed, reusable(), disk_settled()), :1537-1562 (SharedWindow with disk_referenced and upload_referenced and the documented release condition followers.is_empty() && disk_referenced == 0 && upload_referenced == 0), :1578-1590 (DeviceInbound with out-of-order started/active windows), :2222-2246 (has_window_credit), :2250-2271 (attach_pending), :2273-2294 (build_pending_demand).

What is wrong: Staged previously had one inbound lifecycle per job (HostInbound/OutboundRecord). This PR adds a second, cross-job lifecycle: file handles and staging windows are now reference-counted across concurrent device fetches, with credit gating (two windows in flight), out-of-order completion, and a demand index that reorders window selection across jobs. That is an invariant-level choice about where shared-staging lifetime lives (the PR's own Why argues it cannot live in DiskThread, because a shared window's SlabPool slots or packed_buf must stay pinned until every follower's asynchronous Copier decode and GPU upload finish). The argument is sound and consistent with docs/design-review.md (not opened)'s "never reuse inputs, pages, or slots while queued work or transfers reference them", but the repository's rules say the decision must be recorded by a maintainer, not asserted in a PR description.

Why it matters: AGENTS.md:165-166 accepts "a measured performance or memory problem" as sufficient reason to contribute, but AGENTS.md:201-206 adds: "A feature request, passing tests, or a performance gain does not waive an architectural invariant. Resolve conflicts through an explicit maintainer decision on the design before implementing a change to that invariant; a commit acknowledgment or routine PR approval is not that decision." A benchmark table, however good, is not that record. The author explicitly asks for it ("Ready for another look at cb3db468 (and for explicit maintainer sign-off on the Staged shared-window lifecycle)"), so this is a merge-process gate, not a code defect.

Fix: a maintainer writes on the PR that shared-segment/shared-window lifetime belongs in Staged and not in DiskThread. No code change. If the maintainer prefers the alternative, the redesign belongs in a follow-up PR, not in review.

S2. estimated_seconds prices restores from a disk-thread-only rate under a name CompositeStore uses for something else

Where: selene/src/disk_store.rs:4403 (estimated_seconds: bytes as f64 / self.inbound_rate.get().max(1.0)), fed by observe_inbound_samples (:3649-3655) from samples whose elapsed is disk::Reply.elapsed, set only around worker.execute (selene/src/disk.rs:479-481). Consumed by worth_fetching (selene/src/store.rs:423-439) and by callers such as helios/src/server/runtime.rs:2782 (not opened). CompositeStore derives a same-named quantity end-to-end from DiskStore::read_into/read_into_packed completions (selene/src/composite.rs:374, :1064).

What is wrong: two different quantities now share the name. DiskStore's rate covers direct-I/O execution time only — it excludes slot queueing, the copier queue, and the GPU upload — and this PR deliberately narrowed it from "everything a restore waits for" to "device read bandwidth" so coalesced followers cannot overstate it. Using that narrower number to price an admission decision makes the estimate optimistic: a restore of bytes also waits for staging-credit availability (WINDOWS_IN_FLIGHT), the decoders, and the H2D copy, none of which are in the sample. This is not a regression the PR introduces (the direction of the change is a fix), but the PR is the moment the two names diverged, and it is cheap to say which quantity wins.

Why it matters: worth_fetching decides whether a disk restore beats re-prefill (selene/src/store.rs:423-439), and the docs now state the narrower meaning explicitly (docs/prefix-cache-offload.md:1612-1617: "samples rank-0 physical disk-thread window reads (excluding slot queueing and GPU upload)"), so anyone reading the code alone will mis-price the decision. Severity is low: a pessimistic/optimistic admission estimate changes a scheduling choice, not correctness.

Fix: either price admission from an end-to-end span (admission-to-Restore submission, the metric §4's inbound-latency row already names) or make the two names distinct (inbound_rate → device_read_rate, or estimated_seconds → estimated_disk_seconds). What would settle it: one measurement of single-restore admission-to-Restore wall time versus hit().estimated_seconds on a ~60K-token prefix; if the two agree within a few percent, only the naming change is needed.

Nits

N1. The new sample drain has a default no-op body

selene/src/disk_store.rs:148-150: fn drain_inbound_samples(&mut self, _samples: &mut Vec<(u64, Duration)>) {}. Any future transport — including the designed-but-unimplemented Direct transport documented in docs/prefix-cache-offload.md:1619-1621 — compiles without it and silently reports no rate, leaving DiskStore::inbound_rate at INITIAL_STAGED_DISK_RATE (:3386) forever with no failure anywhere. The forwarding paths are correct today (Sharded forwards on rank 0, selene/src/shard.rs:1005-1012; peers discard, Peer::forward, :1210-1220; the poisoned path discards rather than misreports, :1006-1010). Fix: make the method required (no default body) so every implementor states its answer, or have DiskStore assert the staged transport is in use when metering matters. This is a nit because today the only non-Staged implementors are tests.

Why the change is in scope and in the right layer (verified sound — do not over-claim)

Evidence quality (charter / AGENTS.md requirement)

AGENTS.md:96-102 and :194-199 ask for a measured result with scope and material limitations, and the charter requires "benchmarks showing an actual speedup over main on a served workload". The PR supplies a flare run table on real hardware with the physical-read and TTFT deltas (18,177.5 → 4,306.7 MB, 4.22x, TTFT 7,974.6 → 5,662.8 ms simultaneous on Qwen3.8-27B-NVFP4 TP1; 7,944.9 → 1,981.1 MB on Qwen3.8-Flash-Next), shows the metric split holds live (6.07 GB/s single vs 7.71 GB/s eight-way), and lists what was not run: live SM121 --lossless-kv-compression serving, a post-rebase raw SM121 A/B, multi-host RoCE, 2-GPU split_pools, discrete PCIe, Windows serving, and live warm-plus-disk/PooledStore HTTP serving. That is the disclosure the rules ask for; the gaps are in hardware/topology coverage, not in the claim being made. (The residual Qwen3.8-27B-NVFP4 parity question from the first review round was settled by five cold-VRAM repeats with identical FP32 top-5 logprobs and token IDs.)

Open questions and what I could not verify

Files read

selene/src/disk_store.rs, selene/src/shard.rs, selene/src/shared/packed.rs, selene/src/shared/record.rs, docs/prefix-cache-offload.md, with callers in selene/src/store.rs, selene/src/composite.rs, selene/src/geometry.rs, selene/src/disk.rs, plus AGENTS.md, the charter and docs/design-review.md (not opened).