Code correctness report · NVIDIA/hyperflare-inference #734

Raw Markdown for agents: https://autobot.eidonix.com/p/02ce7b0d-8546-4387-bab4-0e37cb0c367a.md

Deep Code Correctness / Invariants / Hot-Path Audit — PR #734 @ 015076e

Scope check (per the partitioning rule): 2 files, 2 modules of one crate (selene/), 554 changed lines — small & single-subsystem, so no sub-agents were spawned; the audit was done directly with batched reads of the diff, both changed files, and every non-trivial callee.

Verdict

No Blocker, no Major, and no verified correctness or hot-path defect. I traced every non-trivial changed function against its callees and against the four protocol checks and could not construct a failing counterexample. Three genuine but non-defect-level observations follow, each directly verified against source at 015076e.


Protocol check 1 — callee / enum / design-invariant resolution (all resolved, all sound)

Inspection (selene/src/shared/record.rs:1304-1313) has four variants; the new match at record.rs:1266-1273 places every one correctly against inspect's own contract (record.rs:1315-1371):

match outcome {
    Inspection::Record(scanned) => records.push(scanned),
    Inspection::Invalid => removals.push(path),
    Inspection::Unreadable(error) => return Err(error),
    Inspection::Absent => {}
}

Protocol check 2 — order-of-operations / state transitions (traced, consistent)

Worker::scan (selene/src/input.rs:514-587), full failure-path trace:

entries.sort();
let mut inspected = super::record::par_map(&entries, |path| inspect(path));
if let Some(pos) = inspected.iter().position(|result| {
    matches!(result, Err(error) if error.kind() != std::io::ErrorKind::InvalidData)
}) { return Err(failure("read prepared-input record", &entries[pos],
        inspected.swap_remove(pos).unwrap_err())); }

Protocol check 3 — adversarial small-N / boundary counterexamples (all pass)

Protocol check 4 — hot-path big-O

par_map and both scans are startup-only (record::scan callers: offload.rs:754, selene-manager/src/disk.rs:101; Worker::scan only from Worker::new, input.rs:506). No per-step/eviction/request path is touched, and remove_orphans's existing O(N)-per-pass HashSet build is unchanged. Nothing in the diff lands on a scheduler/serving hot loop.


Verified observations (non-blocking, cite-and-confirm only)

  1. Minor — documented invariant drift: .*.tmp files now survive a failed scan. record.rs:1259-1261 turns a tmp entry into Inspection::Invalid, and record.rs:1270 + 1274-1276 only reach remove() after the entire pass succeeds, so any Inspection::Unreadable returns at 1270 first:
    Inspection::Unreadable(error) => return Err(error),
    
    Previously (main) the tmp file encountered at record.rs:1147-1150 (old) was unlinked during iteration, before the unreadable file was reached. Consequence: after a permission/device error, the directory keeps both the unreadable .ckpt and every leftover .tmp, whereas the module contract at record.rs:1194-1208 still says the scan "delete[s] temporary files" and narrows the keep-in-place rule to "a .ckpt file the scan cannot open or read", and selene-manager/docs/operating.md:357 (not opened) states "Recovery per scope removes leftover .*.tmp files". The new test at record.rs:2734 ("temp file must not be deleted on unreadable scan failure") enshrines the new behavior, so this appears deliberate — worth an explicit confirm since it changes a documented recovery guarantee (the next successful scan does clean them up).
  2. Minor — par_map makes two extra full passes/allocation copies. record.rs:1181-1191: results are accumulated as Vec<(usize, R)>, sort_unstable_by_key'd, then re-collected into a fresh Vec<R>. For the PR's 10,000-record geometry this doubles peak retention of Scanned (each with a PathBuf + Header) plus the candidates Vec<(PathBuf, String, bool)> at record.rs:1223-1244, which the sequential version never materialized. Startup-only and a few MB at 10k records, but a chunk_index * CHUNK-indexed Vec<Option<R>> (or writing into a pre-sized MaybeUninit/unsafe-free slot vector) would avoid the second pass.
  3. Minor — helper threads do not set priority explicitly. record::inspector's scoped "flare-scan" threads (record.rs:1175-1177) rely on inheritance of the creator's niceness/scheduling class; the disk path deliberately calls flare_eos::lower_priority (disk.rs:619). Irrelevant for cold startup, but the flare-input-records thread sets it (input.rs:295) and its new children do not restate it.

Also verified as non-issues (checked, clean)