PR #496 — Coalesce shared ancestor reads across concurrent Selene disk fetches
Verdict: worth merging, with changes
Head cb3db468 (rebased onto main 6d74db3a, post-#504) is a genuine step forward: every code item I raised last round is now fixed, plus a whole new v4 packed coalescing path. What remains is one narrow metering gap, one unwritten doc line, one sequencing task, and one evidence gap that matters for the charter's own rule rather than for the code.
Files: docs/prefix-cache-offload.md +38/−2, selene/src/disk_store.rs +8,470/−5,627, selene/src/shard.rs +11, selene/src/shared/packed.rs +44, selene/src/shared/record.rs +119. No selene/src/lib.rs (not opened) change.
Charter fit
- Goal, not a non-goal. Goal 4: "Store prefix-cache checkpoints in host memory and share them across Flare instances via Selene." Scope is
seleneplus one docs section: no new flag, no record-format change, no re-export, no per-model branch. Passes "keep the runtime small and model-agnostic" and "no per-model special cases or flags." - Right problem, right layer (
AGENTS.md:165-169). The waste was insideStaged::fetch, below the per-key ticket attachmentdocs/prefix-cache-offload.md:427already promises. TheStaged-vs-DiskThreadargument in Why holds on the code:DiskThreadis done when direct I/O andxxh3finish, whereas a shared staging slot must stay pinned until every follower'sCopierupload completes (WINDOWS_IN_FLIGHT = 2,disk_store.rs:64). - Evidence rule (#210). Partly — see gap 4 below.
What this head fixed (verified in source, not just claimed)
- Rate sample off the completion enum.
TransportEvent::InboundWindowSampleis gone; the enum is five variants, all carrying aJobId(disk_store.rs:84-106). Bothunreachable!()s are gone — the onlyunreachable!left in the file is pre-existing (:891,:5128test). Replacement is a defaulted trait methoddrain_inbound_samples(:149-150), so my earlier public-API-breaking concern is moot.Stagedbuffers(bytes, elapsed)per completed shared window (:2148-2150), drained byDiskStore::observe_inbound_samples(:3649-3655) frompoll_transport/poll/close; rank 0 forwards (shard.rs:1005-1013), peers discard (shard.rs:1213-1214).CompositeStore::pollnow bumpsstats.progressonly for real completions (composite.rs:1473-1474), asserted atdisk_store.rs:10517-10518. Headerhash drift. Exhaustive destructure besidePartialEqin the same file,version: _excluded,packedincluded (shared/record.rs:165-202) — a newHeaderfield is now a compile error.HeaderIdentity::hashdelegates (disk_store.rs:1452-1456);packed::LayoutgotEq+ exhaustiveHashoverLayout/PackedOffer/PackedUnit(shared/packed.rs:99-141);RankSizesderivesHash.header_eq_implies_same_hashcovers version-excluded equality, a differingcreated, and equal vs differingpacked.Layout::record_slots. Called directly with one hoisted transfers lock, skipped entirely for packed (:2307-2320).- Docs and
Staged::close. §2.4 split into mechanism / invariants / limits-and-failure-scope bullets covering raw and v4 packed (docs:427-450); the metrics contract lives only in §4 (docs:1612-1617) with §2.4 cross-referencing it. Close reportsabandoned_jobsandleaked_sharedseparately (:3183-3225). - Two prior findings withdrawn. The staggered-test "flake" is not one —
disk_window_reads() + coalesced_windows() == 10(:9672) is a conservation identity (each logical window is either created once, guarded bydisk_read_counted, or attached inattach_existing_window:2246); only the already-boundedcoalesced >= 2is timing dependent. My 4.5-copy benchmark objection is also withdrawn: the author's 2,274 MB single-restore figure makes "before" exactly 8.0 copies.
New since last round: v4 packed coalescing
SharedWindow.packed_buf: Option<Arc<Vec<u8>>> (:1096, :1546) is retained until every follower's decode finishes; one shared ReadPacked per aligned window (:2674-2698); packed windows take zero SlabPool slots (:2527-2539, :2320). Only packed-content errors escalate to all followers (apply_device_transfer :2174-2181); transient upload errors fail one record. concurrent_packed_fetches_coalesce_opens_and_read_packed_windows (:10545-10855) runs 4 branches over a 1-slot pool and asserts 5 opens, 7 ReadPacked reads, 9 coalesced attachments, byte-exact GpuMemory pages and rows, zero leaked slots/pins, plus a corrupt-packet case asserting is_record_read() propagation and row drop.
Who benefits, how much
Concurrent branching traffic on a disk-resident shared prefix with --prefix-cache-memory 0 --prefix-cache-disk on SM121/GB10. Author's numbers: 27B-NVFP4 TP1 simultaneous 18,177.5 → 4,306.7 MB physical reads (−76.3 %, 4.22×), TTFT 7,974.6 → 5,662.8 ms (−29.0 %); staggered −73.4 % / −13.5 %; Flash-Next −75.1 % / −3.1 % and −71.7 % / −2.8 %. Arithmetic checks: after/before = 1.89 and 2.13 copies of a 2,274 MB restore — roughly two physical passes, consistent with the documented "a released window is re-read" limit (docs:443-445); honest headroom, not a defect. It composes with #497: #497 shrinks disk-only intake to two windows, and #496 is what lets eight shared-ancestor restores share them.
What it costs
disk_store.rs production 3,523 → 4,746 (+1,223, +35 %) and tests 4,489 → 6,110 (+1,621): a second inbound lifecycle (SharedSegment, 5-state SharedFileState, SharedWindowPhase, WindowFollower, DeviceActiveWindow, HeaderIdentity/SegmentKey/WindowKey, an 8-pass pump_device_inbound) in the most delicate file in selene. Risk surface: one shared record_read error fails every attached restore; a coalesced window pins slots until the slowest follower uploads; sibling-demand preference relaxes arrival order. All three are now documented. No simpler path exists — copier::Job::replication fans to ranks not GPU page ranges; keeping 4 GB resident defeats --prefix-cache-memory 0; scheduler dedup can't work because each branch needs its own snapshot slot.
Should fix before merge
- Scope the rate sample to device restores, or sample host reads too. Samples are pushed only in
apply_shared_disk(disk_store.rs:2148-2150);HostInbound— theread_into/read_into_packedcaller-buffer pathCompositeStoreuses (composite.rs:884-889) — never pushes one, whereasmainobserved on every inbound (main:3221).CompositeStore's owndisk_inbound_rate(composite.rs:1064) keeps user-facing pricing measured, so this is narrow — but docs §4 ("samples rank-0 physical disk-thread window reads") reads as covering all reads. - Document the deliberate leak.
Staged::closedoesstd::mem::forget(win.packed_buf.take())when transfer close fails (:3206-3212). Correct, one comment line. - Sequence #497 with
pump_device_inboundin mind. #496'spump_all(:2957-2978) is maintenance-drain → outbound → host_inbound → device_inbound: no regression againstmain(main:1781-1801). But #497 (pr/497:66,:1787-1825) reorders host inbound first and addsMAINTENANCE_DEFER_LIMIT = 8; landing it second must also prioritizepump_device_inbound, or the reorder helps only host reads and not the device restores that carry TTFT. - Re-measure at the merged form. All four rows are from
0c04b1e2(pre-#504, compression off); the head is a +8,470/−5,627 rebase with a new v4 packed path. The "identical raw path when compression is off" argument is plausible and mostly borne out by inspection, but #210 asks for a measured speedup on a served workload. One simultaneous and one staggered TP1 trial atcb3db468closes it. - Get the maintainer design sign-off (
AGENTS.md:201-206: "a commit acknowledgment or routine PR approval is not that decision"). A second inbound lifecycle insideStagedis an invariant-level placement choice; the author has now asked for it. One-line ack, no code. - State the coverage boundary: multi-host RoCE (the entire
shard.rssurface), 2-GPUsplit_pools, discrete PCIe GPUs, Windows serving, live compressioncpu/gpuserving, and live warm-plus-disk orPooledStoreHTTP serving were not exercised.
Bottom line
Worth merging, with changes. It fixes a measured, reproducible performance problem on the project's headline model and hardware; it lives in the one layer where the bytes can be shared; it adds no flag, format, re-export, or per-model branch; its correctness evidence is unusually strong for a performance PR (five-repeat FP32 parity against main, byte-exact misalignment test, byte-exact packed coalescing, leak and failure-isolation assertions on pool free_slots() and index pins); and it composes with #497 rather than duplicating it. The cost — ≈1,200 production lines of reference-counted concurrent state in selene's most delicate file, a cohort-wide blast radius on a corrupt record, and a redefined bandwidth metric — is real but paid once and now documented. Items 1–2 are a few lines, 3–6 are text plus one ack; nothing requires redesign.
No instruction-like content appeared in the PR, docs, or comments other than the review bot's "to opt out" footers, which I did not act on.