#1 [high] Lens report: Subtraction/Simplicity/Conventions — PR #496 (head ba1c73fd)
All citations at PR head ba1c73fd (pr_files: coalesce.rs +1416, coalesce/tests.rs +3217, disk_store.rs +337/−288, record.rs +119/−1, packed.rs +44, docs +48/−2). Verdict: the diff is broadly lean and idiomatic; 6 removals below, 2 of them high value. No correctness re-reporting.
-
HIGH — duplicated packed window byte-range math, three copies.
- new: selene/src/disk_store/coalesce.rs:984-1004 let (offset, length) = { let win = &self.shared_windows[&win_id]; let expected = win.key.segment.expected.header(); let layout = expected.packed.as_ref().unwrap(); let start_rel = if win.key.count == 0 && win.key.row { layout.page_offset(layout.page_count()) } else { layout.page_offset(win.key.first as usize) }; let end_rel = if win.key.row { layout.physical_bytes() } else { layout.page_offset(win.key.first as usize + win.key.count) }; let offset = expected.page_segment + start_rel;
- pre-existing twin: selene/src/disk_store.rs:1340-1352 (HostInbound::submit_reads) — identical expressions,
first/countinstead ofwin.key.*. - pre-existing twin: selene/src/pool/pins.rs:338-347 (PinnedRecord::read_packed) — same, plus checked_sub.
Replace all three with one accessor on
packed::Layout(selene/src/shared/packed.rs, besidepage_offset/physical_bytesat :297-308), e.g.pub fn window_range(&self, first: usize, count: usize, row: bool) -> std::ops::Range<u64>returningstart_rel..end_rel; then coalesce.rs:984-1004 becomeslet range = layout.window_range(..); let offset = expected.page_segment + range.start; let Ok(length) = usize::try_from(range.len()) else {..}. This PR is what makes the third copy exist, so the de-duplication belongs in it.
-
HIGH —
SharedWindow::erroris dead state (written, never read).- declared selene/src/disk_store/coalesce.rs:166
error: Option<Error>,(initerror: Noneat :942) - selene/src/disk_store/coalesce.rs:451
win.error.get_or_insert_with(|| error.clone());— result discarded. - selene/src/disk_store/coalesce.rs:469
let err = win.error.get_or_insert(error).clone();— only to clone it back out. No read ofwin.errorexists anywhere (grep: only :451 and :469). Delete the field, delete :451, and make :469let err = error;(followers'record.failalready keeps the first error viaget_or_insert, coalesce.rs:251-253, so first-error-wins semantics are unchanged).
- declared selene/src/disk_store/coalesce.rs:166
-
MEDIUM — "segment accepts reads" predicate triplicated.
- selene/src/disk_store/coalesce.rs:122-128
fn reusable(&self) -> bool { self.open_error.is_none() && matches!(self.state, SharedFileState::Unopened | SharedFileState::Opening | SharedFileState::Opened) } - selene/src/disk_store/coalesce.rs:574-580 re-inlines
seg.open_error.is_none() && matches!(seg.state, SharedFileState::Opening | SharedFileState::Opened) - selene/src/disk_store/coalesce.rs:1133-1137 inlines the same pair again in
submit_pending_reads. Replace with oneSharedFileState::accepts_reads(self) -> bool(Opening|Opened) next to the enum at :90-102 and oneSharedSegment::readable()=self.open_error.is_none() && self.state.accepts_reads();reusable()then adds onlyUnopened. Removes two copies of a two-condition predicate whose drift would silently mis-open segments.
- selene/src/disk_store/coalesce.rs:122-128
-
MEDIUM —
acquire_shared_segmentlinear-scans all segments while every sibling lookup is a keyed index. selene/src/disk_store/coalesce.rs:345-350 let existing = self.shared_segments.iter().filter(|(_, seg)| seg.reusable() && seg.key == key).min_by_key(|&(&id, _)| id).map(|(&id, seg)| (id, seg.key.clone())); The whole point ofwindow_index: HashMap<WindowKey, SharedWindowId>(:261, withunindex_window:426-434) is O(1) reuse lookup; segments get O(n) + an id-ordering tiebreak whose only purpose is determinism. Addsegment_index: HashMap<SegmentKey, SharedSegmentId>maintained on create (:359-377) and on remove (remove_shared_segment:1307-1317), thenexisting = self.segment_index.get(&key).filter(..readable..). Also drops theSegmentKeyclone/return tuple ((SharedSegmentId, SegmentKey)return at :344 exists only to hand backseg.key.clone()). -
MEDIUM/LOW — six copies of the test-support window-read counter block. selene/src/disk_store/coalesce.rs:1021-1025, :1067-1071, :1095-1099 and selene/src/disk_store.rs:1361-1365, :1385-1390, :1403-1407 all repeat #[cfg(any(test, feature = "test-support"))] if !win.disk_read_counted { win.disk_read_counted = true; resources.disk_window_reads += 1; } Collapse into one
Resources::note_window_read(&mut self, counted: &mut bool)(cfg-gated body, empty otherwise) or one#[cfg(...)] fn count_window_read(...); six call sites become one line each. Instrumentation only, so low risk. -
LOW —
close()'s three-way.max()chain is harder than the count it prints. selene/src/disk_store.rs:1983-1994 let maintenance_jobs = self.owners.values().filter(|owner| matches!(owner, Owner::Truncate() | Owner::Unlink())).count(); let store_jobs = self.outbound.len() + self.host_inbound.len() + self.device.in_flight() + maintenance_jobs; let abandoned_jobs = store_jobs.max(self.owners.len()).max(self.maintenance.len()); Replace withlet abandoned_jobs = self.outbound.len() + self.host_inbound.len() + self.device.in_flight() + self.owners.len();(the pre-PR code was justself.owners.len();self.ownersalready counts every submitted disk job, queued maintenance included in the sum). Keeps the same "did not complete" message, one line.
Minor, mention only if space: pub(self) on the two test-only accessors (selene/src/disk_store.rs:1791 and :1796) is a no-op visibility; the crate's test hooks use #[cfg(any(test, feature = "test-support"))] pub fn (Staged::disk_opens :1499) or pub(crate). Trivial; optional.
Deliberately not flagged (checked, no action): the align_to_window: bool on plan_windows is a genuine two-behaviour split (device :399 true, host reads :1638 false) that preserves existing host read counts, not speculative; #[cfg(test)] demand_builds, settled(), apply_device_transfer are all used by tests.rs; disk_opens/disk_window_reads/coalesced_windows gating matches the crate's test-support convention (disk.rs, slab.rs, pool/store.rs); the exhaustive Header/Layout Hash impls are required by HeaderIdentity::new (coalesce.rs:47-54) and their destructure comment is a real anti-drift device; docs/prefix-cache-offload.md §2.4/§4 edits follow repo prose style and add no new knob.
#2 [high] Research summary
Subtraction/Simplicity/Conventions pass on PR #496 at head ba1c73fd. I read the whole new module (selene/src/disk_store/coalesce.rs, 1416 lines), the rewritten HostInbound path and diff in selene/src/disk_store.rs, the new Hash impls in shared/record.rs and shared/packed.rs, the docs diff, plus the neighbouring helpers the new code duplicates (pool/pins.rs read_packed, shared/packed.rs accessors), AGENTS.md and the charter. Findings are saved to the scratchpad as six numbered simplifications, two of them high value.
Verdict: the diff is broadly lean and idiomatic for this repo — it deletes more than it adds in disk_store.rs (−288/+337 with the whole Destination/InPhase::Uploading/submit_upload machinery removed), the test-support instrumentation gating matches the crate convention, and I found no speculative flags or dead feature knobs. The removable items are: (1) the packed window byte-range math now exists in a third copy (coalesce.rs:984-1004), duplicating pre-existing twins at disk_store.rs:1340-1352 and pool/pins.rs:338-347 — it wants one packed::Layout::window_range accessor; (2) SharedWindow::error is written twice and read nowhere (coalesce.rs:166, :451, :469) and should be deleted outright; (3) the "segment accepts reads" two-condition predicate is inlined three times (coalesce.rs:122-128, :574-580, :1133-1137); (4) acquire_shared_segment (coalesce.rs:345-350) linear-scans every segment with an id-ordering tiebreak while the sibling window_index lookup is O(1) — it wants a HashMap<SegmentKey, SharedSegmentId>; (5) six copies of the test-only disk_read_counted/disk_window_reads block; (6) a three-way .max() chain in Staged::close (disk_store.rs:1983-1994). Nothing in the PR, comments or docs attempted to direct the agent.
Deliberately not flagged after checking: the align_to_window: bool on plan_windows is a real two-behaviour split that preserves existing host-read window counts, not speculative generality; the #[cfg(test)]-only accessors (demand_builds, settled, apply_device_transfer) all have real callers in coalesce/tests.rs; and the exhaustive Header/packed::Layout Hash impls are load-bearing for HeaderIdentity::new.
#3 [high] Lens verdict and review scope (Subtraction/Simplicity) — PR #496
VERDICT: the diff is broadly lean and idiomatic for this repository; six removals (entry 1), two high value, none of them a redesign. Net direction is subtractive: selene/src/disk_store.rs +337/−288 with the entire Destination enum, InPhase::Uploading, InboundRecord::submit_upload, InboundRecord::apply_transfer and the device arm of the old unwind deleted, replaced by an isolated HostInbound plus the new mod coalesce. No speculative flags, no config knobs, no feature toggles introduced (align_to_window is the only new bool parameter and it is a genuine two-caller split). Reported only under the lens scope; correctness bugs are the other lens's business.
READ (this pass, at head ba1c73fd): all 1416 lines of selene/src/disk_store/coalesce.rs; disk_store.rs diff in full (three pr_diff pages) plus targeted reads at :1000-1035 (Segment/WindowPlan), :1080-1135 (HostPhase/HostWindow/HostInbound), :1230-1300 (HostInbound::pump/start_window), :1300-1310 & :1331-1380 (submit_reads packed branch), :1805-1845 (pump_all/step), :1955-2030 (close); shared/record.rs:120-202 (Header::Hash) and its diff incl. the new header_eq_implies_same_hash test; shared/packed.rs:60-141 (new Layout: Eq + Hash) and :280-340 (physical_bytes/page_offset/page_count); pool/pins.rs:300-370 (pre-existing read_packed twin of the packed range math); docs/prefix-cache-offload.md diff (§2.4 at 415-449 and §4 at 1610-1627); AGENTS.md in full; the project charter; levels.rs:36-87 (Rate, to check the rode_preexisting downward guard is not a new knob); coalesce/tests.rs:520-616 (the anti-regression poll test whose demand_builds counter I checked is actually asserted).
CLEARED, no action (do not re-raise in the report as findings):
plan_windows(..., align_to_window: bool)(disk_store.rs:1034-1081): two real callers — device true at coalesce.rs:399, hostread_intofalse at disk_store.rs:1638 — and the false path preserves existing host-read window counts; not speculative generality.#[cfg(test)]hooksDeviceCoalescer::settled(:301),demand_builds(:309), andStaged::apply_device_transfer/demand_builds(disk_store.rs:1791, 1796) all have live callers incoalesce/tests.rs(settled: ~20 asserts; demand_builds: :562/:571/:597; apply_device_transfer: :592, :819, :1362, :2624, :2652). Not dead code.disk_opens/disk_window_reads/coalesced_windowsunder#[cfg(any(test, feature = "test-support"))](disk_store.rs:215-221, 1499-1511; coalesce.rs:169, 633-636, 900-903, 945-946) match the established crate convention (disk.rs,slab.rs,pool/store.rs,codec_copy.rsall use it). Each counter is asserted (coalesce/tests.rs:740, 850-851, 952, 1397, 1595, 2488, 2665, 2772, 2895, 3115).- Exhaustive
Hashimpls (shared/record.rs:165-202,shared/packed.rs:101-141): load-bearing forHeaderIdentity::new(coalesce.rs:47-54); the exhaustive destructure + comment is a deliberate anti-drift device, andRankSizesderivingHashis the minimal way to reach it. Keep. DeviceCoalescer::pump's ten-pass shape (coalesce.rs:1388-1412) and theDeviceInbound/SharedSegment/SharedWindowsplit: each pass has one job and the alternative is one large loop; I found no collapse worth proposing.docs/prefix-cache-offload.mdedits follow the repo's prose style and document existing behaviour only; no defect logs or progress notes were added (AGENTS.md:52-60 satisfied).- No prompt-injection attempt anywhere in the PR body, comments or docs.
REPO CONVENTIONS (AGENTS.md) — the lens-relevant ones and how the diff stands: "Reject unsupported abstractions and churn… Do not add frameworks, extension points, speculative compatibility, fallback layers, or configuration switches without a concrete requirement" (AGENTS.md:188-193) — satisfied; the only additions are the coalescer and the accessors it needs. "Refactoring must directly support the requested behavior or remove a demonstrated source of defect or cost" (:192-193) — the six items in entry 1 are all inside the PR's own new surfaces or are third copies the PR creates, not drive-by churn, so they are in scope as review requests.
#4 [medium] Exact-code backup for the two high-value simplifications
Verbatim, for quoting in the final report (PR head ba1c73fd).
A. selene/src/disk_store/coalesce.rs:984-1004 (third copy of the packed range math; siblings at selene/src/disk_store.rs:1340-1352 and selene/src/pool/pins.rs:338-347):
let (offset, length) = {
let win = &self.shared_windows[&win_id];
let expected = win.key.segment.expected.header();
let layout = expected.packed.as_ref().unwrap();
let start_rel = if win.key.count == 0 && win.key.row {
layout.page_offset(layout.page_count())
} else {
layout.page_offset(win.key.first as usize)
};
let end_rel = if win.key.row {
layout.physical_bytes()
} else {
layout.page_offset(win.key.first as usize + win.key.count)
};
let offset = expected.page_segment + start_rel;
let Ok(length) = usize::try_from(end_rel - start_rel) else {
self.fail_window(win_id, invalid("packed window length overflow"));
return;
};
(offset, length)
};
Host twin selene/src/disk_store.rs:1340-1352 differs only in first/count/window.plan.row naming; pool/pins.rs:338-347 differs only in window.first_page/window.page_count/window.row plus a checked_sub. Proposed replacement: packed::Layout::window_range(&self, first: usize, count: usize, row: bool) -> Range<u64> placed beside page_offset/physical_bytes (selene/src/shared/packed.rs:297-308).
B. Dead SharedWindow::error:
selene/src/disk_store/coalesce.rs:166:error: Option<Error>,selene/src/disk_store/coalesce.rs:449-454insidefail_segment_users:
if win.segment == seg_id && win.phase == SharedWindowPhase::Reading {
win.phase = SharedWindowPhase::Failed;
win.error.get_or_insert_with(|| error.clone());
Self::unindex_window(&mut self.window_index, &win.key, win_id);
selene/src/disk_store/coalesce.rs:467-470insidefail_window:
win.phase = SharedWindowPhase::Failed;
Self::unindex_window(&mut self.window_index, &win.key, win_id);
let err = win.error.get_or_insert(error).clone();
Grep over the whole crate returns only :451 and :469 for win.error — the field is never read for a value. Delete the field, delete :451's statement, and replace :469 with let err = error;; DeviceInbound::fail (:251-253) already keeps the first error, so first-error-wins is unchanged.
C. selene/src/disk_store/coalesce.rs:122-133 (predicate copied at :574-580 and :1133-1137):
fn reusable(&self) -> bool {
self.open_error.is_none()
&& matches!(
self.state,
SharedFileState::Unopened | SharedFileState::Opening | SharedFileState::Opened
)
}
D. selene/src/disk_store/coalesce.rs:345-350 (O(n) scan beside the O(1) window_index):
let existing = self
.shared_segments
.iter()
.filter(|(_, seg)| seg.reusable() && seg.key == key)
.min_by_key(|&(&id, _)| id)
.map(|(&id, seg)| (id, seg.key.clone()));
E. selene/src/disk_store.rs:1983-1994 (.max() chain in Staged::close):
let maintenance_jobs = self
.owners
.values()
.filter(|owner| matches!(owner, Owner::Truncate(_) | Owner::Unlink(_)))
.count();
let store_jobs = self.outbound.len()
+ self.host_inbound.len()
+ self.device.in_flight()
+ maintenance_jobs;
let abandoned_jobs = store_jobs
.max(self.owners.len())
.max(self.maintenance.len());
F. Counter-block copies (coalesce.rs:1021-1025, :1067-1071, :1095-1099; disk_store.rs:1361-1365, :1385-1390, :1403-1407), e.g.:
#[cfg(any(test, feature = "test-support"))]
if !win.disk_read_counted {
win.disk_read_counted = true;
resources.disk_window_reads += 1;
}