Explore scratchpad · NVIDIA/hyperflare-inference #734

Raw Markdown for agents: https://autobot.eidonix.com/p/7e30da78-cf46-46ee-a415-f3c91b51a00d.md

#1 [high] Change: what PR #734 does and its size

PR #734 (open, DRAFT, author FujitsuPolycom, labelled area:selene + performance, Discord "Dooner", base main 22d2ac9, head 015076e, opened & last updated 2026-12-04, no CI checks, no reviews, no comments).

Files (pr_files): selene/src/input.rs (+130/−7), selene/src/shared/record.rs (+424/−23). Total +554/−30; description says +105 net non-test production LOC (+135/−30) with +419 test LOC.

Three production changes:

  1. Header::read_metadata (selene/src/shared/record.rs:355-397): reads into a stack buffer [0u8; HEADER_BYTES + 4096] in a single read() loop (handles short reads + EINTR), so v3 headers and v4 directories <= 4096 B are covered by one syscall; larger v4 falls back to Vec + read_exact for the tail. Doc comment now says "May read ahead past the end of the metadata... callers must not rely on the reader cursor position after this returns" (record.rs:357-359). HEADER_BYTES = BLOCK_BYTES = 4096 (record.rs:92); packed::MAX_DIRECTORY = 2 MiB (selene/src/shared/packed.rs:17).
  2. New par_map helper (record.rs:1142-1189): PARALLEL_SCAN_THRESHOLD=64, PARALLEL_SCAN_CHUNK=8, MAX_SCAN_WORKERS=16; workers = available_parallelism().map_or(4,..).clamp(1,16), falls back to serial map below threshold or if <=1 worker; uses std::thread::scope + Builder::name("flare-scan").spawn_scoped(...).ok() (spawn failure silently degrades to fewer threads) with the calling thread participating; results re-sorted by index for order.
  3. record::scan (record.rs:1206-1280) split into collect-candidates → par_map symlink_metadata + inspect → serial reduction that deletes .tmp/invalid files only after no Unreadable error; then remove_orphans.
  4. Worker::scan (selene/src/input.rs:518-585): collects .input entries, sorts paths, par_map(inspect), returns the first non-InvalidData error before unlinking .input.pending or mutating self.disk/self.budget, then applies the serial budget/recovery loop.

Tests added (record.rs:2429-2740 and input.rs:1643-1750): read_metadata single-read/EINTR/short-read/truncation tests, parallel_scan_handles_large_mixed_v3_v4_directory_deterministically (also checks dangling + live symlinks, subdirs, foreign file survive), parallel_scan_preserves_directory_on_unreadable_entry, two input-side tests (deterministic recovery under tight DiskBudget; unreadable entry preserves dir+budget).

#2 [high] Change: behaviour changes the description does not spell out

Things the description understates or omits (verified in the diff, pr_diff of both files):

  1. Deletion is now deferred and best-effort-ordered: previously record::scan deleted .tmp/invalid files inline as it walked; now removals happen in a second pass after reduction (record.rs:1266-1280). Same net effect on success, but on a mid-scan Unreadable error the whole removal pass is skipped, so garbage that a previous run would have deleted survives until the next successful scan. Same intentional fail-closed change in Worker::scan for .input.pending files (input.rs:548-568) — .pending files used to be deleted as encountered inside read_dir, now only after all inspects succeed.
  2. Worker::scan now sorts .input paths lexicographically before inspecting (input.rs:552 entries.sort()). This is a new deterministic admission order under MAX_DISK_RECORDS/DiskBudget; before, order followed fs::read_dir order. The description mentions it, but it is a behaviour change in which records survive a tight budget, not just a perf change. Test parallel_scan_recovers_large_directory_deterministically_under_tight_budget (input.rs:1645+) pins the new order.
  3. Worker::scan error selection changed: it reports the first non-InvalidData error by sorted path order, and uses swap_remove on the result vec. Description mentions reject-before-unlink; what it does not say is that all inspections still complete before the error is returned (no early abort), so a directory of thousands of files pays full inspection before failing.
  4. par_map is pub(crate) and lives in shared::record (record.rs:1148). selene-manager cannot use it; selene-manager/src/disk.rs::recover (disk.rs:60-108) still does its own sequential per-directory Header::read_metadata loop over the first entries to find identity/fingerprint before delegating the actual scan to record::scan (disk.rs:101). So selene-manager's own discovery loop is still QD=1 — the description says "delegates full directory scans to record::scan", which is true for the scan but not for its pre-pass.
  5. Symlink handling unchanged: inspect still uses fs::symlink_metadata and requires is_file(), so symlinks (live or dangling) are neither followed nor deleted — same as before the change; the new test locks that in. Note a live symlink to a regular file is not treated as a record, it is skipped (record.rs:1256-1262 if !metadata.is_file() { return Inspection::Absent }).
  6. Read-ahead can consume up to 4096 bytes of the first record segment into the buffer: for a v3 record whose file is only HEADER_BYTES long (metadata-only), read() returns fewer bytes, fine; but for any record whose segment begins with page data, up to 4096 page bytes are read and discarded. No correctness effect since every caller either drops the handle or uses positional reads (verified: selene/src/disk.rs:1478 caller later uses read_exact_at at disk.rs:1464, io_uring submits explicit offsets at disk.rs:2126-2165; selene/src/shard.rs:1200-1273 opens and drops per use; selene-manager/src/disk.rs:77 drops the File each iteration).

