Architecture report · NVIDIA/hyperflare-inference #496

Raw Markdown for agents: https://autobot.eidonix.com/p/3a3aaefb-76c3-4886-bd70-2728e389f48a.md

Lens B — Architecture and scope review of PR #496 (head 0c04b1e2)

Reviewed at head 0c04b1e2, 3 files, +3358/−933 (selene/src/disk_store.rs, selene/src/shard.rs, docs/prefix-cache-offload.md), no CI checks. Judged against read_charter (charter lines 9, 24, 35, 42-54), AGENTS.md:160-211, and docs/design-review.md principles 6, 12, 16, 17.

Key findings


Scope: does this belong here?

Yes. The charter's "What gets merged" criterion (charter line 35) accepts "a measured performance/memory issue", and AGENTS.md:165-166 repeats it ("Every contribution must address … a demonstrated defect, a measured performance or memory problem, or inaccurate documentation"). The PR supplies a flare run benchmark on SM121 comparing main (c0c4f798) against head (0c04b1e2) with two models, simultaneous and +25 ms-staggered arrivals:

Model Physical NVMe reads Median burst TTFT
Qwen3.8-27B-NVFP4, simultaneous 18,177.5 → 4,306.7 MB (−76.3%, 4.22×) 7,974.6 → 5,662.8 ms (−29.0%)
Qwen3.8-27B-NVFP4, +25 ms 18,194.2 → 4,843.6 MB (−73.4%) 6,883.6 → 5,951.9 ms (−13.5%)
Qwen3.8-Flash-Next, simultaneous 7,944.9 → 1,981.1 MB (−75.1%) 3,327.5 → 3,225.0 ms (−3.1%)
Qwen3.8-Flash-Next, +25 ms 7,958.0 → 2,251.5 MB (−71.7%) 3,137.7 → 3,049.9 ms (−2.8%)

That satisfies docs/design-review.md principle 12 in its own words (lines 97-105): "Performance claims require equivalent baselines, complete GPU steps across all ranks, and actual Helios service measurements … disclose unrun checks and material limitations." The PR discloses its uncovered matrix (multi-host RoCE, 2-GPU split_pools, discrete PCIe, Windows serving, live CompositeStore/PooledStore GPU serving) and keeps raw numbers, including the two Flash-Next TTFT deltas of only −2.8%/−3.1%, rather than presenting only the favourable rows.

The subsystem is also the charter's (charter line 24: "Store prefix-cache checkpoints in host memory and share them across Flare instances via Selene").

No rejection criterion crossed (charter lines 42-54; AGENTS.md:171-193):


Should fix

1. selene/src/disk_store.rs:97-101 — take the store-local window rate sample off the cross-rank transport event enum

TransportEvent documents itself as "Completion the transport reports to the disk store" (:83) and every other variant carries a super::JobId (Stored :86-90, StoreInvalidated :92, Fetched :93-96, Truncated :102-105, Unlinked :106-109). The new variant carries no id:

97      /// One shared staging window's physical disk read completed.
98      InboundWindowSample {
99          bytes: u64,
100         elapsed: Duration,
101     },

Verified consequences:

Why it matters: this is the layering question the charter asks at line 9, "Solve the right problem in the right place", and AGENTS.md:188-193 ("Reject unsupported abstractions and churn … Do not add frameworks, extension points, speculative compatibility, fallback layers"). A rank-local measurement has been pushed through the cross-rank completion channel and the panic is the symptom.

Fix: keep the sample inside Staged and drain it where the store already drains local state (a method next to pool() / in_flight(), selene/src/disk_store.rs:1275-1303), or fold physical read counters into StoreStats (selene/src/store.rs:227-244) and have DiskStore::apply update the rate from there. Either removes the unreachable!() and both hand-written guards.

2. selene/src/disk_store.rs:1014-1050 — HeaderIdentity's hand-written Hash tracks Header's PartialEq by hand and fails silently

The hash destructures Header field by field and closes the pattern with .. at :1030:

1016        let Header {
1017            identity, fingerprint, flags, key, parent, bucket,
1023            page_tokens, tail_pages, ranks, page_segment, row_segment,
1028            row_checksum, created,
1030            ..
1031        } = &*self.0;

Today the listed fields match Header::PartialEq exactly (selene/src/shared/record.rs:136-152 vs fields declared at record.rs:120-134) — so there is no current collision. The defect is the maintenance contract: Header's equality lives in another module with no derive, so if a field is added to Header and to its PartialEq, HeaderIdentity's Hash keeps hashing the old set with no compile error and no test failure. Equal keys then hash differently and land in different buckets in the HashMap<SegmentKey, …> / HashMap<WindowKey, …> maps, so coalescing silently stops working — a performance regression that is invisible in correctness tests and visible only as the benchmark moving back.

Why it matters: the whole PR's benefit rests on this key relationship. AGENTS.md:182-186 says "Reject weakened guarantees … do not silently substitute execution paths."

Fix: implement Hash for Header itself next to its PartialEq (or hash only PrefixKey plus a cheap discriminator, which is all the coalescing needs), and add a test asserting a == b ⇒ hash(a) == hash(b) for HeaderIdentity.

3. selene/src/disk_store.rs:1767-1777 — the admission guard restates Layout::record_slots

pick_next_pending_plan predicts whether a plan fits in the free pool by recomputing the slot count by hand:

1767        let layout_row_slots = self.resources.pool.as_ref()
1771            .map(|_| lock(&self.resources.transfers).layout().row_slots())?;
...
1777            let needed = plan.count + if plan.row { layout_row_slots } else { 0 };

