#1 [high] Research summary
Review of PR #496 (lens C: conventions and duplication) against the charter, AGENTS.md, docs/design-review.md and .agents/skills/repo-prose/SKILL.md (not opened). I read the whole diff (docs/prefix-cache-offload.md, selene/src/disk_store.rs) and each new construct in its surrounding code, plus the existing precedents it parallels (plan_windows, memory.rs::windows, Segment/InboundRecord, selene/src/testing.rs fixtures, StoreStats, the cfg(any(test, feature = "test-support")) instrumentation in selene/src/disk.rs). I could not build or run the suite (no compiler/hardware here), so every finding is from the code only.
Findings, by severity:
-
Should fix —
plan_aligned_windows(selene/src/disk_store.rs:700) duplicatesplan_windows(:672) almost line for line: same signature, sameWindowPlanoutput, same zero-page/row-only handling, differing only in that the chunk end is clamped to the nextWINDOW_PAGESboundary.selene/src/memory.rs:1336 windows()is a third copy of the same splitter. One function with an alignment mode (or afirst-alignment parameter) keeps the three call sites consistent; as written a change to row placement or empty-link handling must be made in three places. -
Should fix — the shared-window identity tuple
(path, expected Header, first, count, row)is re-expressed four times without a shared type: segment lookup bypath+expected(:1368),SharedWindowfield match infind_reusable_window(:1578), the demand-table key plus innerVec<(Header, usize)>scan (:1647–1677), and the demand-key reconstruction in the two decrement blocks (:1890 and :1996). The PR already introduces named ids (SharedSegmentId,SharedWindowId) in the same spirit; a singleWindowKey(with theHeaderreduced to a comparable digest, sinceshared::record::HeaderderivesPartialEqbut notHash) would make the identity definition one thing and let the demand map and window lookup share it. -
Should fix — per-pump allocation in the poll loop:
build_pending_demandclones aPathBufper pending plan and per bucket push (:1668), andpick_next_pending_plan(:1710) plus the two decrement blocks (:1890, :1996) cloneseg_ref.pathagain on every lookup. That is a heap allocation per plan perpump_device_inboundcall in steady-state serving, which the PR body itself acknowledges as new cost for existing users.find_reusable_windowalso scans everyshared_windowsvalue for every pending plan of every record (Passes 2 and 4). An index fromWindowKeytoSharedWindowId, alongside thepending_page_readsmap the PR already added, removes both the clones and the quadratic scan. -
Nit —
GatedCopier(:8051) andReverseWindows(:7732) are test copiers defined insidedisk_store.rs's test module, andGatedCopier::wrapreturns the positional 4-tupleGatedCopierParts(:8059) ofArc<Mutex<...>>handles. The established fixture precedent isselene/src/testing.rs(StoppedCopier:178,SimulatedGpu:225 withshared_mapped/sharedconstructors returning a two-element pair). IfGatedCopieris used by more than this test module it belongs beside those; either way a small named struct with fields beats a four-element positional tuple. The six new coalescing tests also repeat the same pool/store construction block (:8253–8330 and five more);write_shared_ancestor_treeandpoll_all_fetchesalready exist as fixture helpers and a matchingstore_for_fixturewould remove that repetition. -
Nit — the new counters (
disk_opens,disk_window_reads,coalesced_windows, :192–200) are unconditionalResourcesfields whose accessors, not the fields, are gated, requiring#[cfg_attr(not(any(test, feature = "test-support")), allow(dead_code))]— an attribute used nowhere else in selene/src (only two occurrences in helios/src). The precedent in this crate is to compile the whole test-only member out:selene/src/disk.rs:321,:437,selene/src/disk.rs:309keepfaultsunder#[cfg(any(test, feature = "test-support"))]. Gating the three fields the same way removes the threeallow(dead_code)attributes and the counter increments from release builds. Separately, the crate's stated home for counters isStoreStats(selene/src/store.rs:185–244, "counters every store maintains", reported by/metrics); a physical-open and physical-read count is exactly the kind of number an operator needs to see that coalescing is happening, and it currently reaches tests only. -
Nit —
Staged::close(:2485–2489) now computesabandonedas the sum of outbound/host_inbound/device_inbound/maintenance lengths,.max(usize::from(self.busy())), butbusy()also countsshared_segmentsandshared_windows, so the number can be a floor of 1 that is not a job count. The previous code counted owned disk jobs (owners.len()), and the message still reads "{abandoned} disk transport jobs did not complete". Either count what the message claims (owned disk jobs) or reword the message to what is counted. -
Nit — naming axis mixing in the new types: the record split is
HostInbound(:759) /DeviceInbound(:1117), but the window split isHostWindow(:746) /SharedWindow(:1070), and the phase enumsHostInPhase/SharedWindowPhase. The host path's counterpart ofSharedWindowis named by the other axis, so a reader pairing the two paths has to check both.PrivateWindow/SharedWindoworHostWindow/DeviceWindowwould keep one axis. -
Nit (prose, per the repo-prose skill) — the section 2.4 addition (docs/prefix-cache-offload.md:338–342) states the coalescing rule but not the constraint that makes it valid, namely that published record files are immutable and pinned for the duration of every restore referencing them; that is the invariant a reader needs before accepting that one handle and one staged window can serve several GPU uploads. The module doc comment (selene/src/disk_store.rs:17–21) has the same gap. The doc also says "aligned 64-page windows" while the rest of the section speaks of
WINDOW_PAGES/64 pages plus the multi-slot row (line 398); naming the constant where the alignment rule is introduced would tie the two statements together.
Nothing in the diff duplicates a helper that already did the job (no existing coalescing or shared-handle mechanism in selene/src, shard::Sharded has only a plain fetch at shard.rs:900), and the separator — Staged::read_into staying on the private path — is stated in both the code and the doc, consistent with the design-review principle 6 requirement that lifetimes be explicit. The duplication and instrumentation findings above are the lens-C issues; the highest-value ones are 1–3.
#2 [high] PR #496 lens C: conventions and duplication findings
PR #496 (open, head f9c9191, base main, 2 files +2808/−914: selene/src/disk_store.rs, docs/prefix-cache-offload.md). Reviewer lens C: conventions & duplication. Rules read: charter, AGENTS.md, docs/design-review.md, .agents/skills/repo-prose/SKILL.md. No build/test run possible here; all findings from code.
FINDINGS
-
should fix — plan_aligned_windows (selene/src/disk_store.rs:700) duplicates plan_windows (:672): identical signature, identical WindowPlan output, identical zero-page/row-only handling; only difference is chunk end clamped to next WINDOW_PAGES boundary (:721-722). Third copy of the same splitter is memory.rs:1336
windows(). Fix: one function with alignment parameter. -
should fix — the shared-window identity (path, expected Header, first, count, row) is re-expressed 4×: acquire_shared_segment matching (:1368-1373), find_reusable_window field match (:1578-1583), build_pending_demand key + inner Vec<(Header,usize)> scan (:1647-1677), and demand-key reconstruction at :1890 and :1996. No shared WindowKey type although the PR introduces SharedSegmentId/SharedWindowId. selene/src/shared/record.rs:110-117: Header derives PartialEq but not Hash, so a digest-based key is needed for hashing.
-
should fix — per-pump heap allocation: build_pending_demand clones PathBuf per pending plan/bucket push (:1668); pick_next_pending_plan clones seg_ref.path per lookup (:1710); decrement blocks clone again (:1890, :1996). find_reusable_window (:1576-1599) scans all shared_windows for every pending plan of every record in Passes 2 and 4. Fix: index WindowKey -> SharedWindowId like the PR's own pending_page_reads map.
-
nit — test copiers GatedCopier (:8051) and ReverseWindows (:7732) live in disk_store.rs test module; GatedCopier::wrap returns positional 4-tuple GatedCopierParts (:8059-8064). Precedent: selene/src/testing.rs StoppedCopier :178, SimulatedGpu :225 (shared_mapped/shared return a 2-element pair). Also the 6 new coalescing tests repeat pool/store construction (:8253-8330 etc.) while write_shared_ancestor_tree (:8136) and poll_all_fetches (:8172) already exist as helpers.
-
nit — counters disk_opens/disk_window_reads/coalesced_windows are unconditional Resources fields (:192-200) with only accessors gated (:1214-1229), requiring #[cfg_attr(not(any(test, feature="test-support")), allow(dead_code))] — pattern used nowhere else in selene/src (only helios/src/runtime_core/payload.rs:130, protection.rs:2657). Precedent: selene/src/disk.rs:309/:321/:437 gate the whole
faultsmember. Also StoreStats (selene/src/store.rs:185-244, "counters every store maintains", /metrics) is the crate's home for counters; physical open/read counts are operator-visible signal that only reaches tests. -
nit — Staged::close (:2485-2489)
abandoned= outbound+host_inbound+device_inbound+maintenance lengths .max(usize::from(self.busy())), but busy() also counts shared_segments/shared_windows, so it can be a floor of 1 that is not a job count; message still says "{abandoned} disk transport jobs did not complete". Previously counted owners.len(). -
nit — naming axis mixing: HostInbound (:759) / DeviceInbound (:1117) vs HostWindow (:746) / SharedWindow (:1070), and HostInPhase / SharedWindowPhase. HostWindow's counterpart is SharedWindow, named on the other axis.
-
nit (prose, repo-prose skill) — docs/prefix-cache-offload.md:338-342 states the coalescing rule without the invariant that makes it valid (published record files are immutable and pinned across every restore referencing them); module doc selene/src/disk_store.rs:17-21 has the same gap. Doc says "aligned 64-page windows" while the section speaks of WINDOW_PAGES plus the multi-slot row (doc line 398); name the constant where the alignment rule is introduced.
NEGATIVES / CHECKED, NOT A FINDING
- No pre-existing coalescing or shared-handle mechanism duplicated: shard::Sharded has only a plain fetch (selene/src/shard.rs:900).
- read_into stays on the private path (disk_store.rs:1268-1297) and the separator is stated in code and doc, consistent with design-review principle 6 (explicit lifetimes). Not a convention departure.
- Resources::free_slots() (:230) is a new small helper but no existing one does the job; resources.disk_space()/transfer_space() are its precedents.
- debug_assert! at :1923 is fine; used in selene elsewhere (memory.rs:534, composite.rs:647).
- Doc-side omission of test-support counters from /metrics is arguable either way; framed as nit above.
#4 [high] Should fix: HeaderIdentity hand-writes Hash mirroring a remote PartialEq
SELENE/src/disk_store.rs:1001-1050 — HeaderIdentity(Arc<Header>) implements PartialEq by delegation but writes Hash by hand, destructuring Header and hashing 14 fields one by one.
The contract it mirrors is impl PartialEq for Header in selene/src/shared/record.rs:136-152, an exhaustive field list in a different module ~1200 lines away (Header defined record.rs:116-134, Eq at :154).
Why it matters: the Hash destructure ends with .. (disk_store.rs:1030) and record.rs's PartialEq list is exhaustive. Adding a field to Header forces an edit in record.rs (compile error) but NOT here — the new field silently drops out of the hash, so two headers that compare equal can hash differently, window_index.get(&key) misses, and coalescing silently stops working (perf regression, no test failure; nothing in the suite exercises hash/eq agreement).
Precedent for the alternative: the crate derives both — PrefixKey derives PartialEq, Eq, Hash, PartialOrd, Ord (selene/src/vocab.rs:30), RankSizes derives PartialEq, Eq (record.rs:89), DiskRecord derives (disk_store.rs:72). Result 35 confirms this is the ONLY impl Hash written by hand anywhere in selene/src.
Fix: move Hash beside PartialEq in shared/record.rs (#[derive(Hash)] on Header, or a record::HeaderKey digest type defined next to it) so the two contracts cannot drift; then HeaderIdentity shrinks to the Arc + ptr_eq fast path. Alternative the PR already implies: key on an existing content digest rather than hashing the struct.
#5 [high] Should fix: new sample variant in the completion enum forces special-cases and inflates composite progress
selene/src/disk_store.rs:83-110 — the enum's own doc says "Completion the transport reports to the disk store", yet the new variant InboundWindowSample { bytes, elapsed } (:97-101) is a rate sample, not a completion, and every consumer must now special-case it:
- selene/src/disk_store.rs:3632-3638 —
applyearly-returns beforeself.stats.progress += 1, then the match needsTransportEvent::InboundWindowSample { .. } => unreachable!()to stay exhaustive. - selene/src/shard.rs:476-478 —
Kind::ofreturnsunreachable!("window rate samples stay local to rank zero"). This panic is load-bearing on two forwarding guards that must stay in sync: shard.rs:722-724 (absorb_localpushes to self.events andcontinues) and shard.rs:1148-1150 (Peer::forwardskips). A future caller that routes a sample throughKind::ofpanics instead of getting an error — the crate's convention at shard.rs:462 isreturn Err(invalid("unknown prefix record event kind")). - The wire
Kindenum (shard.rs:441-464) has no code for it, so a peer can never transmit it; the variant exists only on rank 0.
Concrete side effect, verified: CompositeStore (selene/src/composite.rs:1373-1386) drains transport events and does self.stats.progress += 1 at :1376 for every event before dispatch. That progress feeds the maintenance gate at composite.rs:1418-1424 (maintenance_progress != progress → spill_parked(...) + self.disk.maintain()). So each physical window read now re-runs both, once per 64-page window, per restore — the very maintenance cadence StoreStats.progress documents as "Completion and capacity-release events" (selene/src/store.rs:202).
Fix options: state in the variant doc that it is a sample and not a completion and make that structural (a separate fn drain_samples / out-parameter, or a field on Fetched), and exclude it from composite progress. The precedent for a rate signal that is not an event is the existing Budget::progress() counter (selene/src/input.rs:146-152) read by the store, rather than a unit variant of the completion enum.
Note the physical-rate mechanism itself is sound — DiskStore::apply observes inbound_rate at :3632-3634 and Fetched no longer observes it (:3669), which is exactly what the PR claims. This finding is about where the signal is carried.
#9 [high] Resolved-since-last-review list and the one remaining duplication (memory::windows)
Re-checked at 0c04b1e2. Previously reported as should-fix; mostly resolved, with one third copy remaining.
RESOLVED (do not re-report):
- Finding "plan_aligned_windows duplicates plan_windows": fixed — now one
plan_windows(segments, align_to_window: bool), selene/src/disk_store.rs:679-727, with a doc comment (:679-681) explaining whyread_intopassesfalse(:1349) andfetchpassestrue. - Finding "window identity re-expressed 5x, O(n) demand scan": fixed —
SegmentKey(:1052-1056),WindowKey(:1058-1064),window_index: HashMap<WindowKey, SharedWindowId>(:1229),build_pending_demandreturnsHashMap<WindowKey, usize>(:1734-1755),find_reusable_windowis an O(1) index lookup (:1646-1663). - Finding "per-pump PathBuf clone + O(windows x plans) scan": fixed —
SegmentKey.pathisArc<Path>(:1054) so cloning a key does not copy the path. - Finding "test-only counters behind allow(dead_code)": fixed — the three counters are proper
#[cfg(any(test, feature = "test-support"))]fields (:200-208). - Finding "Pass 2 / Pass 4 attach-loop duplication": fixed —
has_window_credit(:1683-1687) andattach_pending(:1711-1730) are extracted and shared (:1916-1918, :1932-1935). - Finding "doc prose lacks the immutable/pin invariant, says '64-page' not WINDOW_PAGES": fixed — docs/prefix-cache-offload.md:346-350 now states the immutability + index-pin + close-before-Fetched invariant, and :342/:356 use
WINDOW_PAGES. - Doc signatures now match code: doc says
write_from(id, header, temporary, path, pages, row, sums)/read_into(id, path, expected, first_page, pages, row)(docs:337-338); code agrees exactly (disk_store.rs:1308-1317, :1334-1342).
STILL PRESENT (third copy of the splitter):
memory.rs::windows() selene/src/memory.rs:1333-1367 remains a third expression of the same WINDOW_PAGES splitter with the same policy: pages.chunks(WINDOW_PAGES) (:1344), row attached to the last chunk (row: if last { row.clone() } else { None }, :1353), a row-only record gets one window (:1356-1365), an empty link gets none (empty chunks → falls through). That is the same three-way rule disk_store.rs plan_windows encodes at :689-700 (zero pages + row → one window) and :719 (row: row && chunk_end == end). Its output type differs (VecDeque<copier::Job> vs Vec<WindowPlan>), so full convergence is a refactor; the minimum is a test pinning the shared policy, or a comment on plan_windows naming memory::windows as its twin. Severity: nit now that the disk-side duplication is gone.
#12 [high] Report of 2026-11-25, run 254 — PR #496 lens C at head 0c04b1e2
Review of PR #496 — lens C: conventions and duplication
Head reviewed: 0c04b1e2 (base main c0c4f798). 3 files, selene/src/disk_store.rs, selene/src/shard.rs, docs/prefix-cache-offload.md. Rules applied: charter lines 9 ("smallest footprint in shared code") and 43/57; AGENTS.md:52-60 (document purposes), :82-102 (why/what/benefit/evidence), :188-193 (reject unsupported abstractions); docs/design-review.md:74 ("account for duplicate representations"); .agents/skills/repo-prose/SKILL.md:71,:84. Not runnable here (no toolchain/GPU), so every finding is established from code.
Verdict: should-fix issues only. No blockers. Six of my previous should-fix/nit findings are resolved at this head (see entry 9) — most notably the plan_aligned_windows/plan_windows duplication, the five-time hand-written window identity, the per-pump PathBuf clones and O(windows x plans) scan, and the Pass 2/Pass 4 attach-loop duplication. Three new should-fix items come from the fixes themselves.
Should fix:
- disk_store.rs:1001-1050 —
HeaderIdentityhand-writesHashover 14Headerfields in a destructure ending in..(:1030), mirroringimpl PartialEq for Headerat shared/record.rs:136-152 in another module. The only hand-writtenHashin selene/src. A field added toHeaderbreaks the compile in record.rs but silently drops out of the hash here → equal headers hash differently →window_indexmisses → coalescing silently stops. Fix: moveHashbesidePartialEqin shared/record.rs, or key on an existing digest. - disk_store.rs:97-101 + 3632-3638, shard.rs:476-478, composite.rs:1376 —
TransportEvent::InboundWindowSampleis a rate sample in an enum documented as "Completion ... reports" (:83). Every consumer special-cases it: twounreachable!()(disk_store.rs:3638, shard.rs:477) guarded by two skip checks that must stay in sync (shard.rs:722-724, :1148-1150); the wireKind(shard.rs:441-464) has no code for it. Concrete cost:CompositeStorebumpsself.stats.progressfor every transport event (composite.rs:1376), that progress surfaces inCompositeStore::stats()(:1482) and gates maintenance (:1418-1424), so each physical window read re-runsspill_parked+disk.maintain(). Fix: carry the sample out-of-band (a drain method or a field onFetched), precedentBudget::progress(input.rs:146-152); exclude from composite progress. The underlying physical-rate mechanism itself is correct (apply:3632-3634 observes;Fetched:3669 no longer does). - disk_store.rs:1766-1777 —
pick_next_pending_planrecomputes slots asplan.count + if plan.row { row_slots } else { 0 }whereLayout::record_slots(geometry.rs:180-182) already does it, and takes the transfers mutex per candidate plan.Resources::allocate(:243-254) usesrecord_slots, so theneeded > freeguard must agree with it.
Nits:
4. disk_store.rs:2513-2544 — close()'s abandoned is .max() over map sizes, so it can report one "disk transport job" for a leaked window (no jobs) or under-report 4 jobs behind 6 leaked windows; message at :2542 always says "disk transport jobs".
5. disk_store.rs:662-664 vs :1106-1109 — two different settled() predicates in the same file, both live.
6. disk_store.rs:1525-1527 / :1543-1545 / :1837-1839 — identical "unindex if index still points at it" block three times; :1813-1816 / :1900-1904 — identical follower-detach retain closure twice; :1690-1695 pushes the same (record, plan_index) identity.
7. memory.rs:1333-1367 windows() remains the third copy of the WINDOW_PAGES splitter (row on last chunk :1353, row-only one window :1356-1365, empty none) now that the disk-side pair is unified — the remaining one.
8. disk_store.rs:8092-8122 — GatedCopier::wrap returns positional GatedCopierParts 4-tuple; 3 of 5 call sites discard by position (:8406, :8530, :8984 _; :8650 _, _). Precedent SimulatedGpu::shared_mapped/StoppedCopier (testing.rs:178, :225) — named handles.
9. docs/prefix-cache-offload.md:337-366 — one 30-line ~250-word bullet carrying nine facts, and the bytes_in/inbound_rate contract is stated twice (:362-366 and :1528-1531).
Checked and sound (not findings): read_into staying private is the right call (explicit lifetimes, design-review principle 6); Resources::free_slots follows disk_space/transfer_space; debug_assert! at :1950 matches selene usage; no pre-existing coalescing/shared-handle helper is duplicated (shard.rs:900 fetch is plain); HeaderIdentity's Arc::ptr_eq fast path is correct; doc signatures now match code exactly (doc :337-338 vs disk_store.rs:1308-1342).
Unsettled: whether Header can derive Hash given its __ private version field is excluded from PartialEq (record.rs:118-119, correctly excluded from the new hash too); nothing here can be settled by a test without a toolchain.
#13 [high] Research summary
Reviewed PR #496 at head 0c04b1e2 through the conventions-and-duplication lens, re-checking every prior finding against the rewritten code and reading each new construct in context. Full report is scratchpad entry #12, with per-finding detail in entries #4–#11 and a resolved/sound ledger in #9.
Verdict: should-fix only, no blockers. Six of my previous findings are genuinely resolved at this head: plan_aligned_windows is folded back into one plan_windows(…, align_to_window); the five-times-hand-written window identity is now named SegmentKey/WindowKey with an O(1) window_index; the per-pump PathBuf clones and O(windows×plans) scan are gone (Arc<Path> keys); the Pass 2/Pass 4 attach loop is extracted into has_window_credit/attach_pending; test-only counters are properly cfg-gated; and the docs now state the immutability/pin invariant with signatures that match the code exactly.
Three new should-fix items, all created by the fixes: (1) HeaderIdentity hand-writes Hash over 14 Header fields with a .. rest-pattern, mirroring impl PartialEq for Header 1,200 lines away in another module — the only hand-written Hash in selene/src, and one where a new Header field would silently break coalescing instead of failing to compile; (2) the new InboundWindowSample is a rate sample placed inside TransportEvent, an enum documented as completions, forcing two unreachable!()s and two skip guards, and it makes CompositeStore count disk-window samples as progress, which gates its maintenance pass; (3) pick_next_pending_plan recomputes pages + row*row_slots by hand rather than calling the existing Layout::record_slots, so its admission guard can disagree with the allocator it guards.
Six nits remain, the substantive one being that memory.rs::windows() is now the last surviving third copy of the WINDOW_PAGES splitter policy, plus close()'s .max()-of-map-sizes message, two same-named settled() predicates, three repeated window-index/follower-detach idioms, the positional GatedCopier 4-tuple, and a 250-word §2.4 bullet that states the metrics contract twice.
Everything is from code reading; no toolchain or GPU was available, so nothing was compiled or run and no finding rests on a test result.
#6 [medium] Should fix: hand-rolled slot arithmetic instead of Layout::record_slots
selene/src/disk_store.rs:1766-1777 — pick_next_pending_plan computes the staging slots a plan needs by hand:
let free = self.resources.free_slots();
let layout_row_slots = self.resources.pool.as_ref()
.map(|_| lock(&self.resources.transfers).layout().row_slots())?;
...
let needed = plan.count + if plan.row { layout_row_slots } else { 0 };
Layout::record_slots(pages, row) does exactly this multiplication and already exists: selene/src/geometry.rs:180-182 (pages + usize::from(row) * self.row_slots()), with row_slots at :173-178. Its callers are everywhere (Resources::allocate at disk_store.rs:245, memory.rs:468, composite.rs:810, :1167).
Two problems with the hand-rolled version: (1) it restates a formula that lives in Layout — if record_slots ever accounts for something beyond pages+row (it is the crate's single definition of "how many slots a record costs"), the admission check here silently disagrees with the allocator that actually runs at :1987; (2) it takes the transfers mutex (lock(&self.resources.transfers)) on every call, for every candidate plan of every record, inside the pump — allocate takes the same lock again immediately after.
Fix: let needed = lock(&self.resources.transfers).layout().record_slots(plan.count, plan.row); — one call, same semantics, one source of truth. Hoist it out of the plan loop alongside free.
Precedent: the PR's own Pass 4 relies on Resources::allocate (:243-254) which uses record_slots; the two must agree for the needed > free guard to be meaningful.
#14 [medium] Coverage ledger: files and line ranges read at head 0c04b1e2
Coverage for the "every changed file has been read in context" condition of this review. PR #496 at head 0c04b1e2 changes 3 files (+3358/−933): selene/src/disk_store.rs, selene/src/shard.rs, docs/prefix-cache-offload.md.
READ DIRECTLY (line ranges, not just the diff):
- selene/src/disk_store.rs — :1-60 (module doc, imports); :60-135 (WINDOWS_IN_FLIGHT/RECORDS_IN_FLIGHT consts, DiskRecord, TransportEvent, DiskTransport trait); :186-285 (Resources incl. the three cfg-gated counters :200-208, free_slots :236-239, allocate :241-254, release :256-260, Owner :263-271); :651-760 (Segment, WindowPlan, plan_windows :679-727, HostInPhase, HostWindow :735, HostInbound :749-760); :806-900 (HostInbound::apply_disk, pump :834-886, start_window :888-918); :990-1215 (SharedSegmentId/SharedWindowId, HeaderIdentity + Hash :1001-1050, SegmentKey :1052, WindowKey :1058, SharedFileState, SharedSegment :1082-1110, SharedWindowPhase, WindowFollower, SharedWindow :1130-1150, DeviceActiveWindow, DeviceSegmentRef :1160-1164, DeviceInbound :1168-1214); :1295-1370 (write_from :1308, read_into :1334, store_pages :1367); :1410-1470 (next_shared_*_id, acquire_shared_segment :1428-1462); :1500-1560 (pump_host_inbound, fail_segment_users, fail_window); :1555-1663 (apply_shared_disk, apply_device_transfer, find_reusable_window); :1665-1755 (find_best_existing_window_for, has_window_credit, attach_existing_window, attach_pending, build_pending_demand); :1760-1830 (pick_next_pending_plan :1760-1793, detach_unwinding_windows); :1830-1990 (sweep_shared_windows, segment_needs_disk_reads, remove_shared_segment, pump_device_inbound Passes 1-4); :2440-2470 (fetch's SegmentKey construction :2443-2445); :2455-2552 (truncate, unlink, poll, close :2503-2547); :3620-3690 (DiskStore::apply incl. InboundWindowSample :3632-3638 and Fetched :3652-3671); :8092-8125 (GatedCopier::wrap); grep-verified call sites :8406, :8530, :8650, :8984, :9234.
- selene/src/shard.rs — :425-510 (protocol consts, Kind enum/code/decode :441-464, Kind::of :466-486); :700-740 (absorb_local :718-729); :1138-1160 (Peer::forward :1144-1155).
- selene/src/composite.rs (consumer of the changed enum) — :290-330 (streamed_event :300-327); :1360-1400 (poll loop :1373-1386); :1410-1490 (maintenance gate :1418-1429, stats progress :1482).
- docs/prefix-cache-offload.md — :325-410 (§2.4 rewritten bullet :337-366); :1518-1538 (§4 measurement table + new :1528-1531).
READ FOR PRECEDENT / RULES (not changed by the PR):
- selene/src/shared/record.rs :85-108 (RankSizes derives), :110-154 (Header :116-134 incl. private
version:118-119, impl PartialEq :136-152, impl Eq :154). - selene/src/vocab.rs :27-34 (PrefixKey derives PartialEq, Eq, Hash, PartialOrd, Ord).
- selene/src/geometry.rs :168-188 (row_slots :173-178, record_slots :180-182).
- selene/src/memory.rs :1333-1367 (windows(), the remaining third splitter).
- selene/src/store.rs :185-244 (StoreStats, "Counters every store maintains").
- selene/src/pool/pins.rs :165-183 (FileSpan {path, header} — closest existing pair type).
- selene/src/input.rs :80-152 (Budget::progress, precedent for a rate/progress signal outside the event enum).
- selene/src/disk.rs :309/:321/:437 (cfg(any(test, feature="test-support")) precedent) — verified via search; the PR now follows it at disk_store.rs:200-208.
- Rules: docs/design-review.md:74; .agents/skills/repo-prose/SKILL.md:71, :84; AGENTS.md:52-60, :72-140, :188-193; charter lines 9, 24, 35, 42-43, 54.
NOT read: the ~5,300 lines of test module in disk_store.rs :5100-9358 in full — I read the NEW test helpers and fixtures (:6341-6350 settled, :8092-8125 GatedCopier, :8136ff write_shared_ancestor_tree, :8172ff poll_all_fetches) and grepped every assertion that touches constructs I review (settled() at :6466-9309, coalesced_windows/disk_opens/disk_window_reads). No test-only construct outside those greps is claimed about.
#15 [medium] Description-vs-code accuracy for the five "What" bullets
AGENTS.md:72-140 makes PR-description accuracy a repository requirement ("The claimed benefit must be clear before presenting the supporting test and benchmark details"; "State what remains untested"). Lens C includes conventions, so I checked the description's five "What" bullets against the code. Four of five are accurate; one overstates.
ACCURATE (verified at 0c04b1e2):
- "Separate host and GPU read paths": yes —
plan_windows(segments, align_to_window)(:679-727),read_intopasses false (:1349),fetchpasses true (:2438-2442);HostInbound/HostWindowvsDeviceInbound/SharedWindow; oneSharedSegmentperSegmentKey(:1428) and oneSharedWindowperWindowKeywithwindow_index(:1229). - "Reference-counted windows and demand indexing":
has_window_credit(:1683),attach_pending(:1711),followers/disk_referenced/upload_referenced(:1144-1149),build_pending_demandshort-circuitdevice_inbound.len() <= 1(:1736-1738), last segment user waits for close beforeFetched(:2244-2270). - "Physical inbound_rate and logical bytes_in":
applyobserves at :3632-3634 and returns beforestats.progress += 1(:3636) and before theFetchedarm (:3652-3671, where the pre-existinginbound_rate.observewas removed); rank-0 forwarding shard.rs:722-724, peer skip :1148-1150. Accurate as behaviour. - "Failure isolation": private child / upload failure fails one record (
record.fail:1211), shared open/read fails all attached (fail_segment_users:1509,fail_window:1538). Accurate. - "Gates diagnostic counters under cfg(any(test, feature = "test-support"))": accurate — :200-208, and the per-window
disk_read_countedat :742/:1139 with increments :1705, :1973.
OVERSTATED: "No core re-export or format change is required." True for re-exports (crate lib.rs re-exports nothing for TransportEvent — verified by search). But TransportEvent is a public enum in a public module and gains a variant (:97-101), and shard.rs's Kind::of has to panic on it (:476-478). So the description should say the enum gained a variant that is rank-0-local rather than implying no public surface changed — that is what forced the two unreachable!()s I file as should-fix #2.
Also worth noting for the report: the description's benchmark table is labelled at 0c04b1e2 (head) with means over 2 interleaved repeats and --max-concurrency/--prefix-cache-disk-limit stated, and "Not covered" lists multi-host RoCE, 2-GPU split_pools, discrete PCIe, Windows serving, live CompositeStore/PooledStore — that satisfies AGENTS.md:103-112 on evidence scope; I am not filing a description finding on the benchmark, only on the "no format change" phrasing above.
#7 [low] Nit: repeated window-index removal and follower-detach closures
Three small repeated bodies in the new shared-window code; each is a place where a later fix must be applied three times or can diverge.
-
"Unindex this window if the index still points at it" — identical 3-line body, three times: selene/src/disk_store.rs:1525-1527 (
fail_segment_users), :1543-1545 (fail_window), :1837-1839 (sweep_shared_windows): if self.window_index.get(&win.key) == Some(&win_id) { self.window_index.remove(&win.key); } The== Some(&id)comparison is the subtle part (it protects a newer window that reused the key). Extractfn unindex_window(&mut self, key: &WindowKey, id: SharedWindowId)so the staleness rule is stated once. Precedent in the same file:SharedSegment::settled/reusable(:1097-1110) are small named predicates rather than inline conditions. -
"Detach this follower from its window" — identical retain closure, twice: :1813-1816 (
detach_unwinding_windows) and :1900-1904 (Pass 1): win.followers.retain(|f| !(f.record == id && f.plan_index == active.plan_index)); The(record, plan_index)pair is the follower identity (WindowFollower, :1119-1123) and appears again at :1690-1695 when pushing. GiveWindowFollowerafn matches(&self, other: &&Self)/fn remove(win, follower)so the identity is one definition. -
Byte accumulation with a follower detach, twice: :1900-1905 (Pass 1) and the same shape inside
detach_unwinding_windows—record.bytes += win.read_bytesonly happens in Pass 1 (:1901), so a follower detached bydetach_unwinding_windowsfor a failed record does not credit bytes (correct, since it errors), but the two paths differ only by that line and by theupload_busy/disk_referencedguard. Worth a comment saying the detach paths differ deliberately in byte crediting.
Severity: nit (readability/duplication), not behaviour. No evidence of current divergence — all three copies are identical at head.
#8 [low] Nit: close() still reports non-jobs as "disk transport jobs"; two settled() predicates
Verified at head 0c04b1e2.
selene/src/disk_store.rs:2513-2544. The rewritten abandoned count no longer matches the message:
let store_jobs = self.outbound.len() + self.host_inbound.len()
+ self.device_inbound.len() + maintenance_jobs;
let internal = self.owners.len().max(self.maintenance.len())
.max(self.shared_segments.len()).max(self.shared_windows.len());
let abandoned = store_jobs.max(internal);
... return Err(invalid(format!("{abandoned} disk transport jobs did not complete within {:?}", copier::CLOSE_TIMEOUT)));
internalcountsshared_segmentsandshared_windows, which are map sizes, not jobs; a single leaked shared window in a store with no in-flight jobs yieldsabandoned == 1and the message claims one disk transport job did not complete..max()means the number reported can under-report: with 4 abandoned outbound jobs and 6 leaked windows it says 6.
This is diagnostics only (surfaced on shutdown / a CI close failure) and the previous code counted owners.len() (owned disk jobs) — but .max() also means maintenance_jobs double-counts, since maintenance jobs are also in owners. Before the change the number was owners.len(), i.e. one job per map entry.
Fix: count what the message claims — self.owners.len() (one disk job per owner, which is what "disk transport jobs" means) — and, if the intent is to catch leaked staging state, report it separately: if !self.shared_windows.is_empty() || !self.shared_segments.is_empty() { ... "{\} shared windows/segments leaked" }. That way each message is literally true.
Related nit confirmed still present: Segment::settled (disk_store.rs:662-664) and SharedSegment::settled (:1106-1109) are two different predicates with the same name in the same file — the first is about one file handle of one host/device segment, the second about a shared segment's disk jobs having drained. Rename one (file_settled / drained) so a reader is not misled about which lifetime is being tested. Both are used (Segment::settled at :882, :987; SharedSegment::settled at :2250, :2266, :2283).
#10 [low] Nit: GatedCopier 4-tuple sits inline beside testing.rs fixture precedent
Verified at head 0c04b1e2.
selene/src/disk_store.rs:8092-8122 — GatedCopier::wrap returns GatedCopierParts, a positional 4-tuple type alias:
type GatedCopierParts = (SharedCopier, Arc<Mutex<bool>>,
Arc<Mutex<VecDeque<copier::Reply>>>, Arc<Mutex<Option<JobId>>>);
fn wrap(inner: SharedCopier, layout: Layout, hold_in: bool) -> GatedCopierParts
Every call site destructures positionally, and 3 of the 5 discard the last two with _: disk_store.rs:8406 let (copier, hold_in, held_in, _), :8530 same, :8650 let (copier, _, _, fail_job), :8984 let (copier, hold_in, held_in, _), :9234 GatedCopier::wrap(inner, layout.clone(), staggered).
Precedent for the alternative: selene/src/testing.rs's SimulatedGpu returns a 2-element pair from shared_mapped/shared (:225ff), and StoppedCopier (:178) is a named type like this one. A named struct GatedHandles { copier, hold: Arc<Mutex<bool>>, held: Arc<Mutex<VecDeque<..>>>, fail: Arc<Mutex<Option<JobId>>> } with named fields makes each call site say which handle it wants ("give me fail") rather than counting positions, and adding a fifth gate would not renumber every site.
Also: GatedCopier is the only test fixture in this module that gates async ordering, and it is used by 5 tests; if it is ever needed by composite.rs tests (which also drive copier::Jobs) it belongs beside StoppedCopier in selene/src/testing.rs. Severity: nit — test-only, no production impact.
Not re-reporting: ReverseWindows misplacement (it is in the same test module and is minimal); the repeated store-construction block in the coalescing tests is now justified by write_shared_ancestor_tree (:8136ff) and poll_all_fetches helpers, and the remaining per-test differences are the pool sizes and copier wiring, which genuinely vary.
#11 [low] Nit: §2.4 bullet too long, and the metrics contract is stated twice
Verified at head 0c04b1e2.
docs/prefix-cache-offload.md:337-366 — the §2.4 bullet added by this PR is a single 30-line, ~250-word block: it starts at ":337 write_from(id, header, temporary, path, pages, row, sums) and ends at :366 estimates. It carries nine distinct facts (signatures, shared handle, alignment, slot lifetime, read_into isolation, immutability+pin invariant, close-before-Fetched, demand scheduling, reuse limits, extra-partial-window cost, failure-isolation scope, bytes_in vs inbound_rate).
.agents/skills/repo-prose/SKILL.md:84 — "Use ordinary readable sentences." :71 — "if understanding any sentence requires 'you had to be there,'" it fails. The content is now complete and accurate (good — my earlier finding about the missing immutability invariant is resolved), but the block is the largest single bullet in the section and mixes the mechanism (handle sharing, alignment), the correctness condition (immutability + pin), the scheduling heuristic (demand preference), and two metrics contracts in one paragraph.
Also: this bullet sits between store/fetch (the transport contract) and the following line ":367 Section 2.6 specifies a second transport, Direct, which is not implemented." The bytes_in vs inbound_rate sentences are measured-instrumentation facts and are ALSO now duplicated at :1528-1531 (§4 measurement table). Two homes for one contract is the duplication lens's concern: the §4 copy is the one a person reading the measurement table needs; the §2.4 copy belongs with the transport contract only if it constrains behavior (it does — admission pricing uses inbound_rate).
Fix: split the bullet — mechanism + invariant + limits keep §2.4; the two-metric contract stays in §4 with a pointer from §2.4 (StoreStats.bytes_in is logical and inbound_rate physical; see §4). Severity: nit.
AGENTS.md:52-60 is the governing rule ("Every repository document has one or both of two purposes: it specifies the architecture, or it instructs agents..."), and AGENTS.md:57-58 says record unrun checks in docs/TODO.txt rather than design docs — the PR correctly does not put benchmark caveats in the doc.