Conventions scratchpad · NVIDIA/hyperflare-inference #496

Raw Markdown for agents: https://autobot.eidonix.com/p/dae87028-3c73-41e8-ba48-baa86103df12.md

#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:

  1. Should fix — plan_aligned_windows (selene/src/disk_store.rs:700) duplicates plan_windows (:672) almost line for line: same signature, same WindowPlan output, same zero-page/row-only handling, differing only in that the chunk end is clamped to the next WINDOW_PAGES boundary. selene/src/memory.rs:1336 windows() is a third copy of the same splitter. One function with an alignment mode (or a first-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.

  2. Should fix — the shared-window identity tuple (path, expected Header, first, count, row) is re-expressed four times without a shared type: segment lookup by path+expected (:1368), SharedWindow field match in find_reusable_window (:1578), the demand-table key plus inner Vec<(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 single WindowKey (with the Header reduced to a comparable digest, since shared::record::Header derives PartialEq but not Hash) would make the identity definition one thing and let the demand map and window lookup share it.

  3. Should fix — per-pump allocation in the poll loop: build_pending_demand clones a PathBuf per pending plan and per bucket push (:1668), and pick_next_pending_plan (:1710) plus the two decrement blocks (:1890, :1996) clone seg_ref.path again on every lookup. That is a heap allocation per plan per pump_device_inbound call in steady-state serving, which the PR body itself acknowledges as new cost for existing users. find_reusable_window also scans every shared_windows value for every pending plan of every record (Passes 2 and 4). An index from WindowKey to SharedWindowId, alongside the pending_page_reads map the PR already added, removes both the clones and the quadratic scan.

  4. Nit — GatedCopier (:8051) and ReverseWindows (:7732) are test copiers defined inside disk_store.rs's test module, and GatedCopier::wrap returns the positional 4-tuple GatedCopierParts (:8059) of Arc<Mutex<...>> handles. The established fixture precedent is selene/src/testing.rs (StoppedCopier :178, SimulatedGpu :225 with shared_mapped/shared constructors returning a two-element pair). If GatedCopier is 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_tree and poll_all_fetches already exist as fixture helpers and a matching store_for_fixture would remove that repetition.

  5. Nit — the new counters (disk_opens, disk_window_reads, coalesced_windows, :192–200) are unconditional Resources fields 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:309 keep faults under #[cfg(any(test, feature = "test-support"))]. Gating the three fields the same way removes the three allow(dead_code) attributes and the counter increments from release builds. Separately, the crate's stated home for counters is StoreStats (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.

  6. Nit — Staged::close (:2485–2489) now computes abandoned as the sum of outbound/host_inbound/device_inbound/maintenance lengths, .max(usize::from(self.busy())), but busy() also counts shared_segments and shared_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.

  7. Nit — naming axis mixing in the new types: the record split is HostInbound (:759) / DeviceInbound (:1117), but the window split is HostWindow (:746) / SharedWindow (:1070), and the phase enums HostInPhase / SharedWindowPhase. The host path's counterpart of SharedWindow is named by the other axis, so a reader pairing the two paths has to check both. PrivateWindow/SharedWindow or HostWindow/DeviceWindow would keep one axis.

  8. 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

  1. 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.

  2. 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.

  3. 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.

  4. 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.

  5. 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 faults member. 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.

  6. 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().

  7. 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.

  8. 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

#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:

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):

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:

  1. disk_store.rs:1001-1050 — HeaderIdentity hand-writes Hash over 14 Header fields in a destructure ending in .. (:1030), mirroring impl PartialEq for Header at shared/record.rs:136-152 in another module. The only hand-written Hash in selene/src. A field added to Header breaks the compile in record.rs but silently drops out of the hash here → equal headers hash differently → window_index misses → coalescing silently stops. Fix: move Hash beside PartialEq in shared/record.rs, or key on an existing digest.
  2. disk_store.rs:97-101 + 3632-3638, shard.rs:476-478, composite.rs:1376 — TransportEvent::InboundWindowSample is a rate sample in an enum documented as "Completion ... reports" (:83). Every consumer special-cases it: two unreachable!() (disk_store.rs:3638, shard.rs:477) guarded by two skip checks that must stay in sync (shard.rs:722-724, :1148-1150); the wire Kind (shard.rs:441-464) has no code for it. Concrete cost: CompositeStore bumps self.stats.progress for every transport event (composite.rs:1376), that progress surfaces in CompositeStore::stats() (:1482) and gates maintenance (:1418-1424), so each physical window read re-runs spill_parked + disk.maintain(). Fix: carry the sample out-of-band (a drain method or a field on Fetched), precedent Budget::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).
  3. disk_store.rs:1766-1777 — pick_next_pending_plan recomputes slots as plan.count + if plan.row { row_slots } else { 0 } where Layout::record_slots (geometry.rs:180-182) already does it, and takes the transfers mutex per candidate plan. Resources::allocate (:243-254) uses record_slots, so the needed > free guard 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.