#4 [high] Project fit: scan runs in the timed 'Prepare host prefix cache' phase (PR #625)

#5 [high] Related work: author's #497/#496 series — same pattern, adjacent paths

This is the third PR in a series by the same author (FujitsuPolycom, Discord "Dooner"; CONTRIBUTOR; 20 merged, 12 closed, 0 open in the last 180 days) doing the same kind of change in Selene:

#6 [high] Project fit: matches charter goals; deviates from the served-workload evidence rule

AGENTS.md (repo root) requirements vs. what this PR supplies:

#7 [high] Process & community: draft, zero engagement, no CI, no review yet

#8 [high] Claims and evidence: what is backed, what is self-reported, what is missing

Headline claims in the description and how each is (or is not) backed:

  1. "9.93x cold / 2.28x warm speedup for record::scan of 10,000 .ckpt on x86_64; 10.84x/2.99x on aarch64 GB10." Backed by the author's own bare-metal microbenchmark, medians with p10–p90, interleaved A-B-B-A, control 22d2ac9 vs candidate 015076e, dataset generator in the uncommitted harness. Not independently reproduced; not end-to-end; the harness itself is not in the diff, so a reviewer must paste ~200 lines from the description to re-run it.
  2. Cold cells are the strong result (all cold cells have non-overlapping ranges). Warm cells are much weaker: record::scan warm 1.38x (500), 1.85x (2000), 2.28x (10000) on x86_64.
  3. One measured regression is declared honestly: warm InputStore::start_bounded on x86_64 goes 2.09 → 2.53 ms (0.83x, +0.44 ms) for 1,000 files; the author attributes it to thread-scope setup + entries.sort() but says it was "not separately isolated by ablation". This is the one place the change makes a real-served path slower, and the affected path (warm restart of the input store) is common in practice (a container restart with a warm page cache).
  4. aarch64 warm distributions are bimodal and overlap between arms on InputStore; the author says so. Cold ratios on GB10 are ~9–10x.
  5. Test evidence is strong and specific: 591 selene tests (lib+integration) with test-support, 566 with --no-default-features, on both aarch64 bare metal and x86_64 container, non-root uid 1000/1001 with rustc 1.94.1/1.99.1/1.100.0; plus full-suite counts for helios (1,976), flare (247), flare-cli (224), selene-manager (205 + 98), and 4 Python tests. Counts are far above the 522/475 figures quoted in #496/#497, consistent with ~10 days of main-branch growth — plausible but not verifiable without CI.
  6. Claim "all five callers in selene and selene-manager either drop the file handle or use positional read_exact_at" — verified correct (see scratchpad entry on callers): record.rs:1334, disk.rs:1478 (positional reads at disk.rs:1464 and io_uring span.offset), shard.rs:1200, shard.rs:1251, selene-manager/src/disk.rs:77.
  7. Claim "0 production unsafe, 0 new dependencies" — verified: diff adds no unsafe; Cargo.toml untouched (std::thread::scope/spawn_scoped only). The only unsafe in the added code is libc::geteuid() inside a #[cfg(unix)] test (record.rs test parallel_scan_preserves_directory_on_unreadable_entry).
  8. Claim "+105 net non-test production LOC (+135/−30)": not independently recounted; pr_files reports +554/−30 across two files, which includes the +419 test LOC the description also states (554 − 419 = 135 added, −30 removed → +105 net; arithmetically consistent).
  9. NOT claimed and not measured: any end-to-end flare run startup A/B; any RSS/CPU-cost measurement of the new threads at startup; any measurement on a machine with a page cache smaller than the cache directory; any behaviour of the changed deletion ordering under a real unreadable-file incident.
  10. No ablation of the two changes against each other (read coalescing vs parallel scan), so a reader cannot tell how much of the cold win comes from each. #497's reviewer asked for exactly this kind of isolation ("attribute the hash pool separately"); the same ask applies here.

#9 [high] Reach: who is affected, compat, deployment, and what is not reversed

Who and what this touches (verified):

#10 [high] Why: the motivation is self-declared, not issue-backed

#3 [medium] Change: read_metadata callers and cursor semantics (verified)

Callers of Header::read_metadata at PR head (from search_code), and why the new read-ahead is safe: