Review of PR #496 — Coalesce shared ancestor reads across concurrent Selene disk fetches
Lens: D, simplicity (what can be deleted). Reviewed selene/src/disk_store.rs (+2803/−913) and docs/prefix-cache-offload.md (+5/−1) against:
- the charter, line 9 ("Solve the right problem in the right place… Look for the smallest footprint in shared code, or a way to solve it without new code at all");
AGENTS.md"Contribution scope and rejection criteria" (188-193: "Do not add frameworks, extension points, speculative compatibility, fallback layers, or configuration switches without a concrete requirement… Refactoring must directly support the requested behavior or remove a demonstrated source of defects or cost") and 194-199 (validation must exercise real behaviour);docs/design-review.mdprinciple 1 ("Keep Helios as simple as possible"), principle 7 (published checkpoints are immutable), principle 12 (validate the real path, report evidence honestly).
Key findings
No blocking or should-fix findings in this lens. Nothing in the change is a fallback layer, switch or speculative abstraction: the split between a private caller-owned host path (read_into, 1268-1297, pumped at 844-996) and a coalescing device path (fetch → pump_device_inbound, 1820-2280) is exactly what the PR says it is, and read_into's observable behaviour is unchanged (same plan_windows planning at 1283, same window slicing of caller buffers now in HostWindow at 914-923, same close/unwind at 875-891 and 976-996). Slot release has one owner (sweep_shared_windows, 1755-1771) and each new test asserts pool.free_slots() == pool.slot_count(), which is the right property rather than a mock.
The eight findings are all nits, each with the smaller version:
-
disk_store.rs:258, 759-770, 1285 — the host inbound read is modelled as a
Vec<Segment>with an always-zero segment index.read_intobuilds exactly oneSegmentand inserts it at index 0 (Owner::HostInbound(id, 0), 1285;HostInbound::new(vec![segment], …), 1293-1294), yetHostInbound.segmentsis aVec(760),apply_disktolerates a missing segment withsegments.get_mut(segment)returning early (799-801), and the pump loops overself.segments(875, 892, 978). Smaller version:struct HostInbound { segment: Segment, … },Owner::HostInbound(JobId)with no index, and no.get_mut()tolerance for a case that cannot occur. This also removesSegment::reads_left(649): it is decremented only at 832 and compared at 877, whereself.done == self.plans.len()is already the condition computed two lines later at 892 — the close then waits one extra pump, which is harmless.WindowPlan.segmentbecomes dead for the host path. -
disk_store.rs:1093-1098 —
PlanState::Doneis never distinguished fromActive. Every read is!= PlanState::Pending(1606, 1660, 1698) or== PlanState::Pending(1796);Doneis only ever assigned (1833) and otherwise behaves asActive. Completion is already counted separately byrecord.done(1834, 2216). Smaller version: astarted: Vec<bool>(or aHashSet<usize>of started plans) onDeviceInbound, dropping the three-variant enum and the state nothing branches on. -
disk_store.rs:1071-1074 —
SharedWindowduplicates its segment's identity and its own key.SharedWindow.path/.expected(1073-1074) repeatSharedSegment.path/.expected(1024-1025), andfind_reusable_windowcompares them (1582-1583), cloning aPathBufand aHeaderper window at 1966-1967.acquire_shared_segmentalready dedups on path+expected (1371), soSharedWindow.segment(1072) identifies the pair. Smaller version: passseg_ref.sharedintofind_reusable_windowand comparewin.segment == seg_id, dropping both fields and the per-window clone. The one behavioural difference is attaching to an already-Readwindow whose segment has moved to Closing/Closed (the current path+expected compare would still match it, a segment compare would re-read) — worth a one-line comment if the fields are kept. The threeidfields that duplicate theirHashMapkeys (SharedWindow.idat 1071 against 1961-1964, likewise for segments and windows at 1000-1003 and 1372-1373) can go too by iterating(&id, seg). -
disk_store.rs:672-695 vs 700-738 — two window planners where one would do. After this PR
plan_windowshas exactly one caller,read_into(1283);plan_aligned_windowsserves the device path (2412). Both take(first, count, row)triples, emit ≤WINDOW_PAGES-sizedWindowPlans with the row on the last window and a row-only window whenpages == 0(676-680 vs 704-715), and differ only in where they split (segment-relative vs 64-page file-boundary aligned). Smaller version: callplan_aligned_windowsfromread_intoand deleteplan_windows(~24 lines) plus theplan_windowshalf ofwindows_split_segments_at_the_window_size_and_carry_the_row_last(6221-6253). Same window count bound, same bytes, only split points move; no behaviour asserted outside that one test changes. If the author prefers to keep host reads byte-identical to today, a comment at 672 saying why two planners exist would settle it. -
disk_store.rs:192-200 — three test-only counters live in the always-compiled
Resources, each with#[cfg_attr(not(any(test, feature = "test-support")), allow(dead_code))], a pattern not otherwise used in this file; their only readers are the new tests (8320-8322, 8428, 8443-8450, 8548-8550, 8668, 8778, 8843-8844) via accessors that are already#[cfg(any(test, feature = "test-support"))](1213-1229). Smaller version: put the same#[cfg(any(test, feature = "test-support"))]on the fields and on each increment (910, 1946, 1642, 946, 963, 2082, 2109) and drop the threeallow(dead_code)attributes — the patternselene/src/disk.rs:104-116already uses forFaults. Related:HostWindow.disk_read_counted(753, 921, 944-947, 961-964) andSharedWindow.disk_read_counted(1083, 1976, 2080-2083, 2107-2110) exist only sodisk_window_readscounts windows rather than jobs; one doc line on the field, or counting jobs instead, removes two state flags. -
disk_store.rs:1845-1861 and 1874-1903 — the attach loop is written twice and the credit check three times. Pass 2 and Pass 4 run the identical
needs_creditclosure (1847-1852, 1876-1881; the same predicate appears inline at 2122-2124) and the identicalfind_best_existing_window_for+attach_existing_windowloop; the only difference is Pass 4's demand-table decrement (1886-1900). Smaller version:fn has_window_credit(&self, id: JobId) -> boolandfn attach_pending(&mut self, id: JobId, demand: Option<&mut Demand>) -> boolreturning whether anything attached, called by both passes and by Pass 5b's check — roughly 30 lines less, one place to change credit policy, and the loop bodies cannot drift apart. -
docs/prefix-cache-offload.md:337-342 — one 60-word sentence carries three separate behaviours (a shared open handle, coalescing aligned 64-page windows to every attached GPU upload, and
read_intostaying independent), after a paragraph that starts at 333. The doc's own style elsewhere is one behaviour per sentence (compare 328-336). Smaller version: split at 339-342 into "Concurrentfetchjobs … share one open file handle per record." / "Each aligned 64-page window is read once and fanned out to every attached fetch's GPU upload before its staging slots are released." / "Caller-ownedread_intoreads run independently." This is required prose underAGENTS.md's prose review and principle 16 ofdocs/design-review.md, so it is worth the edit. -
Description vs code — "Existing users pay per-pump demand indexing when free slots exist" overstates the cost.
build_pending_demandreturns an empty table before doing any work whendevice_inbound.len() <= 1(1651-1653), andpick_next_pending_plantakes the layout lock once per call (1691-1695) rather than per pass. The statement is true only for multi-fetch pumps; saying so (or noting the single-fetchfast path) makes the perf claim exact. Not a code defect — flagging it because the description is what reviewers and future readers will trust.
Simplicity
All eight findings above are in this section; each names the smaller version. The two deletions I would actually ask for in review are #4 (one planner) and #6 (one attach helper) — they remove ~55 lines and a duplicated credit policy — followed by #1 and #2, which remove a Vec, an index, a counter and an enum variant. #3, #5 and #7 are polish.
On scale, which is the natural simplicity question for a +2803/−913 diff: I do not think the size is churn under AGENTS.md 188-193. The host path had to keep a private, unshared pipeline (read_into is called by CompositeStore with caller-owned buffers, selene/src/composite.rs:830 (not opened)), the device path had to gain per-file and per-window reference state to keep uploads and errors independent, and the eight passes in pump_device_inbound each carry an ordering argument that the others depend on (attach before sweep and before new reads, 1842-1844; release unreferenced slots, 1863-1865; start/attach new windows, 1867-1868; submit reads, then uploads, 2119-2121). That ordering is what makes the coalescing correct, and each pass has the comment to justify it, so I am not asking for a different shape — only for the duplication inside it (#6) to go.
What I checked and found clean
read_intoand the host path keep their old semantics: caller-buffer slicing moved fromDestination::HostintoHostWindow.pages/row(914-923), sub-window reads still re-submit throughpages_submitted/row_submitted(931-970), the error path still drains referenced replies and closes files before reporting (unwind, 976-996).- No obvious double release or slot leak:
sweep_shared_windows(1755-1771) is the single release point, gated on followers,disk_referencedandupload_referenced, andResources::releaseis idempotent viaslots.take(). - The new tests exercise the real path, not mocks:
SimulatedGpubyte-exact page and row assertions (8453-8460, 8468-8570), and the counters they assert (opens, window reads, coalesced windows) are physical counts incremented at the actualsubmit_disksites (910, 1946, 946, 963, 2082, 2109), so they satisfyAGENTS.md194-199. The shared fixtureswrite_shared_ancestor_tree(8136-8170) andpoll_all_fetches(8172-8189) are used by five of the seven new tests, so they are not scaffolding. pump_all(2268-2289) runs outbound, host-inbound, then device, consistent with the merge-order note against #497.
Open questions / could not settle from the code
- Whether
plan_aligned_windowscan simply replaceplan_windowsfor host reads (#4). No test outsidewindows_split_segments_at_the_window_size_and_carry_the_row_last(6221-6253) asserts host-read split points, so the behaviour looks free to unify; only the author knows if the segment-relative split was kept deliberately (e.g. to keepread_into's file reads page-aligned to the record rather than the file). A one-line comment would settle it. - Whether the
disk_read_countedflags (#5) are load-bearing for any assertion other thandisk_window_reads. They appear only in the counter increments and the tests that read the counter; if the counters are gated as suggested, the flags can go with them. - Nothing in this lens turned up a place where the change adds a switch, fallback or compatibility path that
AGENTS.md188-193 would reject.