PR #496 — Coalesce shared ancestor reads across concurrent Selene disk fetches
Verdict: worth merging, with changes
Nothing new landed on the branch (head is still 0c04b1e2; files: docs/prefix-cache-offload.md +35/−2, selene/src/disk_store.rs +3,313/−931, selene/src/shard.rs +10/−0). The change clears the charter's bar on all four tests it sets for a performance PR, and the prior round's blocker (61.3K retrieval parity) is settled. What is left is a short list of should-fix items — two of real substance, the rest docs and process. I update the previous report: one of the bot's five items is overstated, and two panic/consistency sites it did not mention need the same treatment.
Charter fit
- Goal, not a non-goal. Goal 4: "Store prefix-cache checkpoints in host memory and share them across Flare instances via Selene." This touches only
seleneplus one docs section. No new flag, no format change, no re-export (selene/src/lib.rs:44-56untouched), no per-model branch — so it 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 scheduler's per-key ticket attachment thatdocs/prefix-cache-offload.md:318-319already promises ("an inbound for a key already in flight attaches the request as another waiter"). The PR closes exactly that gap and does not reach up into Helios. TheStaged-vs-DiskThreadargument in Why is correct on the code:DiskThreadsees only file offsets and raw host addresses and is done when direct I/O andxxh3finish, whereas a shared staging slot must stay pinned inSlabPooluntil every attached follower's asynchronousCopierupload completes (WINDOWS_IN_FLIGHT = 2,disk_store.rs:63/shared/limits.rs:18). - Evidence rule (#210,
AGENTS.md:165-166). Satisfied at the head: before/after on a served workload (flare run,/v1/chat/completions, ingress-to-first-token TTFT), four topologies, cold-VRAM restart, plus correctness evidence (five-repeat FP32 parity againstmain, byte-exact misalignment test) that a performance PR rarely carries. - Maintainer decision (
AGENTS.md:201-206). The one process gap: putting a second inbound lifecycle insideStagedis an architectural placement call. The rationale is written in Why, butAGENTS.md:204-206wants the design choice recorded by a maintainer ("a commit acknowledgment or routine PR approval is not that decision"). Ask for that explicitly; it is a one-line ack, not a code change.
Who benefits, how much
Anyone running concurrent branching/agent traffic at a disk-resident shared prefix on SM121/DGX Spark with --prefix-cache-memory 0 --prefix-cache-disk — precisely the mode selene/src/offload.rs:600-641 builds as a bare DiskStore.
Author's GB10, head 0c04b1e2 |
Physical NVMe read | Median TTFT |
|---|---|---|
| 27B-NVFP4 TP1, simultaneous | 18,177.5 → 4,306.7 MB (−76.3 %, 4.22×) | 7,974.6 → 5,662.8 ms (−29.0 %) |
| 27B-NVFP4 TP1, +25 ms stagger | 18,194.2 → 4,843.6 MB (−73.4 %, 3.76×) | 6,883.6 → 5,951.9 ms (−13.5 %) |
| Flash-Next TP1, simultaneous | 7,944.9 → 1,981.1 MB (−75.1 %) | 3,327.5 → 3,225.0 ms (−3.1 %) |
| Flash-Next TP1, +25 ms stagger | 7,958.0 → 2,251.5 MB (−71.7 %) | 3,137.7 → 3,049.9 ms (−2.8 %) |
The TTFT percentages all recompute correctly, and the arithmetic is coherent: one 61,054-token prefix is 954 pages × ~4.19 MB ≈ 4.0 GB, so "after" at 4,306.7 MB is essentially one copy plus eight ~256-token tails, and the removed duplicate reads at the measured 6–7.7 GB/s account for the 2.31 s drop. The bandwidth win is uniform (~75 %); the latency win is concentrated where the single disk thread is the bottleneck (27B TP1), and the description now says Flash-Next only gains 3 %.
No-regression path, verified in the code: build_pending_demand returns early when device_inbound.len() <= 1 (disk_store.rs:1736), window_index is an O(1) HashMap lookup (1646-1663), attach_pending is shared with Pass 4 (1711), and plan_windows(..., align_to_window) only aligns for device restores (682-727). The single documented cost — at most one extra partial window per segment when skip_pages % 64 != 0 — is in docs:354-358.
Is there a simpler way? No
Re-checked at this head: copier::Job::replication fans one verified share to several ranks, not one host window to several GPU page ranges across requests; keeping a 4 GB prefix in DRAM is what --prefix-cache-memory 0 exists to avoid on a 128 GB Spark; and scheduler-side dedup cannot work because each branch needs its own pages in its own snapshot slot. The bytes can only be shared where this PR shares them. It also does not duplicate #497: #497 shrinks disk-only intake to intake_slots(layout, 1) — two staging windows — and documents that concurrent unique-prefix restores serialize through them; #496 is what lets eight shared-ancestor restores share those two windows. #497 alone would make shared-prefix bursts worse; #496 alone wins on a larger pool.
What it costs
- Complexity.
disk_store.rs6,976 → 9,358 lines (tests 2,827 → 3,937): ≈+1,110 production, ≈+1,270 test lines in the most delicate file inselene. New machinery:SharedSegment/SharedWindow,HeaderIdentity/SegmentKey/WindowKey,SharedFileState(5 states),SharedWindowPhase,WindowFollower,DeviceActiveWindow,DeviceSegmentRef,DeviceInbound, and an eight-passpump_device_inbound(1883) over a dozen helpers. The author has since collapsed key construction intoWindowKey(1059), unifiedplan_windowsbehindalign_to_window, removedPlanState, and gated the counters, so it is reviewable and commented pass by pass — but it is a second inbound lifecycle in a file that already had two. - Risk surface. One shared
record_readerror fails every attached restore; a coalesced window pins its slots until the slowest follower uploads; sibling-demand preference relaxes strict arrival order. All three are now documented atdocs/prefix-cache-offload.md:337-366. - Metering definition change.
DiskStore::hitpricesestimated_seconds = record_bytes / inbound_rate(disk_store.rs:3615-3628), andinbound_ratenow observes disk-thread window throughput — excluding queueing and the GPU upload — wheremainobserved per-restore end-to-end. That makesworth_fetching(store.rs:423-438) andrestore_wait.defer(helios/src/server/runtime.rs) marginally more permissive, and changes whatflare_host_cache_inbound_bytes_per_second(helios/src/server/metrics.rs:1310) means.CompositeStorekeeps its own end-to-enddisk_inbound_rate(composite.rs:358), and on multi-host the sample is rank-0-only (shard.rs:1148-1150drops it on peers). Measured 6.07–7.71 GB/s sits in the same band as #497's end-to-end 8.68 GB/s, so the bias looks small — but it must be in the docs.
Evidence — strong
- Parity settled the right way. Five cold-VRAM repeats (
seed = 1234..1238,60,534tokens,top_logprobs = 5) gave identical FP32 top-5 logprobs and token ids onmainand head (6/9, 8/9, 7/9, 9/9, 4/9both), with the honest root cause (Flare has no greedy mode; the first script used per-build prompt nonces) rather than a swallowed difference. - The one plausible correctness hazard has a direct test:
misaligned_follower_attaching_to_shared_partial_tail_and_row_matches_private_restore(disk_store.rs:8767+) runs askip_pages = 13follower alone and then as a follower and asserts byte-equalSimulatedGpupages and row. - Leak/failure tests assert pool
free_slots()and index pins (private_failure_isolation_preserves_sibling_sharing_ancestor,shared_ancestor_failure_propagates_to_all_followers_without_leaks,staged_close_drains_active_coalesced_fetches_cleanly). - Invariants I re-verified at this head:
window_indexcannot be clobbered by a live entry (Pass 4 creates a window only whenattach_pending/find_reusable_windowfound none,1646-1748);record.bytes += win.read_bytescredits exactly one window per completed plan (1901) with(segment, first, count, row)in the key, so logical totals match;Fetchedis deferred until the last user's segment close settles (2244-2255), which is what makes the pin release at3656-3658safe;HeaderIdentity::equsesArc::ptr_eqthenHeaderequality, so equal headers cannot be missed (1006-1010). CompositeStoreis better covered than the Not covered line says:composite.rs:1229routes non-resident chains intoDiskStore::fetch→Staged::fetch, andhelios/src/offload/gpu_tests.rs:1275-1289(not opened) buildsCompositeStore+DiskStoreover real CUDA transfers in the 21/21 SM121offload::suite the author ran. Correct that line.
Should fix before merge
- Get the rate sample out of
TransportEvent(the strongest item).InboundWindowSample(disk_store.rs:97-101) carries noJobIdyet sits in the enum documented as "Completion the transport reports to the disk store" (:83). It forces twounreachable!()s, not one:shard.rs:476-478(Kind::of) anddisk_store.rs:3638(DiskStore::apply's match, guarded only by the earlyif letreturn at3632), held up by the filters atshard.rs:722-725and1148-1150. A third call site is a release-mode serving crash; aStageddrain method or a field onFetchedremoves both.- Correction to the bot: the
CompositeStore::pollside effect it cites (composite.rs:1376stats.progress += 1, re-runningspill_parked+disk.maintain()at:1418-1428) cannot happen in the benchmarked configuration. With--prefix-cache-memory 0 --prefix-cache-disk,captureis false (offload.rs:587) andoffload.rs:632-641returns a bareDiskStore. It does bite warm-plus-disk configs, where ~954 windows would each trigger maintenance instead of ~8. Say so; do not let the wrong config justify the right fix.
- Correction to the bot: the
- Close the
HeaderIdentityhash drift — but not the way the bot suggests. It hashes 14 fields through a..pattern (disk_store.rs:1014-1050,..at:1030) againstHeader's exhaustivePartialEqin another module (shared/record.rs:136-152); a newHeaderfield silently drops out of the hash and coalescing quietly stops. DerivingHashonHeaderis wrong —versionis deliberately excluded from equality (shared/record.rs:118-119). Instead spell the ignored fields explicitly (version: _) so adding a field is a compile error, and add ana == b ⇒ hash(a) == hash(b)test. - De-flake
staggered_arrival_attaches_out_of_order_to_in_flight_windows.assert_eq!(staged.disk_window_reads() + staged.coalesced_windows(), 10)atdisk_store.rs:8487contradicts its own comment (8481-8484: "at least W1 and W2 are guaranteed"). Assert bounds (coalesced ≥ 2,reads + coalesced ≥ 10) instead of an exact total that depends on disk-thread timing; this runs in CI. - Document the metering semantics once. State that
inbound_rateexcludes queueing and the GPU upload, that on multi-host it is rank-0 NVMe only (shard.rs:1148-1150), and thatCompositeStorekeeps an end-to-enddisk_inbound_rate. Merge the duplicate statement (docs:362-366vs:1528-1531) and split the 250-word §2.4 paragraph into mechanism + limits/failure-scope bullets — the bot's item 4 is right on maintainability. - Note the public-API surface.
TransportEventis public viaselene::disk_store(not re-exported inlib.rs:44-56); adding a variant is a breaking change for any external exhaustive matcher. One line in What, and consider#[non_exhaustive]. - Reconcile the "8 child branches" label with the read totals. "After" = 4,306.7 MB is ~one copy — correct and impressive. But "before" = 18,177.5 MB is ≈4.5 copies, not 8 (8 concurrent ~4 GB restores would be ≈32 GB), while
flare_host_cache_bytes_in_totalis claimed to be 8× single (~32 GB) in the same breath; and simultaneous vs staggered before-totals agree to 0.1 % (18,177.5 vs 18,194.2), which points to a shared cause rather than arrival timing. Either the burst overlapped ~4–5 restores at read time or the physical gauge under-counts — say which. An honest 8-way figure makes 4.22× larger, so this is credibility, not a threat. - Sequence and reconcile with #497 in writing. Both now say "merge in either order" while both edit
Staged::pump_all(disk_store.rs:2291) and #497 addsMAINTENANCE_DEFER_LIMITplus inbound-first ordering. Note also that #497 shrinks integrated disk-only intake to two windows, which is exactly the pool this PR needs to be shared — state the order and land the second one'spump_allas reviewed. - State the coverage boundary in Evidence: multi-host RoCE (the entire
shard.rssurface of this PR), 2-GPUsplit_pools, discrete PCIe GPUs, Windows serving, and livePooledStoreGPU serving were not exercised live.mainis unaffected there, and #497 has the same boundary, but the shard edits are untested beyond unit level.
Items 1–3 are small code changes; 4–8 are text plus one maintainer ack. None requires redesign. The Layout::record_slots item the bot raised last (disk_store.rs:1777 vs geometry.rs:180-182) is cosmetic — record_slots(pages, row) is literally pages + usize::from(row) * row_slots — worth doing while touching the function, not a reason to hold the merge.
Bottom line
Worth merging, with changes. By the charter's own tests: it fixes a measured, reproducible performance problem (#210) on the project's headline model and hardware; it lives in the one layer where the bytes can be shared and adds no flag, format, re-export, or per-model branch; its correctness evidence is unusually good for a performance PR and now covers the exact misalignment hazard plus five-repeat FP32 parity against main; and it composes with #497 rather than duplicating it. The cost is real — ≈1,100 production lines of reference-counted concurrent state in selene's most delicate file, a cohort-wide blast radius on a corrupt record, and a changed bandwidth metric — but it is paid once, it is documented, and the alternative is 4.5× redundant NVMe reads for the exact burst shape (branching agents on a shared prefix) Flare exists to serve. Fix item 1 (both unreachable!s), 2 and 3, tighten 4–8, get the maintainer ack, and merge.
(Conversation on the PR is this repo's own automated case-file bot plus the author's responses; the only instruction-like text are the bot's "to opt out" footers, which I did not act on. No human reviewer has signed off yet.)