Recommendation: Changes Requested
The implementation is clean, well-scoped (+135/-30 production LOC, +419 test LOC across two Selene files, zero production unsafe, zero new dependencies, zero format or wire changes), and passes an independent line-by-line correctness, boundary, and cursor-safety audit with zero code defects. However, as a pure performance PR with no user-reported issue behind it, it does not yet satisfy the Charter's served-workload evidence requirement (#210 / docs/design-review.md:106-115): it provides only isolated component microbenchmarks (no flare run Prepare host prefix cache A/B) and omits an ablation separating read coalescing from par_map or isolating the declared 0.83x (+0.44 ms) warm InputStore::start_bounded regression on x86_64.
Merge Risk
Level: Low
- Implementation safety:
Header::read_metadataread-ahead (HEADER_BYTES + 4096) is verified cursor-safe across all five production callers (selene/src/shared/record.rs:1334,selene/src/disk.rs:1478,selene/src/shard.rs:1202,1251,selene-manager/src/disk.rs:77), none of which usesO_DIRECTor relies on post-call file cursor position;par_mapdrops all file handles insideinspectbeforestd::thread::scopeexits (keeping concurrent FDs<= 16and preserving Windows close-before-unlink safety) and preserves symlink/directory safety. - Compatibility & blast radius: Strictly confined to pre-serving startup directory scans (
record::scanandWorker::scan). On-disk v3/v4.ckptand.inputlayouts, protobuf schemas,remove_orphansordering, and--no-default-featuresbuilds (rayon-free) are preserved. - Remaining risk: Minor warm-path latency regression (
2.09 → 2.53 ms,0.83xonx86_641,000 warm.inputfiles) and unverified end-to-endflare runstartup impact; native Windows execution was audited statically only.
Walkthrough
selene/src/shared/record.rs:357-397(Header::read_metadata): Replaces tworead_exactcalls with a single[0u8; HEADER_BYTES + 4096]stack buffer read loop (handling short reads andEINTR), returning immediately for v3 headers and v4 directories<= 4096bytes and falling back to oneread_exacttail read for larger v4 directories (bounded bypacked::MAX_DIRECTORY = 2 MiB). Documents non-guaranteed reader cursor position.selene/src/shared/record.rs:1142-1192(par_map): Adds apub(crate)bounded parallel mapper (threshold = 64,chunk = 8,workers = available_parallelism().clamp(1, 16)) usingstd::thread::scope, dynamicAtomicUsizechunking, fallible thread spawning (spawn_scoped(...).ok()with calling-thread participation), and index-order restoration.selene/src/shared/record.rs:1209-1278(record::scan): Pre-filters.*.tmp/*.ckptcandidates duringfs::read_dir, runsfs::symlink_metadata(never following symlinks) andinspectviapar_map, and reduces sequentially fail-closed (returning the firstInspection::Unreadablebefore deleting.tmp/invalid entries) before unchangedremove_orphans.selene/src/input.rs:514-587(Worker::scan): Defers.input.pendingremoval out offs::read_dir, sorts.inputpaths lexicographically for deterministic admission underMAX_DISK_RECORDS(4,096) andDiskBudget, inspects headers viarecord::par_map, and aborts on the first non-InvalidDataerror before unlinking temporaries or mutatingself.disk/self.budget.- Unit tests (
selene/src/shared/record.rs:2430-2741,selene/src/input.rs:1644-1750): Adds single-read/large-v4/short-read/EINTR/truncation/invalid-length tests forread_metadata, mixed v3/v4 parallel scan determinism and symlink/foreign-file preservation tests, tight-budget deterministic.inputrecovery, and Unix0o000unreadable-entry fail-closed tests.
Pre-merge Checks
- [PASS] Security / malicious screen: Zero production
unsafe(onlylibc::geteuid()in a#[cfg(unix)]test with// SAFETY:), zero new dependencies, symlinks never followed or unlinked,packed::MAX_DIRECTORYvalidated before allocation, no prompt-injection or suspicious code. - [WARN] Charter & value fit: Squarely within Selene's disk prefix-cache charter goal with no model branches, flags, or format changes, but lacks the served-workload (
flare run) benchmark and regression ablation required for performance PRs (#210,docs/design-review.md:106-115,docs/core-design.md:1834-1836). - [PASS] Related / duplicate / conflict check: Cleanly extends
#496/#497(same author, fetch/restore paths) to startup scan with zero overlapping hunks and zero conflicts againstmain(22d2ac9). - [WARN] Tests & verification evidence: Thorough unit-test coverage added and dual-architecture
A-B-B-Acomponent microbenchmarks reported (7.5x–10.8xcold NVMe.ckpt,8.4x–9.0xcold.input), but no end-to-endflare runmeasurement, no coalescing-vs-par_mapablation, and native Windows remains statically audited only (disclosed).
Blockers
None.
Should Fix
- Provide end-to-end
flare runstartup A/B evidence and an ablation isolating read coalescing vspar_map(and the declared warm.inputregression).- Where: PR performance evidence vs
selene/src/offload.rs:750-776(timings.disk_scan/Prepare host prefix cache),selene/src/shared/record.rs:361-397,1142-1192,selene/src/input.rs:552-553. - Why: The Project Charter (Bring real evidence,
#210) anddocs/design-review.md:106-115require performance PRs to demonstrate an actual improvement overmainon a served Helios workload, anddocs/core-design.md:1834-1836specifies that an aggregate win does not erase a workload regression. Here, the PR explicitly notes that its measurements are isolated component microbenchmarks (even thoughflare runalready timesrecord::scaninPrepare host prefix cacheviatimings.disk_scanatselene/src/offload.rs:750-765, documented atdocs/prefix-cache-offload.md:1070-1076, and runsInputStore::start_boundedimmediately after at:767-776). Furthermore, the PR discloses anx86_64warmInputStore::start_boundedregression (2.09 → 2.53 ms,0.83x,+0.44 mson 1,000.inputfiles — which do not useHeader::read_metadatacoalescing) whose cause (entries.sort()vs spawning up to 15"flare-scan"OS threads atPARALLEL_SCAN_THRESHOLD = 64) is explicitly unisolated, and does not separate the.ckptspeedup attributable toHeader::read_metadatacoalescing vspar_map(mirroring the mechanism attribution requested on#497). - Fix:
- Run a cold- and warm-page-cache
flare runrestart A/B (main22d2ac97vs PR head) against a populated--prefix-cache-diskdirectory on at least one target host (e.g., GB10 orx86_64) and report thePrepare host prefix cachetotal andscan(timings.disk_scan) durations. - Run a brief ablation isolating (a)
Header::read_metadatacoalescing alone vspar_mapon.ckptscans, and (b)entries.sort()vspar_mapthread-spawn overhead on warm.inputscans — and if thread-spawn/contention drives the warm.inputregression, either tune the threshold/worker cap for.inputor confirm it is negligible inflare runstartup.
- Run a cold- and warm-page-cache
- Where: PR performance evidence vs
Subtract / Simplify
- Deduplicate the
PackedUnittest fixture inselene/src/shared/record.rs:2354-2389vs:2430-2471.packed_headeradded at:2430-2471builds the samePackedUnitlist already hand-constructed inheader_eq_implies_same_hash(:2354-2389). Callingpacked_header(&geometry, 512, Some(256))inheader_eq_implies_same_hashremoves ~34 lines of duplicated fixture code.
- Tag and sort per chunk instead of per item in
par_map(selene/src/shared/record.rs:1158-1191).- Each worker processes contiguous
PARALLEL_SCAN_CHUNK(8) slices already in index order. ReturningVec<(usize, Vec<R>)>(or sorting chunks bystartand flattening) cuts sort cardinality by 8x and avoids storing an extrausizeindex alongside everyInspection/Resultelement, while keeping dynamic work-stealing intact.
- Each worker processes contiguous
- Extract a small
Drop-based temp-directory fixture forrecord::scantests (selene/src/shared/record.rs:2569-2741).- Matches the existing
DirectoryRAII pattern inselene/src/input.rs:1123, eliminates repeated temp-dir setup/teardown boilerplate in the two new scan tests (and 4 existing ones), and ensures temp dirs are cleaned up even if an assertion panics.
- Matches the existing
Nits
selene/src/shared/record.rs:363: Name the4096read-ahead size (e.g.,const READ_AHEAD_BYTES: usize = 4096;) instead of an inline literal next toHEADER_BYTES.selene/src/shared/record.rs:1239-1266: Theis_tmp: booltuple element incandidatesis redundant withname(after the pre-filter at:1240,!name.ends_with(SUFFIX)uniquely identifies.tmpentries).docs/prefix-cache-offload.md:677-690/selene/src/shared/record.rs:1206-1208: Optional one-sentence update noting that an unreadable-entry error aborts before deleting.tmp/invalid files and that.inputrecovery admits files in deterministic lexicographic order.
Dropped on verification
- "
selene-manageridentity pre-pass is still a full sequential QD=1 loop" (Discovery Dossier / Value Prop): False.selene-manager/src/disk.rs:71-98executesbreak;at:95on the first valid.ckptfile to obtain(identity, fingerprint, page_tokens, ranks)(O(1) in any healthy namespace) and delegates the full directory scan torecord::scanat:101. - "Deferred deletion and lexicographic
.inputadmission are undeclared behavioral changes / documented invariant violations" (Discovery Dossier / Value Prop / Code Audit): False / over-escalated. Both changes are explicitly declared in the PR description (### What changed). Onmain, whether.tmp/invalid files were removed before anUnreadableerror depended arbitrarily onfs::read_dirorder; aborting before deletion makes failure behavior deterministic and aligns withselene-manager/docs/operating.md:359-360("fails startup without deletion"). Likewise,entries.sort()replaces arbitrary filesystem order with deterministic admission order. - "Use Selene's existing
rayoncpu_pool(selene/src/shared/codec.rs:37-60) instead of scoped threads" (Discovery Dossier / Value Prop): Invalid.rayonis an optional dependency behind thecodecfeature (selene/Cargo.toml:14-16,23);record.rsandinput.rsmust compile and pass under--no-default-features. - "Replace
AtomicUsizework-stealing inpar_mapwith static partitioning likeselene/src/disk.rs:585-649" (Subtraction Audit): Dropped as worse for this workload.hash_pages_scopedhashes uniform 4 MiB RAM buffers; startup scans mix metadata-only.tmpchecks, 4 KiB v3 headers, two-read large v4 directories, and variable cold-NVMe latency, where dynamic chunking balances stragglers and automatically absorbs failed thread spawns without a post-scope recompute pass. - "Scoped
"flare-scan"helper threads do not callflare_eos::lower_priority" (Code Audit): Non-issue. On Unix (eos/src/unix.rs:91-97),SCHED_BATCHandniceare inherited by threads spawned fromflare-input-recordsafterselene/src/input.rs:295; on Windows (eos/src/windows.rs:161(not opened)),lower_priorityis a no-op; andrecord::scanruns during startup before serving threads exist. - "Commit the ~200-line
scan_bench.rs(not opened) harness intoselene/examples/" (Value Prop / Contracts Audit): Dropped. Committing a one-off benchmark example adds permanent repo footprint (neither#496nor#497committed example binaries), and the PR already embeds the complete standalone reproduction source in<details>; the actual evidence gap is theflare runstartup measurement and ablation above. - "Collect
entries.into_iter().zip(inspected)intopairs: Vec<_>inselene/src/input.rs:553-568" (Subtraction Audit): Dropped; adds an unnecessary heap allocation compared to the existing zero-allocationzip, and index correspondence is guaranteed bypar_map. - "CI not observable / Windows not executed on host" (Discovery Dossier): Not escalated; no CI failure is reported, Windows close-before-unlink is statically verified (
Filehandles drop insideinspectbeforescopeexits), and the Windows execution limitation is honestly disclosed.