Architecture scratchpad · NVIDIA/hyperflare-inference #496

Raw Markdown for agents: https://autobot.eidonix.com/p/2da89c5e-3a56-4c74-bf87-3c6375eb812a.md

#1 [high] Research summary

Lens B (architecture & scope). I read the charter, AGENTS.md (contribution scope/rejection criteria, required PR descriptions, validation), docs/design-review.md principles, docs/verification.md, docs/prefix-cache-offload.md (esp. §2.4, §2.5, §4, §5) and the changed code in selene/src/disk_store.rs in context (Staged, Resources, Owner, HostInbound, SharedSegment/SharedWindow, pump_device_inbound passes 1–5e, DiskStore::apply/fetch, Rate, plus composite.rs callers), and PR #497 as the stacked companion.

Verdict: the change sits in the right layer (Selene's disk transport; no CUDA, no model knowledge, no new flags/env switches, no per-model branching, no core/format change, and no re-export needed — behaviour derives from record path + header identity, which matches AGENTS.md "keep native specialization focused on cache storage contracts" and principle 3). It has served-workload evidence of the kind the charter demands for a performance PR ("benchmarks showing an actual speedup over main on a served workload"). But it adds a second, shared, reference-counted I/O lifecycle inside shared cache machinery (+2803/−913 in an already 8.8k-line file) and it silently changes what the store's own bandwidth metric means, which is used for restore-cost estimates.

Findings:

  1. should fix (high) — metering semantics changed: selene/src/disk_store.rs:1530/1829/3626-3628. SharedWindow::read_bytes accumulates the physical reply bytes once per window, and each follower adds the whole window's read_bytes to its own record.bytes (line 1829), which becomes stats.bytes_in and is fed to inbound_rate.observe(bytes, job.started.elapsed()). Before this PR each restore read its own windows, so bytes_in and the observed rate were both physical. Now bytes_in stays logical (bytes delivered to GPU) while physical reads drop up to 4.2×, so the observed inbound rate is inflated toward the coalescing factor. That rate is the basis of DiskStore::hit().estimated_seconds (line 3587) and of /metrics host_cache_inbound_bytes_per_second (helios/server/metrics.rs:1310 (not opened)) — the very number §4 of docs/prefix-cache-offload.md uses for "Inbound latency"/"Copy-out bandwidth" gating and that the PR's own table quotes. Effect: restore estimates used by tier choice/scheduling become optimistic (up to ~4× low) under concurrency, and qualification-measured disk bandwidth no longer means device bandwidth. Fix: feed the rate from physical window bytes (count a window's bytes once, e.g. at segment/window completion rather than per follower) while keeping bytes_in as the logical restored-bytes counter, and state the distinction in §2.5/§4. This is checkable from the code alone; a test asserting bytes_in == physical bytes / coalescing and rate stability across concurrency would settle it.

  2. should fix — scope/complexity needs maintainer sign-off, and the module contract is now self-contradictory. disk_store.rs:8-24 still promises "at most WINDOWS_IN_FLIGHT windows of one record staged at a time" and "Nothing here waits", while the file now hosts five new lifecycle types (HostInbound, SharedSegment with 5-state file machine, SharedWindow with two reference counts, DeviceActiveWindow/PlanState) with out-of-order plan completion, linear demand indexing, and a close-only-when-settled rule (lines 2205-2255). AGENTS.md "Reject unsupported abstractions and churn" and design-review principle 1/6 ask for the smallest footprint in shared code and explicit lifetimes; this is a substantial new ownership protocol in shared cache policy rather than a small fix. Recommendation: keep the technical content but require an explicit maintainer decision on the design (and on whether coalescing belongs in Staged versus inside the disk thread, which already owns the file handle), and rewrite the module/Staged doc comments so they describe the two-window-credit, follower-shared staging model rather than the old per-record window rule. As written, a future reader of the header comment will misread the invariants of pump_device_inbound.

  3. should fix — docs/prefix-cache-offload.md:337-342 asserts coalescing unconditionally and the same edited paragraph keeps signatures that do not exist. The text says concurrent fetches "share one open file handle and coalesce aligned 64-page windows while staged", omitting the two material caveats the PR itself discloses: windows already released are read again by later arrivals (so coalescing is best-effort and timing-dependent), and device restores now split up to one extra partial window when skip_pages % 64 != 0. Per AGENTS.md ("State support as present qualification… unresolved defects, unrun checks and pending measurements"), §2.4 should state those limits. Also, the paragraph this PR edited still claims write_from(key, metadata, buffers) and read_into(key, buffers); the real signatures are write_from(id, header, temporary, path, pages, row, sums) (line 1242) and read_into(id, path, header, first_page, pages, row) (line 1268). Fix both while the sentence is being touched.

  4. nit — evidence staleness: the PR's own "Not covered" note says the SM121 single-pass runs predate the linear demand-index and close-count edits, and that the numbers come from a revision before those changes. Those edits alter exactly the scheduling path that produced the measured windows, and AGENTS.md requires the claimed result to be tied to the code under review. Re-run at least one TP1 simultaneous and one staggered configuration at the head commit before merge, or restate the table's scope explicitly as measuring an earlier revision.

  5. nit — the coalescing counters exist only under test-support (lines 192-200 with allow(dead_code), accessors at 1213-1236), so nothing in a production or qualification run can show whether coalescing happened; combined with finding 1 the mechanism is unverifiable outside unit tests, while §4 of the offload doc gates defaults on store counters. Consider exposing opens/reads/coalesced windows through StoreStats (no per-model or flag implications) instead of test-only accessors.

Nothing found for the per-model-flags, environment-variable, format-compatibility or silent-field-drop criteria: the change introduces none of those, and the failure-isolation rules (private child/upload failures fail only their restore; shared open/read failures fail all attached restores after drain, keeping the record_read invalidation path at lines 3630-3641) preserve the existing "don't swallow the error" rule.

#2 [high] PR #496 lens B: bytes_in / inbound_rate inflation by coalescing

Finding 1 (should fix, high) — selene/src/disk_store.rs (PR #496 head f9c9191).

#4 [high] Report run 2 (head 0c04b1e2) — Lens B verdict: previous should-fixes resolved; 2 remaining notes

PR #496 lens B (architecture & scope), head 0c04b1e2

Previously reported, now resolved at 0c04b1e2

  1. inbound_rate no longer fed from logical bytes: DiskStore::apply short-circuits TransportEvent::InboundWindowSample into self.inbound_rate.observe(bytes, elapsed) (selene/src/disk_store.rs:3632-3635) and the old self.inbound_rate.observe(*bytes, job.started.elapsed()) inside the Fetched arm is gone (job field started removed, :3851-3856). stats.bytes_in += bytes stays logical (:3669). Docs state the split: docs/prefix-cache-offload.md:362-366 and :1529-1532.
  2. Module contract rewritten: selene/src/disk_store.rs:7-27 now describes per-fetch window credits, shared handles/follower windows, and "Submissions never block the caller … last user of a shared segment holds its Fetched event until the file close settles". Old "at most WINDOWS_IN_FLIGHT windows of one record" / "Nothing here waits" text gone.
  3. Docs §2.4 now carries the two limits (windows released before a later attach are re-read; skip_pages % WINDOW_PAGES != 0 adds ≤1 partial window per segment) and the real signatures write_from(id, header, temporary, path, pages, row, sums) (:1308) / read_into(id, path, expected, first_page, pages, row) (:1334); docs:337-366.
  4. Resources::allocate rustdoc restored above allocate (disk_store.rs:241-243) with free_slots doc at :236.
  5. WindowKey/HeaderIdentity/SegmentKey single definition (:1001-1064), window_index O(1) lookup, has_window_credit/attach_pending extracted, demand table HashMap<WindowKey, usize>; build_pending_demand short-circuit for device_inbound.len() <= 1 (:1760 área).
  6. Test-only coalescing counters gated with #[cfg(any(test, feature = "test-support"))] (:200-208, accessors :1279-1295).

Remaining findings

Should fix (layering) — a store-local statistic now rides the transport event channel and forces an unreachable!() in the sharded protocol mapper

Nit — estimated_seconds now prices restores at pure disk-thread bandwidth, excluding staging and GPU upload

Held (scope/process, unchanged)

Verified sound in this pass

#5 [high] Research summary

Reviewed PR #496 at head 0c04b1e2 through the architecture-and-scope lens against the charter, AGENTS.md contribution/rejection criteria, docs/design-review.md (not opened) and docs/prefix-cache-offload.md, reading every changed function in context plus its callers (shard.rs, composite.rs, disk.rs, levels.rs, store.rs, record.rs, helios metrics/runtime).

Of the four should-fixes I raised on the previous revision, three are now genuinely fixed in code and docs: the inbound rate is fed from physical window bytes instead of logical per-record bytes (disk_store.rs:3632-3635), the module contract describes the new per-fetch window-credit/follower-sharing/settle-before-Fetched model (disk_store.rs:7-27), and §2.4 now carries the two coalescing limits plus the real write_from/read_into signatures (docs:337-366). The design call for a second inbound lifecycle inside Staged is now argued in the PR's Why section, leaving only a maintainer sign-off to record.

What remains: a should-fix layering issue — the new TransportEvent::InboundWindowSample variant puts a store-local metering sample into the enum that is also the cross-rank wire event set, forcing an unreachable!() in Kind::of (shard.rs:476-478) whose invariant is upheld only by hand at two call sites and which the shard test helper at shard/tests.rs:338-339 would already trip; and a nit that inbound_rate now measures pure disk-thread time (disk::Reply.elapsed, disk.rs:447-454), excluding staging and GPU upload, so hit().estimated_seconds and worth_transfer price restores optimistically even for a single restore. No format, flag, per-model or wire-protocol break was found.

#6 [high] Report run 2 — finding titles/serities for the final report + rule citations used

Companion to entry #4 (which holds the evidence). This note holds the titles and rule citations the final report needs.

Verdict

No blocking findings. 1 should fix (layering), 1 nit, plus 1 held process note (maintainer sign-off for the design decision).

Finding titles

  1. Should fix: a store-local metering sample is carried on the transport event channel and forces unreachable!() in the sharded protocol mapper — selene/src/disk_store.rs:97-101 (InboundWindowSample), selene/src/shard.rs:476-478, hand-maintained at shard.rs:722-725 and shard.rs:1148-1150; would trip the existing helper at selene/src/shard/tests.rs:338-339. Fix: keep the sample in Staged behind a method (like in_flight()/pool()), or fold the physical counters into StoreStats (selene/src/store.rs:227-244).
  2. Nit: inbound_rate now measures pure disk-thread time, so estimated_seconds prices restores optimistically — disk.rs:447-454 sets elapsed around worker.execute only; consumed at disk_store.rs:3615-3627 (hit), store.rs:422-438 (worth_fetching/worth_transfer), heros runtime.rs:2796, heros metrics.rs:640/1312; CompositeStore instead measures read_into completion spans (composite.rs:994-1004), so the two disagree.
  3. Held (process): maintainer sign-off for putting a second reference-counted inbound lifecycle in Staged vs in DiskThread; the PR's Why section now argues the layer choice, so this is a record-the-decision ask, not a code-shape ask.

Rule citations used for the layering judgement

What is settled (do not re-litigate)

#8 [high] Report of 2026-11-25, run 2 (run 370) — Lens B verdict: should-fix issues only; all verified at head 0c04b1e2

PR #496 lens B (architecture & scope) — head 0c04b1e2, 3 files, +3358/−933, no checks

Verdict: should-fix issues only, no blockers.

Scope: belongs in the repo

Charter "What gets merged" (charter line 35) names a measured performance/memory issue; AGENTS.md:165-166 the same. The PR measures on a served workload (flare run, 8 concurrent /v1/chat/completions, ingress-to-first-token TTFT, main c0c4f798 vs 0c04b1e2): 18,177.5 → 4,306.7 MB physical NVMe reads (−76.3%, 4.22×) and 7,974.6 → 5,662.8 ms median burst TTFT on Qwen3.8-27B-NVFP4 TP1 — satisfies design-review.md principle 12 ("Performance claims require … actual Helios service measurements") and the charter's benchmark requirement. No rejection criterion crossed: no CPU/non-NVIDIA path, no CUDA or model knowledge in selene, no per-model branch, no new flag/env/recipe knob, no Header/on-disk format change, no wire Kind change (shard.rs diff only adds a guard + drop at :476-478, :722-725, :1148-1150 — verified via pr_diff of shard.rs).

Should fix (verified this pass)

  1. Store-local metering sample rides the cross-rank event set. TransportEvent::InboundWindowSample { bytes, elapsed } (selene/src/disk_store.rs:97-101) has no JobId although the enum documents itself as "Completion the transport reports to the disk store" (:83) and every other variant carries an id. Consequences verified: Kind::of must panic (selene/src/shard.rs:476-478 unreachable!("window rate samples stay local to rank zero")), upheld only by hand at shard.rs:722-725 (absorb_local re-pushes the sample into self.events) and shard.rs:1148-1150 (Peer::forward drops it); the existing helper events.sort_by_key(|e| Kind::of(e).1) at selene/src/shard/tests.rs:339 would panic if a fetch ran in that test (test issues only stores/unlinks: shard/tests.rs:325-352). Also CompositeStore::poll bumps stats.progress for every transport event before dispatch (selene/src/composite.rs:1376), so each physical window now counts as progress and re-arms spill_parked + disk.maintain() (composite.rs:1418-1428, gated on maintenance_progress != progress) — a behavioural side effect of a statistic. Fix: keep the sample inside Staged (drain method next to in_flight()/pool(), disk_store.rs:1275-1303) or fold physical counters into StoreStats (selene/src/store.rs:227-244). Rules: charter line 9 "Solve the right problem in the right place"; AGENTS.md:188-193 "Reject unsupported abstractions and churn".
  2. HeaderIdentity's hand-written Hash tracks Header's PartialEq by hand. selene/src/disk_store.rs:1014-1050 hashes 14 fields, destructuring Header with .. at :1030, against Header's exhaustive PartialEq in another module (selene/src/shared/record.rs:136-152). A new Header field added to PartialEq silently drops out of the hash → SegmentKey/WindowKey equality stays correct (Eq/PartialEq still compare full headers) but equal-but-differently-hashed keys land in different map buckets, so coalescing stops silently with no test failure. Coalescing correctness rests on this: give Header a Hash impl (or hash only PrefixKey) and add an a == b ⇒ hash(a) == hash(b) test. AGENTS.md:182-186 "Reject weakened guarantees… do not silently substitute execution paths".
  3. Admission guard restates Layout::record_slots. selene/src/disk_store.rs:1767-1777 computes plan.count + layout_row_slots by hand while the allocator it predicts uses record_slots(pages, row) (selene/src/geometry.rs:180-182, called at disk_store.rs:245). One-line change; keeps the predictor and allocator from diverging. AGENTS.md:188-193 (no duplicated mechanisms).
  4. docs/prefix-cache-offload.md:337-366 is one ~250-word bullet carrying ~12 separate behaviours (open-handle sharing, alignment, credit semantics, demand scheduling, re-read-after-release limit, extra-partial-window limit, failure isolation split, metrics split), and the bytes_in/inbound_rate statement is repeated at :1528-1531. Split mechanism (here) from limits/failure scope (bullets) and state metrics only in §4. Design-review.md principle 16 / repo-prose skill (present-state spec, one claim per statement).
  5. Process (no code change): the chosen layer — a second reference-counted inbound lifecycle (SharedSegment five-state file machine :1085-1110, SharedWindow with disk_referenced+upload_referenced :1130-1150, out-of-order DeviceInbound :1166-1214, demand indexing :1734-1755) inside Staged rather than DiskThread — is argued in the PR Why and matches design-review.md:64-68 ("Never reuse inputs, pages, or slots while queued work or transfers reference them"), but AGENTS.md:201-206 asks that an invariant-level design decision be explicitly recorded by a maintainer, not settled by merge.

Nit (verified)

inbound_rate now measures pure disk-thread time: 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 + xxh3, excluding slot wait, copier queue and GPU upload. hit() divides by it (disk_store.rs:3625), feeding worth_fetching/worth_transfer (store.rs:422-438) and the host_cache_inbound_rate metric, so restore estimates are optimistic even for a single restore; before this PR the rate was observed per record over Inbound.started.elapsed() (main disk_store.rs:3172). CompositeStore measures a different quantity under the same name from read_into completions (composite.rs:994-1004). Fix: document inbound_rate as device read bandwidth and keep an end-to-end estimate, or include the per-record wait.

Verified sound this pass

Not settled here (other lenses / needs a run)

#9 [high] Research summary

Reviewed PR #496 at head 0c04b1e2 through the architecture-and-scope lens against the charter, AGENTS.md and docs/design-review.md, and re-verified every earlier finding in source this pass (disk_store.rs, shard.rs, composite.rs, disk.rs, store.rs, geometry.rs, shared/record.rs, offload.rs, docs/prefix-cache-offload.md:325-375 and 1515-1535, shard/tests.rs). Full write-up is scratchpad entry #8.

Verdict: should-fix issues only, no blockers. The change belongs in the repository: it fixes a measured problem on a served workload with a main-vs-head benchmark the charter's merge criteria and design-review principle 12 demand (18.2 → 4.3 GB physical reads, 7,975 → 5,663 ms burst TTFT), and crosses no rejection criterion — no CPU path, no CUDA or model knowledge in selene, no new flag/env/recipe knob, no Header or on-disk format change, no wire Kind change.

Should fix: (1) TransportEvent::InboundWindowSample (disk_store.rs:97-101) puts a job-id-less metering sample into the enum that is also the cross-rank wire event set, forcing unreachable!() in Kind::of (shard.rs:476-478) upheld by two hand-written guards (:722-725, :1148-1150), would panic the existing helper at shard/tests.rs:339, and makes each physical window count as progress in CompositeStore::poll (composite.rs:1376, maintenance gate :1418-1428); (2) HeaderIdentity's hand-written Hash (disk_store.rs:1014-1050) tracks Header::PartialEq (record.rs:136-152) with a .. pattern, so a new field silently disables coalescing; (3) pick_next_pending_plan restates Layout::record_slots by hand (disk_store.rs:1767-1777 vs geometry.rs:180-182); (4) docs §2.4 (prefix-cache-offload.md:337-366) is one ~250-word paragraph of ~12 behaviours with the metrics contract repeated at :1528-1531; (5) process: maintainer sign-off to record the Staged-vs-DiskThread design decision (AGENTS.md:201-206). One nit: inbound_rate now measures pure disk-thread time (disk.rs:448-450), so hit().estimated_seconds prices restores optimistically while CompositeStore measures a different quantity (composite.rs:994-1004).

#10 [high] Run 370 (head 0c04b1e2) — severity-prefixed finding titles + rule citations the report must use

Companion to entry #8 (evidence). This note carries the exact titles, severities and rule citations for the final report of this run.

Verdict line

Should-fix issues only — no blocking findings. 5 should-fix, 1 nit, 1 held process note.

Finding titles (use verbatim, severity first)

  1. Blocking: none.
  2. Should fix: take the store-local window rate sample off the cross-rank transport event enum — selene/src/disk_store.rs:97-101 (InboundWindowSample, enum doc "Completion the transport reports to the disk store" at :83, no JobId); forces unreachable!() in Kind::of at selene/src/shard.rs:476-478; invariant upheld by hand at shard.rs:722-725 (absorb_local re-pushes it) and shard.rs:1148-1150 (Peer::forward drops it); the existing helper Kind::of-over-events at selene/src/shard/tests.rs:339 would panic if a fetch ran there; and CompositeStore::poll counts it as progress for every physical window (selene/src/composite.rs:1376), re-arming spill_parked + disk.maintain() at composite.rs:1418-1428. Fix: drain the sample from Staged (alongside in_flight()/pool(), disk_store.rs:1275-1303) or fold physical counters into StoreStats (selene/src/store.rs:227-244).
  3. Should fix: HeaderIdentity's hand-written Hash tracks Header's PartialEq by hand and fails silently — selene/src/disk_store.rs:1014-1050 (14 fields, .. at :1030) vs the exhaustive PartialEq in selene/src/shared/record.rs:136-152. A new Header field stays in PartialEq but drops out of the hash, so equal keys bucket apart and coalescing stops with no test failure. Fix: give Header a Hash impl or hash only PrefixKey; add an a == b ⇒ hash(a) == hash(b) test.
  4. Should fix: the admission guard restates Layout::record_slots — selene/src/disk_store.rs:1767-1777 recomputes pages + row_slots, while the allocator it predicts calls record_slots(pages, row) (selene/src/geometry.rs:180-182, used at disk_store.rs:245).
  5. Should fix: docs §2.4 is one paragraph carrying a dozen behaviours and repeats the metrics contract — docs/prefix-cache-offload.md:337-366, duplicate statement at :1528-1531. Mechanism here, limits/failure scope as bullets, metrics only in §4.
  6. Should fix (process, no code change): record the design decision — the second reference-counted inbound lifecycle inside Staged (selene/src/disk_store.rs:1085-1110, :1130-1150, :1166-1214, :1734-1755) rather than inside DiskThread; argued in the PR Why, but AGENTS.md:201-206 requires an explicit maintainer decision for a change to an invariant.
  7. Nit: inbound_rate now measures pure disk-thread time, so estimated_seconds prices restores optimistically — disk::Reply.elapsed set only around worker.execute (selene/src/disk.rs:448-450); consumed at disk_store.rs:3625 (hit) → worth_fetching/worth_transfer (selene/src/store.rs:422-438) and the host_cache_inbound_rate metric; previously per-record over Inbound.started.elapsed() (main disk_store.rs:3172); CompositeStore measures read_into completion spans instead (selene/src/composite.rs:994-1004).

Rule citations backing each judgement

Report must also state