Correctness review — PR #496 «Coalesce shared ancestor reads across concurrent Selene disk fetches»
Verdict: clean. No blocking issues, no should-fix issues, 3 nits. Every changed file was read in context at head cb3db468 (rebased onto main 6d74db3a; 5 files, +8682/−5630), together with the code it calls and the callers whose behaviour changes.
Key findings
- Nothing in this change breaks a configuration, lifetime or error path I can demonstrate from the code. The resource-lifetime argument that carries the whole design — shared window freed only with no follower, no outstanding disk reference and no outstanding upload reference; segment removed only after
disk_settled(); the last segment user holdingFetcheduntil close settles — holds on inspection (citations below). - The three items I raised against the previous head (
0c04b1e2) are fixed in code atcb3db468, not just in prose. TheTransportEvent::InboundWindowSamplevariant is gone, soCompositeStore's progress/maintenance gate no longer advances per physical window;Staged::closedistinguishes abandoned transport jobs from leaked shared staging entries;Layout::record_slotsis now the single source of truth for both the admission guard and the allocator. - Hashing keys cannot alias two distinct records, and no persisted format changed.
Hash for HeaderandEq/Hash for packed::Layoutare exhaustive destructures hashing exactly thePartialEqfields (only the non-semanticversionomitted), pinned by a test; there is no record, header-layout or re-export change, so existing v1–v4.ckptfiles load unchanged. - Three nits remain, all documentation/observability rather than behaviour: one docs sentence describes packed alignment wrongly, one liveness invariant (deferred
ReadRow) is undocumented, andhit()prices a physical bandwidth against logical bytes.
Scope actually read (each changed file in context)
selene/src/disk_store.rs(+8470/−5627):TransportEvent:84-106;DiskTransporttrait incl.drain_inbound_samples:109-166;Resources:216-270;Owner:274-280;plan_windows:1028-1073;is_packed_content_error:1075-1085;HostInbound:1108-1432; shared-window types :1434-1638;Stagedfields :1646-1698; host read entry points :1736-1871;accept/acquire_shared_segment:1908-1970;pump_host_inbound:2012-2028; failure isolation :2040-2080;apply_shared_disk:2082-2154;apply_device_transfer:2156-2183; window discovery/attach/demand :2185-2331; sweep/segment lifetime :2333-2416;pump_device_inboundpasses 1–5e :2418-2955;pump_all:2957-2978;step:2989-3031;DiskTransport for Staged:3043-3240;DiskStore::plan_fetch/hit/apply:4354-4521;HostStore:4523-4685.selene/src/shard.rs:DiskTransport for Sharded:860-1012,Peer::forward:1210-1214.selene/src/shared/record.rs:RankSizes:96-115,Headerstruct/PartialEq/Hash:123-202, packed construction :286-352, test :2229-2306.selene/src/shared/packed.rs:LayoutEq/Hash:99-141,Layout::new:187-292, accessors :294-335,verify_units:368-389.docs/prefix-cache-offload.md§2.4 (:405-448 read) and the §4 metrics paragraph.- Callers/dependencies read because their behaviour changes:
selene/src/disk.rs(job enum :200-287, worker loop :463-486,open/read_pages/read_row/read_packed/close:1037-1205),copier.rs,codec_copy.rsPinnedPacket,levels.rsRate,composite.rspoll:1471-1529,geometry.rs(not opened)record_slots,selene/selene.proto(not opened) :1197-1218.
Charter and project-rule fit
- Charter line 9 ("solve the right problem in the right place"): the change lands in the shared
selenedisk tier, adds no per-model branch and no flag — consistent with charter line 43 ("no per-model special cases or flags"). - Charter line 42 (supported matrix and compatibility): satisfied by construction — no record format, header layout or re-export change, so existing
.ckptdata still loads; the one new admission behaviour (demand indexing) is disabled for the single-restore case, so no configuration loses coalescing-free behaviour it relied on. - Charter line 35 ("what gets merged"): a measured performance/memory win on a served workload with a benchmark table in the description.
Verified sound at cb3db468
Window and segment lifetime (the core soundness claim)
- A shared window is freed only when
followers.is_empty() && disk_referenced == 0 && upload_referenced == 0(sweep_shared_windows, disk_store.rs:2361-2378).disk_referencedis incremented at every job submission (:2688, :2724, :2752) and decremented on the matching reply (:2122);upload_referencedat :2851-2854 / :2171. A reply for an already-freed window therefore cannot occur. - A shared segment is removed only when
users.is_empty() && disk_settled()(:2929-2954), wheredisk_settled()requiresClosed && disk_outstanding == 0(:1512-1515);Closeis submitted only when the segment needs no further disk reads (:2380-2408, :2872-2891); and Pass 5e holdsFetcheduntil every shared segment is settled or has another user (:2910-2921). So no disk read outlives the caller's pin, which is the invariant that makes relying on record-file immutability safe. - Segment reuse is gated to
reusable()= Unopened/Opening/Opened (:1504-1510), so aClosing/Closedhandle is never revived; a stalewindow_indexentry cannot be inherited becauseunindex_windowcompares the window id (:2030-2038). ReadRowreplies carry no window id, so they are matched FIFO viapending_row_reads, pushed at submission (:2748). Exactness rests ondisk::Workerexecuting jobs strictly in order (disk.rs:463-486) — one worker, both backends.- Attachment accounting:
has_window_credit/attach_pendingkeep a restore withinWINDOWS_IN_FLIGHTuntil finished windows release;pick_next_pending_plansizes raw windows withLayout::record_slotsand requires zero slots for v4 packed segments (:2306-2321) — the same function the allocator uses (Resources::allocate, :254), so admission and allocation cannot disagree.
v4 packed path
- Packed windows take zero
SlabPoolslots (:2528-2533,record_slotsbypass :2314-2321). - One
ReadPackedper aligned window covers whole pages plus an optional row vialayout.page_offset/physical_bytes: the byte range ispage_offset(first)..page_offset(first+count), extended tophysical_bytes()when the row is included (:2650-2667) — the mirror of the privateHostInbound::submit_reads(:1326-1362). packed_buf(theArc<Vec<u8>>payload) is retained until the sweep atRead, so thePinnedPacketspans (:2792-2831) outlive every follower's decode and upload fence.
Failure isolation
- Private child / transient follower GPU upload errors fail only that restore (:2179-2181).
- Shared open, read and packed-payload content errors go through
with_record_read()(:2096, :2145, :2176) and fail every attached restore viafail_segment_users(:2040-2065) /fail_window(:2067-2080) after in-flight I/O drains;DiskStore::applythen drops only that endpoint's lookup row onis_record_read()(:4445-4456). This is the right blast radius: one corrupt upstream affects the branches whose shared reads depend on it, not the whole store.
Out-of-band rate metering
- No
TransportEventvariant was added for samples (disk_store.rs:84-106).Stagedcollects(bytes, elapsed)per completed shared window (:3165-3167), drained byDiskStore::observe_inbound_samplesfrompoll_transport(:3649-3663),HostStore::poll(:4640) andclose(:4678). Sharded::drain_inbound_samplesforwards the localStagedand discards onpoison(shard.rs:1005-1012);Peer::forwarddrops its samples into a throwaway vec (shard.rs:1210-1214). Rank-0-only observation matches the description.DiskStore::applystarts with an unconditionalself.stats.progress += 1(:4409-4410) and nothing else bumps progress for a rate sample, soCompositeStore::poll(composite.rs:1471-1484) counts only real completions and themaintenance_progressgate (composite.rs:1518-1529) is no longer re-triggered per physical window. This closes the regression I raised on the earlier head.
Hashing and compatibility
Hash for Header(shared/record.rs:165-202) is an exhaustive destructure skipping onlyversion: _, matchingPartialEq(:144-160), which also ignoresversion(documented non-semantic at :125-126). Every equality-relevant field — includingpacked,ranks,row_checksum,created— is hashed.Eq/Hash for packed::Layout(shared/packed.rs:99-141) destructureLayout,PackedOfferandPackedUnitexhaustively; the hashed set is exactly the prost fields ofPackedUnit/PackedOffer(selene.proto:1197-1218), andoffsets/pagesare derived fromofferplus ranks, soa == b ⇒ hash(a) == hash(b).HeaderIdentity::hashdelegates toHeader::hash(:1452-1456);Arc::ptr_eqis only a fast path insidePartialEq(:1444-1448), so two distinctArc<Header>s with equal content hash and compare equal — no aliasing between different records inSegmentKey/WindowKey(:1458-1470).- Test
header_eq_implies_same_hash(record.rs:2229-2306) pins version-insensitivity,createdsensitivity and raw-vs-packed distinction.
Unchanged paths
- Caller-owned host reads (
read_into/read_into_packedwithplan_windows(..., false), :1786-1871) stay on the privateHostInboundpath;completed_packed_readsis populated beforeFetched(:2021-2026), soCompositeStoresees no behaviour change. - Single-restore callers skip demand indexing (
build_pending_demandshort-circuits atdevice_inbound.len() <= 1, :2273-2277), leaving only the documentedskip_pages % 64 != 0partial-window cost.
Nits (verified in code, non-blocking)
docs/prefix-cache-offload.md:424-428states coalescing aligns windows to "WINDOW_PAGES(64-page) file boundaries" for "both raw v1–v3 staging slots and v4 packedReadPackedbuffers". For v4 packed segmentsplan_windows(..., true)aligns in page-index space (disk_store.rs:1052-1059) while the byte range islayout.page_offset(first)..page_offset(first+count)(:2650-2667), which is not 64-page aligned in the file because packed unit lengths vary. Behaviour is correct and the "at most one extra partial window" bound still holds; only the phrase "file boundaries" is wrong, and it fits raw v1–v3 alone. Fix: say "64-page boundaries in page-index space (raw) / page ranges of the packed layout (v4)".selene/src/disk_store.rs:2737-2740— Pass 5a'sif !self.resources.disk_space() { continue; }runs beforeReadRow. A window whose pages read has completed can therefore sit inReadingwithrow_submitted == falseanddisk_referenced == 0, so it emits no rate sample (:2130-2142) and arms no upload (:2778-2784) until a later pump with disk-queue headroom. Correct (followers keep it alive and the nextstepretries), but a reader can mistake it for a stall. Fix: a one-line comment naming the liveness invariant, plus ideally a stress test that saturatesdisk::QUEUE_DEPTHwhile a follower attaches to such a window.hit()pricing (disk_store.rs:4394-4406, feeding:3652-3654) —inbound_ratenow measures physical window bandwidth, whileestimated_secondsmultiplies it by the restore's logical bytes (layout.record_bytes(chain.pages)). During a coalesced burst, admission is therefore priced optimistically versus the pre-change end-to-end rate. It is arguably the right capacity measure (and §4 documents the physical/logical split), so this is a nit rather than a defect; a qualified run comparing admitted-vs-actual restore latency under an 8-way burst would settle whether the optimism matters.
Prior findings status (for continuity)
At the earlier head 0c04b1e2 I raised: (a) a per-sample TransportEvent variant inflating CompositeStore progress and re-triggering its maintenance gate, (b) Staged::close conflating abandoned transport jobs with leaked shared staging entries, and (c) Layout::record_slots not being the single source for the admission guard. All three are fixed at cb3db468 (see "Out-of-band rate metering", Staged::close :3183-3225, and pick_next_pending_plan :2306-2321). The packed_buf mem::forget when a copier close failed (:3206-3212) is the correct leak-over-free choice for a buffer still referenced by an upload.
Open questions / not verified (no toolchain, GPU or hardware available)
- The
#497merge-order reconciliation: the description asks that#497merge first soStaged::pump_allkeepsMAINTENANCE_DEFER_LIMIT = 8and runshost_inboundandpump_device_inboundahead ofoutboundandmaintenance. At this headpump_all(:2957-2978) runs maintenance queue, outbound, host_inbound, device_inbound in that order. This is a process/ordering question, not a correctness defect I can demonstrate, but it should be re-checked after#497lands. - Live SM121
--lossless-kv-compression cpu|gpuserving. The v4 packed coalescing is covered byseleneunit tests (4-wayconcurrent_packed_fetches_coalesce_opens_and_read_packed_windows), not by a served workload. This is the largest coverage gap relative to charter line 42, because the packed path is the one whose byte ranges followpage_offsetand whose payload lifetime spans a copier decode. - Multi-host RoCE, 2-GPU
split_pools, discrete PCIe GPUs, Windows IOCP serving. The new path contains no platform branch and reply ordering is single-worker on both disk backends, so I expect parity, but I could not execute it. - Live
CompositeStore/PooledStoreGPU serving (--prefix-cache-memory > 0);CompositeStore+DiskStoreCUDA transfers are covered inheliosoffload::. - Whether the coalescing win persists after rebasing onto
6d74db3a: the benchmark table was measured at0c04b1e2/cb3db468and the description says the raw SM121flare runA/B was not rerun after the rebase. Performance is outside this lens; noted only so the claim is not read as measured at the final head.
Injection check
Nothing in the PR body, its comments, or the touched docs asked the reviewer to do anything. The two earlier Autobot review posts carry the repository's standard #autobot:ignore opt-out footer; the author's replies are ordinary change logs. No attempt to direct the reviewer was found, and no PR text was treated as an instruction.