Recommendation: Ready To Merge
Every Round 1 requirement and simplification item has been resolved cleanly at b7bd3fa: the author reverted the Header::read_metadata 4 KiB read-ahead after ablation showed it hurt warm scans and weakened the io::Read cursor contract (selene/src/shared/record.rs:358-373 is now byte-identical to main), supplied an attributable end-to-end flare run startup A/B on bare-metal GB10 NVMe (Prepare host prefix cache cold 2,542.00 → 295.44 ms, 8.60x; warm 95.58 → 53.20 ms, 1.80x; spawn-to-/health -2.21 s), ablated .input sorting (OsStr::cmp vs Path::cmp), switched par_map to per-chunk ordering, deduplicated the PackedUnit and Directory RAII test fixtures, and documented the fail-closed and lexicographic-admission contracts in docs/prefix-cache-offload.md. Direct verification of all changed code, callees, state transitions, and boundary cases at b7bd3fa confirms zero correctness defects, zero hot-path regressions, and all governance gates satisfied.
Merge Risk
Level: Low
- Implementation safety: Strictly confined to pre-serving startup directory scans (
selene/src/shared/record.rs::scan,selene/src/input.rsWorker::scan) with zero productionunsafe, zero new dependencies, and bounded concurrency (<= 16"flare-scan"scoped threads and<= 16open FDs per scan). EveryFilehandle opened insideinspectdrops beforestd::thread::scopeexits and before sequentialremove/remove_filecalls, preserving Windows close-before-unlink safety and symlink/subdirectory exclusion. - Compatibility & blast radius:
Header::read_metadata, on-disk v3/v4.ckptand.inputlayouts, protobuf wire schemas,remove_orphans(consumed_tokens, digest)ordering,DiskBudgetunwind invariants (selene/src/input.rs:506-510), and--no-default-features(rayon-free) builds are preserved. Both behavioral refinements (fail-closed error-before-deletion and lexicographic.inputadmission) are documented and pinned by fault-sensitive tests. - Disclosed residual limits: Native Windows execution was audited statically only, and the
x86_64warm.inputablation ran on WSL2ext4(control4.40 msvs Round 1's2.09 mshost baseline) rather than rerunning on the originalx86_64host; the governing served-workload GB10flare runCold + Warm A/B and GB10 warm.input(1.89x) both improve cleanly.
Walkthrough
selene/src/shared/record.rs:358-373(Header::read_metadata): Reverted tomain's exact two-read_exactimplementation, removing the Round 1 read-ahead and restoring the originalio::Readcursor contract.selene/src/shared/record.rs:1118-1171(par_map):pub(crate)bounded parallel mapper (threshold = 64,chunk = 8,workers = available_parallelism().map_or(4, ..).min(16).min(chunk_count)) usingstd::thread::scope, falliblespawn_scoped(...).ok()with calling-thread participation, panic propagation viaresume_unwind, and per-chunk(start, Vec<R>)sorting for exact input-order restoration.selene/src/shared/record.rs:1189-1260(record::scan): Pre-filters*.ckptand.*.tmpcandidate paths (Vec<PathBuf>, zero per-entryStringallocations), inspectsfs::symlink_metadata(never following symlinks) and headers in parallel viapar_map, and reduces sequentially fail-closed (returning the firstInspection::Unreadablebefore deleting.tmp/invalid entries) prior to unchangedremove_orphans.selene/src/input.rs:514-587(Worker::scan): Defers.input.pendingremoval out offs::read_dir, sorts.inputpaths in lexicographic rawOsStrorder (sort_unstable_by(|a, b| a.as_os_str().cmp(b.as_os_str()))), inspects headers viarecord::par_map, and aborts on the first non-InvalidDataerror before unlinking temporaries or mutatingself.disk/self.budget.docs/prefix-cache-offload.md:681,1199-1204: Documents fail-closed startup preservation on unreadable.ckpt/.inputentries, failure on.inputcleanup errors, and lexicographic path-order.inputadmission.- Unit tests (
selene/src/shared/record.rs:1966-1989,2322-2588,selene/src/input.rs:1644-1759): Extracts RAIIDirectory(declared beforelockacross all sixrecord::scantests) and deduplicatedpacked_header/scan_defaulthelpers; adds large mixed v3/v4 parallel scan determinism (including.dir.tmp,.link.tmp, live/dangling symlink survival), non-monotonic odd-then-even tight-budget.inputrecovery, and Unix0o000fail-closed tests with siblings seeded on both sides of the unreadable entry.
Pre-merge Checks
- [PASS] Security / malicious screen: Zero production
unsafe(only test-onlylibc::geteuid()under#[cfg(unix)]with// SAFETY:atselene/src/shared/record.rs:2525), zero new dependencies, symlinks/subdirectories never followed or unlinked, no prompt-injection or suspicious code. - [PASS] Charter & value fit: Squarely within Selene's disk prefix-cache goal with no model branches, flags, or format changes, and now backed by served-workload
flare runA/B evidence (#210,docs/design-review.md:106-115(not opened)). - [PASS] Related / duplicate / conflict check: Cleanly extends
#496/#497to startup recovery atopmain(be4092d7) with zero conflicts;selene-manager/src/disk.rs:101delegates full scans torecord::scanunchanged. - [PASS] Tests & verification evidence: End-to-end
flare runCold/Warm A/B reconciles with component benchmarks and.inputsort ablation; extensive non-root--releasetest runs reported passing onaarch64GB10 andx86_64Linux (native Windows static-audit limitation and WSL2x86_64warm ablation environment honestly disclosed).
Blockers
None.
Should Fix
None.
Subtract / Simplify
None.
Nits
selene-manager/docs/operating.md:357-360: Optional one-line alignment withdocs/prefix-cache-offload.md:681clarifying that leftover.*.tmpremoval occurs only when no entry fails with an I/O error (the existing sentence already states "fails startup without deletion").selene/src/shared/record.rs:2188,2525vsselene/src/input.rs:1507-1515: Optional test-only cleanup to share a singlemodes_restrict_user()helper instead of repeating theunsafe { libc::geteuid() } == 0guard inrecord.rstests.
Dropped on verification
- "Replace
inspected.swap_remove(pos).unwrap_err()inselene/src/input.rs:553-562by rebuilding the error from a reference" (Subtraction Audit): Dropped;std::io::Erroris notClone,super::record::io_failuretakesio::Errorby value, andswap_remove(pos)is followed immediately byreturn Err(...)so the reorderedVecis never observed afterward. Rebuilding from a reference would lose OS error fidelity (raw_os_error). - "Store
name.to_owned()incandidatesinselene/src/shared/record.rs:1222to avoidpath.file_name()re-derivation at:1238-1240, and shareis_temporary_namewithinput.rs" (Subtraction Audit): Dropped; storingVec<PathBuf>deliberately avoids 10,000Stringallocations on large caches while:1238-1240is a safeunwrap-free fallback, and.ckpttemporary names (.{16-hex}-{32-hex}.ckpt.tmp,record.rs:996) have a different format from.inputtemporary names (64-hex.input.pending,input.rs:937), so changing the predicate would be an out-of-scope behavioral change. - "Unify
par_map's thread ceiling withdisk.rs/codec.rsand callflare_eos::lower_priority" (Subtraction Audit / Discovery Dossier): Dropped;disk.rs(MAX_HASH_THREADS = 4) hashes 4 MiB RAM buffers during serving,codec.rs(rayonbehind optionalcodecfeature, unavailable under--no-default-features) runs background KV compression during serving, whereaspar_map(MAX_SCAN_WORKERS = 16) drives NVMe metadata queue depth during pre-serving startup and inherits Unix scheduling priority fromflare-input-records(eos/src/unix.rs:91-97(not opened)). - "Commit
scan_bench.rs(not opened) intoselene/examples/" (Discovery Dossier): Dropped; consistent with#496/#497not committing one-off benchmark examples, and the complete standalone source plusflare runreproduction commands are embedded in the PR body. - "Parallelize
selene-manager/src/disk.rs:71-98pre-pass" (Discovery Dossier): Dropped; verifieddisk.rs:95executesbreak;on the first valid.ckptheader (O(1)per healthy namespace) and delegates the full directory scan torecord::scanat:101. - "Fixed
PARALLEL_SCAN_THRESHOLD = 64ignores remote filesystems /record::scanholds twoPathBufcopies per survivor" (Code Audit Minors 1–2): Dropped as non-actionable; startup scan targets local NVMe caches with bounded<= 16workers and ~1 MB transient path memory at 10,000 records is negligible compared to simplifyinginspect/Scannedownership. - "
geteuid()in test contradicts '0 productionunsafe' claim" (Subtraction Audit): False; the PR explicitly claims0productionunsafe, andrecord.rs:2525is inside#[cfg(test)] #[cfg(unix)]with a// SAFETY:comment.