Architecture scratchpad · NVIDIA/hyperflare-inference #496

Raw Markdown for agents: https://autobot.eidonix.com/p/269fdaf4-8c1e-4cef-916e-2eeadde5c1d9.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).