#17 [high] Correction at head 0c04b1e2: HeaderIdentity's .. fails safe (collisions, not broken coalescing)

CORRECTION to entry #16 finding 1 and entry #4.

At head 0c04b1e2 the omission is already live, not hypothetical: Header at selene/src/shared/record.rs:116-134 has no packed field, but main (post-#504, commit 716df00f) added pub packed: Option<Arc<packed::Layout>> at main's shared/record.rs:127 and included it in impl PartialEq for Header at main:146. HeaderIdentity::hash (disk_store.rs:1014-1050) destructures with .. at :1030 and hashes 14 fields, so packed is not hashed.

Direction of the error matters, and I had it wrong:

So the finding stands but must be re-framed: HeaderIdentity is the only hand-written Hash in selene/src (grep impl (std::hash::)?Hash for → disk_store.rs:1014 alone), while the crate derives instead (PrefixKey vocab.rs:30, SegmentKey/WindowKey disk_store.rs:1052/1058, levels.rs:9, plan.rs:22, store.rs:17/115, shard.rs:441, slab.rs:36). It duplicates Header's equality contract from another module and needs maintenance on every Header field change with no compiler help. The fix is unchanged and still cheap: give Header a Hash (next to its PartialEq at record.rs:136-154) that mirrors the field list, or hash the canonical form already used by shard::shape (selene/src/shard.rs:1242-1249, header.canonical_encoding()), and add an a == b ⇒ hash(a) == hash(b) test. Severity stays should-fix on conventions grounds (single hand-written Hash, cross-module contract duplication); drop the "coalescing stops with no test failure" sentence from the report — that claim is not supportable.

Everything else in entry #16 was re-verified at the same head commit and is unchanged: no new commits since (PR head still 0c04b1e2), InboundWindowSample still at disk_store.rs:97-101 with unreachable!() at shard.rs:476-478 and the two guards at shard.rs:722-725 / :1148-1150; CompositeStore::poll still bumps stats.progress for every transport event at composite.rs:1376 ahead of the maintenance gate at :1418-1429; pick_next_pending_plan still recomputes plan.count + row*row_slots at disk_store.rs:1777 where Layout::record_slots (geometry.rs:180-182) exists and is what Resources::allocate uses (disk_store.rs:245); memory.rs::windows() (memory.rs:1336-1367) is still the third splitter beside plan_windows (disk_store.rs:682-727); Staged::close still reports the .max() chain (:2522-2545) as "disk transport jobs".

#18 [high] Research summary

Re-reviewed PR #496 (head 0c04b1e2, unchanged — no new commits since my last report) through the conventions-and-duplication lens, re-verifying every prior finding against the code and correcting one. The verdict is unchanged: no blockers, three should-fix findings, six nits; the full report is my scratchpad entry #16, with the correction recorded as entry #17.

The correction matters. My previous report said that HeaderIdentity's hand-written Hash (selene/src/disk_store.rs:1014-1050, .. rest-pattern at :1030) would make coalescing "silently stop" if a Header field were added. That is the wrong direction: because Header's PartialEq (selene/src/shared/record.rs:136-152) enumerates every field while the hash omits any new one, the a == b ⇒ hash(a) == hash(b) implication still holds and the only effect is extra hash collisions in window_index — the unsafe direction is the reverse (a hashed-but-not-compared field such as the private version). And the omission is not hypothetical: main has already grown packed: Option<Arc<packed::Layout>> on Header (main's shared/record.rs:127, compared at :146) after this branch, so the .. is dropping a real field today. The finding survives as a conventions issue — it is the only hand-written Hash in selene/src while every other key type derives (PrefixKey vocab.rs:30 (not opened), SegmentKey/WindowKey disk_store.rs:1052/1058), and it duplicates a contract owned 1,200 lines away in another module — with the same fix: put Hash beside Header's PartialEq (or hash canonical_encoding, as shard::shape at shard.rs:1242-1249 does) and add an equal-implies-equal-hash test.

The other two should-fix findings re-verified unchanged: TransportEvent::InboundWindowSample (disk_store.rs:97-101) is a rate sample inside an enum documented as completions (:83), forcing unreachable!() at shard.rs:476-478 plus two hand-written guards (:722-725, :1148-1150), and it makes CompositeStore::poll bump stats.progress per physical window (composite.rs:1376) ahead of the maintenance gate (:1418-1429); and pick_next_pending_plan recomputes plan.count + row*row_slots by hand (:1777) where Layout::record_slots (geometry.rs:180-182) is already what the allocator it guards uses (disk_store.rs:245). Nits stand as before — the surviving third WINDOW_PAGES splitter in memory.rs::windows (memory.rs:1336-1367), Staged::close's .max() chain reported as "disk transport jobs" (:2522-2545), duplicate settled() predicates, three repeated unindex blocks and two repeated follower-detach closures, the positional GatedCopier 4-tuple, and the 250-word §2.4 bullet that states the bytes_in/inbound_rate contract a second time (§4, docs:1528-1531). No toolchain or GPU here, so nothing was compiled or run.

#19 [high] FINAL corrected report — PR #496 lens C (conventions & duplication), head 0c04b1e2

Review of PR #496 — lens: conventions and duplication (FINAL, corrected)

Head 0c04b1e2, base main c0c4f798. No new commits since the previous round. Changed files: selene/src/disk_store.rs (+3313/−931), selene/src/shard.rs (+10/−0), docs/prefix-cache-offload.md (+35/−2). Case file: https://autobot.eidonix.com/api/v1/cases/774e16ea-5f84-4ff8-9166-74ab6876cc37.html

Verdict: should-fix only. No blockers. This supersedes entry #16, whose finding 1 stated the wrong failure mode (see "Correction" below). Per-finding detail: #4–#11; resolved/sound ledger: #9; coverage ledger: #14; description accuracy: #15; correction: #17.

Rules applied: charter line 9 ("Solve the right problem in the right place… smallest footprint in shared code"), lines 24, 35, 42-43; AGENTS.md:52-60 (one purpose per document), :72-140 (why/what/benefit/evidence, untested scope), :188-193 (reject unsupported abstractions and churn — "Refactoring must directly support the requested behavior or remove a demonstrated source of defect or cost"), :201-207 (maintainer decision required for an architectural invariant); docs/design-review.md:74 ("account for duplicate representations"); .agents/skills/repo-prose/SKILL.md:71, :84 (ordinary readable sentences). No toolchain or GPU was available: nothing was compiled or run; every finding is established from source.

Correction to the previous round

My earlier report claimed HeaderIdentity's .. rest-pattern means "a new Header field silently drops out of the hash and coalescing stops with no test failure". Wrong direction, and worth stating precisely:

So finding 1 stands as a conventions/robustness issue, not as a correctness bug.

Should fix

1. The only hand-written Hash in selene/src, mirroring an equality contract owned in another module

File: selene/src/disk_store.rs:1001-1050 (impl :1014-1050; .. at :1030). Precedent: selene/src/shared/record.rs:136-154 (impl PartialEq for Header exhaustive, impl Eq); derives everywhere else — PrefixKey (vocab.rs:30), SharedSegmentId/SharedWindowId (:995/:998), SegmentKey (:1052), WindowKey (:1058), levels.rs:9, plan.rs:22, store.rs:17/:115, shard.rs:441, slab.rs:36, pool/types.rs:12. Grep impl (std::hash::)?Hash for over selene/src returns exactly this one hit. HeaderIdentity(Arc<Header>) implements PartialEq by delegation (:1006-1010) then hashes ten-plus-four fields by hand. Adding or reclassifying a Header field is a compile error in record.rs and silent here; the .. makes the omission invisible in review. Fix: implement Hash next to Header's PartialEq in shared/record.rs (or hash the canonical encoding already used by shard::shape, shard.rs:1242-1249 via Header::canonical_encoding, record.rs:260/348) and add a test that equal headers hash equally.

2. A rate sample placed in the cross-rank completion enum

File: selene/src/disk_store.rs:83 ("Completion the transport reports to the disk store"), variant :97-101. Consumers that must special-case it: Kind::of shard.rs:476-478 (unreachable!), absorb_local shard.rs:722-725 and Peer::forward shard.rs:1148-1150 (skip guards that must stay in sync), DiskStore::apply disk_store.rs:3632-3638 (early return plus a second unreachable! arm), CompositeStore::poll composite.rs:1376 bumping stats.progress for every event before the maintenance gate at :1418-1429 (spill_parked + disk.maintain()). Precedent for out-of-band progress/rate signalling in the same crate: Budget::progress / DiskBudget::progress (selene/src/input.rs:80-81, :146-148) and StoreStats.progress (store.rs:201-202) — a counter read by the owner, not a variant of a completion enum. Fix: drain the sample from Staged directly (a take_window_samples() beside take_packed_read-style accessors, cf. Staged::take_packed_read) or carry it on Fetched. Also makes the maintenance pass per physical window disappear.

3. Hand-rolled slot arithmetic where Layout::record_slots exists

File: selene/src/disk_store.rs:1766-1777 (needed = plan.count + if plan.row { layout_row_slots } else { 0 }). Precedent: selene/src/geometry.rs:180-182 record_slots(pages, row); used by the allocator this guard predicts — Resources::allocate disk_store.rs:245 — and at disk_store.rs:6403/6618/7531/7626/7701, composite.rs:810/1167, memory.rs:468/1856/3883/4064. Fix: hoist lock(&self.resources.transfers).layout() once beside free and call layout.record_slots(plan.count, plan.row); that also removes the per-candidate-plan mutex acquisition.

Nits

Checked and sound (not findings)

Description accuracy (AGENTS.md:72-140)

Four of five "What" bullets match the code. "No core re-export or format change is required" overstates: TransportEvent is a public enum that gains a variant (:97-101), which is what forces the unreachable!() at shard.rs:476-478. The benchmark table is labelled at head with repeats and concurrency settings, and "Not covered" lists multi-host RoCE, 2-GPU split_pools, discrete PCIe, Windows serving and live CompositeStore/PooledStore — that satisfies AGENTS.md:103-112.

Open questions / what would settle them

#21 [high] Research summary

Verdict on PR #496 at head cb3db468 (rebased onto main 6d74db3a), lens C (conventions and duplication): should-fix issues only, no blockers.

The rebase resolved everything my earlier rounds raised on this lens, and the author's reply documents each fix. Verified in the code at this head: Header's Hash now lives beside its PartialEq in selene/src/shared/record.rs:165-202 with an exhaustive destructure (version: _) matching PartialEq's omission of encoding version, plus an a == b ⇒ hash(a) == hash(b) test (header_eq_implies_same_hash, record.rs:2228-2303) covering raw and v4 packed headers; HeaderIdentity now delegates (disk_store.rs:1452-1456); packed::Layout has Eq/Hash with exhaustive destructures over Layout, PackedOffer and PackedUnit (shared/packed.rs:99-141) and RankSizes derives Hash (record.rs:96). TransportEvent::InboundWindowSample is gone — samples are buffered in Staged::inbound_samples (disk_store.rs:1663), drained through the defaulted DiskTransport::drain_inbound_samples (disk_store.rs:150, :3165; Sharded shard.rs:1005-1012; peers discard shard.rs:1213-1214) and observed by DiskStore::observe_inbound_samples (:3649-3655, called from poll_transport, poll, close), so TransportEvent is back to six completion variants and CompositeStore's progress count is unaffected. pick_next_pending_plan now hoists the transfers lock once and calls layout.record_slots(plan.count, plan.row) (disk_store.rs:2306-2322), the helper Resources::allocate uses (:254; geometry.rs:209-211). Staged::close reports abandoned_jobs and leaked_shared separately (:3192-3225), GatedCopier::wrap returns a named GatedCopierHandles struct (:9252-9282), §2.4 is split into three sub-bullets with the metrics contract left only in §4 (docs/prefix-cache-offload.md:428-448, :1612-1618), and the diagnostic counters stay cfg-gated (:1205-1213, :2513-2516).

What remains on this lens is one nit, recorded in the scratchpad: selene/src/memory.rs:1834-1867 is now the last surviving hand-written WINDOW_PAGES splitter (the disk side's two copies were unified into plan_windows(…, align_to_window) at disk_store.rs:1028-1073), so the same "chunks of WINDOW_PAGES, row on the last window, row-only window, empty link none" policy lives in two unrelated functions; a third sibling, packed::Layout::windows, is deliberately different (byte-bounded, packed payload) and carries a max argument this one does not, so the cleanup is a comment or a shared helper, not a merge. Beyond that I found no new construction that duplicates an existing helper or departs from a crate precedent: SegmentKey/WindowKey derive Hash like every other key type (disk_store.rs:1458-1470), is_packed_content_error/with_record_read reuse error.rs:56-69's existing record-read marking rather than adding a parallel error style, the packed-window byte-range arithmetic in submit_reads (:1331-1345) and pump_device_inbound (:2650-2667) mirrors the pre-existing pair in pool/pins.rs:338-351 (both derived from Layout::page_offset/physical_bytes, not a new abstraction), and Staged's out-of-band sample drain follows the existing take_packed_read/take_evicted accessor shape rather than adding an enum variant.

Two limits worth stating with the report: no toolchain or GPU was available to me, so nothing was compiled or run — every finding is established from source at cb3db468 — and the ~5,600-line test module (disk_store.rs:9200-10857) was read only where a reviewed construct appears (the coalescing, packed-coalescing and rate tests at :10288-10857, and the GatedCopier fixture). Description accuracy against AGENTS.md:72-140 now holds on all five "What" bullets, including the corrected statement that no TransportEvent variant was added.

Full per-finding detail, the resolved ledger and the coverage list are in scratchpad entries #2, #19 and #20; this round's verification is in the notes recorded above.

#22 [high] FINAL report — PR #496 lens C at head cb3db468 (rebased onto main 6d74db3a)

Review of PR #496 — lens: conventions and duplication (FINAL, head cb3db468)

Head cb3db468 (rebased onto main 6d74db3a, post-#504), base main. Changed files (pr_files): docs/prefix-cache-offload.md (+38/−2), selene/src/disk_store.rs (+8470/−5627), selene/src/shard.rs (+11/−0), selene/src/shared/packed.rs (+44/−0), selene/src/shared/record.rs (+119/−1). No CI checks on head; no toolchain/GPU available to me, so nothing compiled or run — everything below is established from source at this head.

Verdict: should-fix issues only (now zero should-fix). No blockers.

One nit remains. Every item my earlier rounds raised on this lens is resolved at this head; verified individually, not taken from the author's reply.

Resolved and verified at cb3db468 (citations)

  1. Header hash beside equality: impl Hash for Header record.rs:165-202, exhaustive destructure with version: _ (matches PartialEq record.rs:144-161 which also omits version); impl Eq for Header :163. RankSizes derives Hash :96. packed::Layout Eq/Hash with exhaustive destructures over Layout, PackedOffer, PackedUnit shared/packed.rs:99-141. HeaderIdentity delegates to Header::hash with Arc::ptr_eq fast path retained on PartialEq: disk_store.rs:1444-1456. Test header_eq_implies_same_hash record.rs:2228-2303 covers raw and v4 packed headers, version swap equality, and created/packed inequality.
  2. Rate sample out of the completion enum: no InboundWindowSample variant remains; TransportEvent (disk_store.rs:84-106) is six completion variants again, each with a JobId. Staged.inbound_samples: Vec<(u64, Duration)> :1662-1663, pushed in apply_shared_disk :2148-2150, drained by DiskTransport::drain_inbound_samples (defaulted no-op :150; Staged :3165-3167), forwarded on rank 0 in Sharded shard.rs:1005-1012 (poison → discard) and discarded per peer in Peer::forward shard.rs:1211-1214. DiskStore::observe_inbound_samples :3649-3655 → poll_transport :3659-3664, poll :4640, close :4678. stats.progress untouched by samples.
  3. Layout::record_slots in the admission guard: pick_next_pending_plan :2299-2331 hoists let transfers = lock(&self.resources.transfers); let layout = transfers.layout(); once (:2307-2308) and uses layout.record_slots(plan.count, plan.row) > free (:2320); helper at geometry.rs:209-211, same one Resources::allocate uses (disk_store.rs:254).
  4. Staged::close reports abandoned_jobs (:3192-3194, message :3214-3219) and leaked_shared (:3195, message :3220-3225) separately.
  5. GatedCopier::wrap returns a named GatedCopierHandles struct (:9252-9282) instead of the positional 4-tuple; call sites :9592, :9715, :9834, :10168, :10421, :10800.
  6. Docs split: §2.4 now three sub-bullets (mechanism docs/prefix-cache-offload.md:428-437; invariant/pin :438-443; limits and failure scope :444-448 pointing at §4); the bytes_in/inbound_rate/CompositeStore.disk_inbound_rate contract appears once, at :1612-1618.
  7. Diagnostic counters disk_opens/disk_window_reads/coalesced_windows remain #[cfg(any(test, feature = "test-support"))] (:1205-1213, increments :2513-2516, :2244-2247, :2689-2693, :2725-2729, :2753-2757).

Remaining nit (only finding)

Nit — selene/src/memory.rs:1834-1867 is now the last hand-written WINDOW_PAGES splitter. The PR unified the disk side's two copies into plan_windows(segments, align_to_window) (disk_store.rs:1028-1073), but memory::windows still encodes the same policy independently (chunks of WINDOW_PAGES, row on the last window, row-only window when there are no pages, empty link none). Precedent showing the crate prefers one splitter: plan_windows's own doc comment (:1025-1027) explains the two-mode split, i.e. the disk side deliberately merged rather than copied. Note packed::Layout::windows (shared/packed.rs:154-185) is a different splitter (byte-bounded, max argument, packed payload) and should not be merged. Fix: a one-line cross-reference comment in memory::windows pointing at plan_windows, or lift the policy into one helper taking the align flag. Cosmetic; no behaviour risk.

Checked and sound (not findings)

Limits of this review

Rules applied: charter line 9 (smallest footprint in shared code; good ideas in the wrong place are declined), lines 24 (checkpoints in host memory via Selene), 35 (what gets merged), 42-43 (design review covers conventions/duplication; no per-model flags); AGENTS.md:52-60 (one purpose per document), :72-140 (why/what/result/evidence), :188-193 (reject unsupported abstractions and churn; refactoring must support the requested behaviour), :201-207 (maintainer decision for architectural invariants).

#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):

READ FOR PRECEDENT / RULES (not changed by the PR):

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):

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.

  1. "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). Extract fn 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.

  2. "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. Give WindowFollower a fn matches(&self, other: &&Self) / fn remove(win, follower) so the identity is one definition.

  3. Byte accumulation with a follower detach, twice: :1900-1905 (Pass 1) and the same shape inside detach_unwinding_windows — record.bytes += win.read_bytes only happens in Pass 1 (:1901), so a follower detached by detach_unwinding_windows for a failed record does not credit bytes (correct, since it errors), but the two paths differ only by that line and by the upload_busy/disk_referenced guard. 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)));

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.