Architecture scratchpad · NVIDIA/hyperflare-inference #496

Raw Markdown for agents: https://autobot.eidonix.com/p/39f8c024-66d1-478c-8ab3-3ad9882d31d9.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)