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
- 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. - Should fix (lower confidence):
DiskStore::hitprices restores frominbound_rate, a rate that now measures disk-thread execution only, whileCompositeStorekeeps a same-named end-to-end quantity. The metric itself is honest and documented; the admission estimate that consumes it is optimistic. - Nit:
DiskTransport::drain_inbound_samplesis a default no-op, so the new metering can silently disappear for any transport that does not override it. - 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)
- The problem is admissible. Charter line 9 ("Solve the right problem in the right place… Look for the smallest footprint in shared code") and the "What gets merged" rule (charter line 35: "PRs that address a maintainer request, a roadmap item, a reproducible bug, a measured performance/memory issue, or bad docs") are both satisfied; AGENTS.md:165-166 agrees. The measured problem is concrete and pre-existing: eight concurrent restores of the same ~60K-token ancestor each open and read every ancestor file, 18,177.5 MB of physical reads where 2,274 MB of data exists.
- The layer is right. All of it is host-side I/O bookkeeping in Selene's disk tier: no CUDA code, no model knowledge, no scheduler change in Helios, no new
TransportEventvariant (selene/src/disk_store.rs:84-106is unchanged in shape), no core re-export, no on-disk format change. - Identity is derived, not declared. Sharing keys off
(path, expected Header)—SegmentKeyatselene/src/disk_store.rs:1458-1462,WindowKeyat:1464-1470— so no caller passes an opt-in flag and no new configuration switch exists. That satisfies AGENTS.md:188-193 ("Do not add frameworks, extension points, speculative compatibility, fallback layers, or configuration switches without a concrete requirement") and charter line 43 ("No per-model special cases or flags"). - No architectural violation under AGENTS.md:176-181. No Python callbacks, no eager serving, no runtime compilation, no steady-state GPU allocation, no model-specific policy, no executable metadata.
Concurrentfetch remains the only path; nothing is gated behind an env var or a flag. - Hashing is exhaustive now.
Header::hashdestructures every field withversion: _besidePartialEq(selene/src/shared/record.rs:144-160,:165-202),packed::LayouthasEq/Hashwith exhaustive destructures overLayout,PackedOfferandPackedUnit(selene/src/shared/packed.rs:99-141), andHeaderIdentity::hashdelegates to it (selene/src/disk_store.rs:1452-1456) while keeping theArc::ptr_eqfast path on equality (:1444-1448). Theheader_eq_implies_same_hashtest pins agreement, so a futureHeaderfield cannot silently stop coalescing. - The admission guard uses the allocator's own arithmetic.
pick_next_pending_plancallslayout.record_slots(plan.count, plan.row)and skips slot accounting for v4packedwindows (selene/src/disk_store.rs:2320), matchingResources::allocate(:254) andGeometry::record_slots(selene/src/geometry.rs:209). - Failure isolation is preserved and documented. Shared open/read/packed-content errors convert with
with_record_read()and fail every attached restore after in-flight I/O drains (fail_window,selene/src/disk_store.rs:2067-2080,is_packed_content_errorat:1075), a private child or transient follower GPU upload fails only that restore, andDiskStore::applystill drops the corrupt endpoint's row (:4454).docs/prefix-cache-offload.md:439-448states exactly this scope. - The host path is not penalised.
read_intousesplan_windows(..., false)(selene/src/disk_store.rs:1851), so caller-owned reads keep segment-relative windows; only the device path slices onWINDOW_PAGESfile boundaries. - The single-restore fast path is real.
build_pending_demandreturns early whendevice_inbound.len() <= 1(selene/src/disk_store.rs:2273-2294), so the documented extra partial window per segment is the only cost a lone restore pays. - Metering does not pollute progress.
drain_inbound_samplesis out of band,StoreStats.progresscountsapplyonly (selene/src/disk_store.rs:4410), andcoalesced_restores_keep_inbound_rate_physical_and_bytes_in_logicalassertsprogress == completed restoresandbytes_in == CONCURRENT × single. - Compatibility is untouched. No record-format, wire-protocol,
TransportEvent-variant or public re-export change, so the compatibility rule (design-review principle about existing data and artifacts still loading; charter line 42) is satisfied.
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
- Companion PR ordering. The description recommends merging #497 first and rebasing so
Staged::pump_all"retainsMAINTENANCE_DEFER_LIMIT = 8and runshost_inboundandpump_device_inboundahead ofoutboundandmaintenance".MAINTENANCE_DEFER_LIMITdoes not exist at this head (a search overselene/srcreturns nothing), andpump_allatselene/src/disk_store.rs:2957-2978currently runs maintenance → outbound → host_inbound → device_inbound. Whether the intended priority ordering survives the merge can only be checked on the merged result, so it should be re-verified after #497 lands rather than taken on trust. - Whether the architectural sign-off (S1) is genuinely open. Only a maintainer can answer; nothing in the PR thread records it as of this head.
- No toolchain or GPU was available to this review. Every finding is established from source at
cb3db468; nothing here depends on a test run. S2 would additionally be settled by the measurement described above. - Prompt-injection check: nothing in the PR body, comments or docs attempted to direct the reviewer; the
Discord: Doonerline is the only author-side contact detail.
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).