PR #496 — Coalesce shared ancestor reads across concurrent Selene disk fetches
Verdict: worth merging, with changes
The previous round's blocker (the 61.3K parity discrepancy) is settled, the inbound_rate metering defect is fixed, the docs now describe the mechanism, the benchmarks were re-run at the head that will be merged, and the TTFT arithmetic checks out. What remains is a benchmark-consistency question, one flaky assertion, one release-mode panic path, and the sequencing with #497. Nothing argues against the change on the merits. It solves a real, measured, charter-aligned problem in the right layer.
Charter fit — good, and better than last round
- 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
selene(disk_store.rs,shard.rs, one docs section). No new flag, no format change, no re-export, no per-model branch — so it satisfies "keep the runtime small and model-agnostic" and "no per-model special cases or flags." - The right layer. The duplication was inside
Staged::fetch, below the scheduler's per-key ticket attachment (docs/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 upward into Helios. - Evidence rule (#210). Now genuinely 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, and correctness evidence that a benchmark PR rarely carries (below).
The two PRs are complementary, not merely adjacent
#497 shrinks disk-only intake to intake_slots(layout, 1) — two staging windows — and explicitly documents that concurrent unique-prefix restores now serialize through them. #496 is what lets eight shared-ancestor restores share those same two windows instead of each demanding their own. Together they are "less RAM and less NVMe for the same burst"; separately, #497 alone would make shared-prefix bursts worse (more serialization) while #496 alone delivers its win on a larger pool. That is a coherent roadmap step and worth saying in the description.
Who benefits, and how much
Anyone running concurrent branching/agent traffic against a disk-resident shared prefix on SM121/DGX Spark with --prefix-cache-memory 0 --prefix-cache-disk — the configuration the docs default to for flare run (docs/core-design.md:1633).
Workload (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 arithmetic is internally consistent and now correct (the previous iteration's TTFT slips are gone): 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 tiny tails, and the removed duplicate reads (~3 × 4 GB at the measured 6–7.7 GB/s) account for the 2.31 s TTFT drop.
Read honestly: the bandwidth win is uniform (≈75 %) and the latency win is concentrated where the single disk thread is the bottleneck (27B TP1, −29 % / −13.5 %); on Flash-Next, 75 % less NVMe buys −3 %, and the description now says so. Single-stream restores, read_into/CompositeStore spill reads, and pool serving do not benefit — but they do not regress either: the single-restore path returns early from build_pending_demand (disk_store.rs:1736), looks windows up in window_index in O(1) (1646), and shares attach_pending with Pass 4 (1711), so its only residual cost is the documented ≤1 extra partial window per segment when skip_pages % 64 != 0 (docs:354-358).
Is there a still simpler way? No
I re-checked the alternatives at this head and they remain dead ends: copier::Job::replication fans one verified share to several ranks, not one host window to several different GPU page ids across requests; keeping these ~4 GB prefixes in DRAM is precisely what --prefix-cache-memory 0 avoids on a 128 GB Spark; and scheduler-side dedup can't work because each branch needs its own page range in its own snapshot slot. The narrowest place the bytes can actually be shared is where this PR puts it.
What it still costs
Complexity, honestly stated. disk_store.rs goes from 6,976 lines on main to 9,358 at head (tests start at 2,827 → 3,937), i.e. ≈+1,110 production lines and ≈+1,270 test lines in the most delicate file in selene. The new machinery is SharedSegment/SharedWindow(+ids), HeaderIdentity/SegmentKey/WindowKey, SharedFileState (5 states), SharedWindowPhase, WindowFollower, DeviceActiveWindow, DeviceSegmentRef, DeviceInbound, and an eight-pass pump_device_inbound (1883) over a dozen helpers. The author has since collapsed the duplicated key construction into WindowKey (1059), unified plan_windows behind align_to_window (682), removed PlanState, and gated the counters — the shape is now reviewable, and it is commented pass by pass. It is still a second inbound lifecycle in a file that already had two pipelines.
Intentional risk surface. One shared record_read error fails every attached restore; a coalesced window pins its SlabPool slots until the slowest follower's upload finishes (WINDOWS_IN_FLIGHT = 2, shared/limits.rs:18); sibling-demand preference relaxes strict arrival ordering. All three are now documented at docs/prefix-cache-offload.md:337-366, which is what I asked for last round.
Metering definition change (new, worth one line). DiskStore::hit still prices estimated_seconds = record_bytes / inbound_rate (disk_store.rs:3615-3628), and inbound_rate now observes disk-thread window throughput — excluding queueing and the GPU upload — where main observed per-restore end-to-end (Fetched). The worth_fetching gate (store.rs:423-438) and restore_wait.defer (helios/src/server/runtime.rs:2796) therefore became slightly more permissive, and flare_host_cache_inbound_bytes_per_second (helios/src/server/metrics.rs:1310) changed meaning for users. Measured 6.07–7.71 GB/s sits in the same band as #497's 8.68 GB/s single-restore end-to-end figure, so the bias looks small — but note in the docs that CompositeStore keeps its own end-to-end disk_inbound_rate (composite.rs:897, 1000-1003), and that on multi-host the sample is rank-0-only (shard.rs:1148-1150 drops it on peers).
Evidence — strong now
- Parity settled. Five cold-VRAM repeats (
seed = 1234..1238,60,534tokens,top_logprobs = 5) produced identical FP32 top-5 logprobs and token ids onmainand head (6/9, 8/9, 7/9, 9/9, 4/9both), with the honest explanation that Flare has no greedy mode (helios/src/model.rs:230-236(not opened)) and that the original single-pass script used per-build prompt nonces. That was the right root-cause answer, not a swallow. - New misalignment test.
misaligned_follower_attaching_to_shared_partial_tail_and_row_matches_private_restoreruns restore B (skip_pages = 13) alone on an isolated store and then as a follower on a shared store, and asserts byte-equalSimulatedGpupages and row — the direct test for the only plausible correctness hazard in this design. - Failure isolation and leak tests (
private_failure_isolation_preserves_sibling_sharing_ancestor,shared_ancestor_failure_propagates_to_all_followers_without_leaks,staged_close_drains_active_coalesced_fetches_cleanly) assert poolfree_slots()and index pins, which is what would actually leak here. CompositeStoreis better covered than the "Not covered" line admits:composite.rs:1229routes non-resident chains intoDiskStore::fetch→Staged::fetch(the coalesced path), andhelios/src/offload/gpu_tests.rs:1275-1289buildsCompositeStore+DiskStoreover real CUDA transfers in the 21/21 SM121offload::suite the author ran. Worth correcting.- I re-verified the invariants I flagged earlier and they hold:
window_indexcannot be clobbered by a live entry (Pass 4 only creates a window whenattach_pendingfound none,1916-1948);record.bytes += win.read_bytescredits exactly one window per completed plan (1901) with the key including(segment, first, count, row), so logical byte totals match;Fetchedis deferred until the last user's segment settles (2244-2255), which is what makes the pin release at3656-3658safe;SegmentKeyusesArc<Path>/Arc<Header>andHeaderIdentityhashes exactlyHeader'sPartialEqfields (shared/record.rs:136-152), so equal headers can't be missed.
What must change before merge
- Reconcile the "8 child branches" label with the read totals. "After" = 4,306.7 MB is ~one copy (954 pages ≈ 4.0 GB) — correct and impressive. But "before" = 18,177.5 MB is ≈4.5 copies, not 8 (8 concurrent ~4 GB restores should be ≈32 GB), while
flare_host_cache_bytes_in_totalis stated as 8× single (~32 GB) at the same time. Simultaneous and staggered before-totals differ by 0.1 % (18,177.5 vs 18,194.2), which suggests 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 would make 4.22× larger, so this is a credibility fix, not a threat to the win. - 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; W3 coalesces because both still need it"). Assert a bound (≥ 2coalesced, reads + coalesced ≥ 10) instead of an exact total that depends on disk-thread timing. This runs in CI (.github/workflows/native-serving.yml:51(not opened)). - Replace the
unreachable!inKind::of.shard.rs:476-478panics in release if any caller passes anInboundWindowSampleunfiltered. Both current sites filter first (shard.rs:722,1148), but a third call site is a serving crash. Make it adebug_assert!plus a benign default, or handle the variant inKind. - Add the two metering sentences to the docs (see above): the window rate excludes queueing and the GPU upload, and on multi-host it is rank-0 NVMe only. Also note that
TransportEventis public (selene::disk_store, not re-exported inlib.rs:44-56), so the new variant is a breaking change for any external exhaustive matcher — one line in What, and consider#[non_exhaustive]. - Sequence with #497 explicitly. Both PRs now say "merge in either order" but both edit
Staged::pump_all(disk_store.rs:2291) and #497 addsMAINTENANCE_DEFER_LIMIT. State the order and land the second one'spump_allas reviewed. - State the coverage boundary plainly in Evidence: discrete PCIe GPUs, Windows serving, 2-GPU
split_pools, and multi-host RoCE (the entireshard.rssurface of this PR) were not exercised live.mainis unaffected there, but the shard edits are untested beyond unit level.
Items 1–3 are small; 4–6 are text. None of them requires redesign, and 1 is likely a one-sentence correction.
Bottom line
Worth merging, with changes. By the charter's own tests: it addresses a measured, reproducible performance problem (#210) on the project's headline model and hardware; it sits in the one layer where the bytes can be shared; it adds no flag, no format, no per-model branch; its correctness evidence is unusually good for a performance PR and now includes byte-exact parity on the exact misalignment hazard and five-repeat FP32 parity against main; and it composes with the companion #497 rather than duplicating it. The cost is real — ≈1,100 production lines of concurrent reference-counted 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 pattern (branching agents against a shared prefix) that Flare exists to serve. Fix items 1–3, tighten 4–6, and merge.
(Conversation on the PR is this repo's own automated case-file/review bot plus the author's response; the only instruction-like text in it are the bot's "to opt out" footers, which I did not act on. No human reviewer has signed off yet, and docs/core-design.md / the charter do not require maintainer sign-off for this class of change — but the two behavioral trade-offs now documented in §2.4 deserve an explicit maintainer ack.)