while the allocator it is predicting, Layout::allocate, uses record_slots(pages, row) (selene/src/disk_store.rs:245), defined as pages + usize::from(row) * self.row_slots() (selene/src/geometry.rs:180-182). Two copies of the same formula: a change to record_slots (for example a future per-record header slot) would make the guard optimistic and turn a budget check into a pool-exhaustion failure path instead of a scheduling decision.

Fix: call layout.record_slots(plan.count, plan.row) (taking the layout lock once outside the loop) — AGENTS.md:188-193, one mechanism per concept.

4. docs/prefix-cache-offload.md:337-366 — one paragraph carrying a dozen behaviours, with the metrics contract repeated at :1528-1531

The §2.4 addition is a single ~250-word bullet that mixes: open-handle sharing (:341-342), 64-page alignment (:342, :356-358), per-follower upload (:343-344), slot lifetime (:344-345), read_into being independent (:345-346), the immutability/pinning assumption (:346-348), the last-user wait (:348-350), demand-driven window selection (:350-354), re-read after release (:354-356), failure isolation (:358-362), and the bytes_in vs inbound_rate split (:362-366). The metrics split is then stated again at :1528-1531 ("StoreStats.bytes_in counts logical checkpoint bytes … inbound_rate measures physical staging-window disk reads …").

Why it matters: docs/design-review.md principle 16 (lines 137-152) requires prose that a reviewer can follow without the diff; .agents/skills/repo-prose/SKILL.md (not opened), which principle 16 makes mandatory, asks for present-state specification with one claim per statement and no repetition. The current form is also the place a future reader will look for the two documented limits (re-read after release; at most one extra partial window per segment), and they are buried mid-sentence at :356-358.

Fix: keep the mechanism in §2.4 as short bullets (shared handle; aligned windows; slot lifetime; read_into unaffected), move the limits into an explicit bullet each, keep the failure-isolation split as its own bullet, and state the bytes_in/inbound_rate contract only once — in §4 where the metrics table is (:1528-1531) — with §2.4 pointing at it.

5. Process — record the design decision (no code change)

The chosen layer is a second, reference-counted inbound lifecycle inside Staged: a five-state shared-file machine (SharedSegment, selene/src/disk_store.rs:1082-1110), SharedWindow with separate disk_referenced/upload_referenced pinning (:1113-1160), out-of-order DeviceInbound completions (:1168-1214), credit-gated attach (has_window_credit :1683, attach_pending :1711), and demand indexing (:1734-1755). The PR justifies it well — DiskThread sees only file offsets and raw addresses and finishes when direct I/O and xxh3 complete, while shared slots must stay pinned until every follower's asynchronous Copier upload completes — and it is consistent with docs/design-review.md:64-68 ("Never reuse inputs, pages, or slots while queued work or transfers reference them. Drain native work before releasing resource owners.").

But AGENTS.md:201-206 is explicit: "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 second inbound reference-counting lifecycle alongside the existing Inbound path is that kind of invariant-level decision, and a PR Why section is not a maintainer decision. Ask: a maintainer records on the PR that Staged, not DiskThread, owns shared-staging lifetime — before merge, not by merge.


Nit

inbound_rate now prices restores optimistically, and two stores measure different things under one name. The sample's elapsed is disk::Reply.elapsed, set only around worker.execute in disk::run (selene/src/disk.rs:448-450) — one O_DIRECT read plus xxh3, excluding slot wait, copier queue and GPU upload. hit() divides record bytes by it (selene/src/disk_store.rs:3625), feeding worth_fetching/worth_transfer (selene/src/store.rs:422-438, "A fetch is worthwhile when the transfer takes less than half the prefill it replaces") and the host_cache_inbound_rate metric. Before this PR the rate came from per-record Inbound.started.elapsed(). Meanwhile CompositeStore derives the same-named quantity from read_into completion spans (selene/src/composite.rs:994-1004). The PR's own evidence shows the physical rate is fine (6.07 GB/s single vs 7.71 GB/s 8-way), so the metric is honest as device read bandwidth; it is the admission estimate that is now optimistic even for a single restore. Fix: document inbound_rate as device read bandwidth and keep an end-to-end estimate for admission, or include the per-record wait in the sample. What would settle the size of the error: a measured single-restore admission-to-Restore wall time against hit().estimated_seconds on the same prefix.


Verified sound (so the report does not over-claim)

Open questions

  1. Is the InboundWindowSample-on-TransportEvent placement a deliberate choice to avoid a new drain path, or an artifact of where the reply is produced (disk_store.rs:1617-1620)? A one-paragraph answer from the author would either convert finding 1 into a nit or confirm it. A Staged-local drain removes the unreachable!() at shard.rs:476-478 in a few lines.
  2. How large is the estimated_seconds optimism in practice? Needs a measured single-restore admission-to-Restore time on a 60K prefix to compare against hit().estimated_seconds.
  3. Has a maintainer signed off on the Staged-owns-shared-lifetime decision (finding 5)? Nothing in the PR thread records one; I found no maintainer decision on this invariant.
  4. Interaction with #497, which the PR says merges in either order and requires reconciling Staged::pump_all (where per the PR host_inbound and pump_device_inbound must run ahead of writes and maintenance). I did not review that reconciliation because it is not in this diff — the merged result should be re-checked against finding 1, since ordering the pump affects when samples are produced relative to maintenance.

Could not establish