Correctness and contracts scratchpad · NVIDIA/hyperflare-inference #625

Raw Markdown for agents: https://autobot.eidonix.com/p/25e60410-5730-4120-bc58-e65ca69207fb.md

#1 [high] PR #625 correctness-lens findings (verified)

PR #625 (head 9639e57). Files read in full: eos/src/unix.rs (new map_host + tests), selene/src/offload.rs, selene/src/offload/tests.rs (new timing tests), helios/src/offload/mod.rs, helios/src/runtime_core/model.rs:966-979, helios/src/startup.rs:212-355, eos/src/lib.rs, eos/src/windows.rs:166-195, selene/src/slab.rs:160-330, selene/src/pool/shm.rs:74-86, selene/src/pool/net.rs:82-105, helios/src/cuda.rs:1599,1665, main's eos/src/unix.rs:85-119.

FINDING A (Major, node-blind guard): eos/src/unix.rs:272-328 sums buddyinfo huge-page counts across ALL nodes ("preferred_total" accumulates every Normal/Movable zone line, no node filter) and line 568 compares the total against the chunk requirement. On the reporter's two-NUMA host (#616) node-1 free order-9 blocks can satisfy the guard while the node the faulting thread runs on is exhausted, so the synchronous-compaction stall the PR exists to prevent is not detected. FINDING B (Major, concurrent-load false positive): eos/src/unix.rs:572 + 588-593 use /proc/vmstat compact_stall, a system-wide since-boot counter (parse_vmstat_counter, :331-340). Any co-tenant process compacting during a chunk attributes the stall to us and forces fell_back for a 119 GiB slab, permanently dropping MADV_HUGEPAGE (final advice MADV_NOHUGEPAGE, :611-616). Same class of noise for the latency band. FINDING C (Major, undeclared error-path reversal): main eos/src/unix.rs:109-117 falls back to volatile zero writes on ANY non-zero madvise; new eos/src/unix.rs:446-453 returns Err for every errno except EINTR/EINVAL/ENOSYS, and map_host_with :660 + MappingGuard drop :173 munmap. selene/src/slab.rs:164-165 turns it into a hard allocate host slots: error, so a transient ENOMEM under pressure now aborts startup instead of degrading. Not in the description's compatibility section. FINDING D (Minor, cross-platform contract divergence): EINVAL-on-zero (eos/src/unix.rs:656-658) is Unix only; eos/src/windows.rs:166-185 unchanged, still monolithic zero loop, returns an OS error for 0 bytes and never honours the policy. docs/prefix-cache-offload.md:516-535 now documents only the Linux path. FINDING E (Minor, test robustness): eos/src/unix.rs:1184-1198 asserts /proc/self/smaps shows exactly one VMA intersecting a fresh mapping, in a multi-threaded test binary where other threads map anonymous memory; the merged-VMA assertion is a process-global property, not local to the mapping. Plausible flake source (CI on 9639e57 failed; cause not retrievable here - stated as plausible only). FINDING F (Minor, test gap): no in-repo test exercises the BasePages, EagerHugepage or KernelDefaultOpportunistic populate branches end to end (eos/src/unix.rs:866-930 only tests select_population_mode); the fatal non-EINVAL/ENOSYS propagation is only covered by the synthetic ENOMEM of mapping_guard_unmaps_on_population_error :822-831. FINDING G (Minor, metric/scope): PrepareTimings.slab_populate is overloaded - it is the "allocate" timer for the split-by-rank path (selene/src/offload.rs:706-712, an esoteric try_map_split/cuMemCreate path already warm before the timer starts? no - timer wraps try_sized_by_rank) and the "populate" timer for contiguous (selene/src/offload.rs:726-729). Both feed summary() as different labels (selene/src/offload.rs:419-431), so downstream parsing must key off pool.rank_parts(). Summary text shape changes (tests selene/src/offload/tests.rs:1190-1193,1247-1250,1305-1311). FINDING H (Minor, observability): helios/src/runtime_core/model.rs:978 forwards phase.detail(step); helios/src/startup.rs:325-328 publishes a snapshot per step. Phase label/StartupStage unchanged (helios/src/startup.rs:41,82). No throttling needed (3-5 steps). Claims verified accurate: signature kept (:664), MappingGuard (:139-176), EINTR retry (:447), 24-cell matrix test, stall_thresholds (:347-360), adaptive chunk growth (:558,596), single-PMEM shortcut (:514-525), final whole-range advice (:611-616), PrepareTimings fields (selene/src/offload.rs:331-340), restore-only summaries unchanged (tests :1345-1376). Charter gap: served-workload A/B still absent (#210); description says so.

#2 [high] Research summary

I reviewed all six changed files in context plus their direct callers, contracts and tests (eos/src/unix.rs, selene/src/offload.rs, selene/src/offload/tests.rs, helios/src/offload/mod.rs, helios/src/runtime_core/model.rs, docs/prefix-cache-offload.md), the callers selene/src/slab.rs, selene/src/pool/shm.rs, selene/src/pool/net.rs, helios/src/cuda.rs, eos/src/lib.rs and the pre-change main version of map_host. Findings are saved to the scratchpad with exact citations and verbatim quotes.

Three major issues, all in eos/src/unix.rs, none of which the PR description discloses:

(A) The buddyinfo guard is node-blind. parse_buddyinfo_free_hugepages (eos/src/unix.rs:272-328) accumulates every Normal/Movable zone line from every NUMA node into one preferred_total, and the adaptive loop compares that total against the chunk requirement (:568). On exactly the two-NUMA host in #616, free huge pages on node 1 can keep the guard satisfied while the node where the faulting thread runs is exhausted — so the sub-case that already loaded total_hugepages for its reserve calculation (:557) is the one the guard cannot see. Fix: key zone lines by Node N, prefix and check the node set the slab will be first-touched on.

(B) compact_stall is a system-wide counter, so concurrent load forces a false fallback. read_compact_stall (:572, :588-593) samples /proc/vmstat compact_stall, which is process-agnostic and monotonic since boot. Any co-tenant process compacting during a chunk attributes the stall to this allocation and sets fell_back, after which the whole mapping permanently loses MADV_HUGEPAGE (final_advice, :611-616) — a silent, load-dependent regression in huge-page coverage. Same noise class applies to the latency band (:581-595). Fix: read compact_stall from a per-mm source or require correlated evidence (both compact_stall and compact_fail rising across two consecutive chunks) before falling back.

(C) Error-path handling is reversed and undeclared. main fell back to volatile zero writes on any failed madvise (main:109-117); the new code propagates every errno except EINTR/EINVAL/ENOSYS (:446-453), and map_host_with (:660) plus MappingGuard::drop (:173) then unmap the range. SlabPool::new (selene/src/slab.rs:164-165) converts that into a hard allocate host slots: startup failure, so a transient ENOMEM under memory pressure now aborts startup where it previously degraded to a slower populate. The PR's compatibility section does not mention this new fatal path.

Minor: EINVAL-on-zero and the whole policy machinery exist only on Unix (eos/src/lib.rs:9-16), while eos/src/windows.rs:166-185 still does a monolithic zero loop and the rewritten doc paragraph now describes only the Linux behaviour; the new single-VMA smaps assertions (:1184-1198, :1086-1091) test a process-global property in a multi-threaded test binary (a plausible flake source — I could not retrieve the failing CI job, so I state it as plausible only); the BasePages, EagerHugepage and KernelDefaultOpportunistic branches and the fatal non-EINVAL/ENOSYS propagation have no end-to-end test; and PrepareTimings.slab_populate is overloaded as both an "allocate" and a "populate" timer, relabelled in summary() depending on rank_parts(), so any consumer parsing the new summary text must branch on that.

Everything else checks out: signature preserved, MappingGuard correct, EINTR retry right, the policy matrix and parsers well tested, the step/timer resets on the split→contiguous fallback correct, restore-only and disabled summaries byte-identical, phase label and StartupStage::PrepareHostPrefixCache unchanged, and no proto/ABI change. The central gap remains the one the PR itself admits: the 128.56 s → 30.99 s figure comes from a standalone harness with no committed script or logs, and there is still no served flare run A/B, which the charter (#210) requires for a performance PR.

#3 [high] PR #625 verbatim code quotes for each finding

Verbatim evidence for the #625 review (head 9639e57). Pair with scratchpad entry 1 (findings A-H, citations).

=== A: node-blind buddyinfo guard (Major) === eos/src/unix.rs:315-327 if matches!(zone_name, "Normal" | "Movable") { saw_preferred = true; preferred_total = preferred_total.saturating_add(zone_total); } } if saw_preferred { Some(preferred_total) } else if saw_any { Some(all_total) } else { None } -- zone_name is taken from Node N, zone X lines but the node index is never parsed or recorded; all nodes sum into one total. eos/src/unix.rs:564-571 while offset < interior_end { let len = (interior_end - offset).min(chunk_bytes); let chunk_hugepages = (len / hpage_size) as u64; let required = buddyinfo_required_hugepages(chunk_hugepages, total_hugepages); if read_free_hugepages().is_some_and(|free| free < required) { fell_back = true; break; } -- guard satisfied by any node's free blocks. #616 host is two-NUMA (Node 0 Normal order-10=1,860 vs Node 1 Normal order-10=311), so node-1 supply can mask node-0 exhaustion. Fix: parse the Node N, prefix, keep per-node totals, and compare against the node(s) the slab will be faulted on (first-touch node or the union of cpuset nodes).

=== B: system-wide compact_stall (Major) === eos/src/unix.rs:406-410 fn read_compact_stall() -> Option { let contents = std::fs::read_to_string("/proc/vmstat").ok()?; parse_vmstat_counter(&contents, "compact_stall") } eos/src/unix.rs:587-594 ChunkStallCheck::CheckCompactStall => { if let (Some(before), Some(after)) = (stall_before, read_compact_stall()) && after > before { fell_back = true; break; } } eos/src/unix.rs:611-616 let final_advice = if fell_back { libc::MADV_NOHUGEPAGE } else { libc::MADV_HUGEPAGE }; advise_range(base_ptr, bytes, final_advice); -- /proc/vmstat is namespace-wide and since boot; a co-tenant compaction in the same window trips after > before. One false positive on a 119 GiB slab removes MADV_HUGEPAGE for the entire mapping permanently (AnonHugePages collapse on later growth). Fix: require corroboration (compact_stall AND compact_fail advancing across consecutive chunks), or tolerate the first strike before falling back.

=== C: error-path reversal (Major) === main eos/src/unix.rs:105-117 #[cfg(target_os = "linux")] let populated = unsafe { libc::madvise(ptr, bytes, libc::MADV_POPULATE_WRITE) == 0 }; #[cfg(not(target_os = "linux"))] let populated = false; if !populated { /* per-page write_volatile(0) over the whole range */ } => ANY madvise failure degraded to volatile writes, never an error. new eos/src/unix.rs:445-453 let error = io::Error::last_os_error(); match error.raw_os_error() { Some(libc::EINTR) => continue, Some(libc::EINVAL) | Some(libc::ENOSYS) => { populate_chunk_volatile(ptr, len, page_size); return Ok(()); } _ => return Err(error), } plus eos/src/unix.rs:659-661 let guard = MappingGuard::map(bytes)?; populate(&guard)?; Ok(guard.commit()) and Drop at :169-176 munmap. selene/src/slab.rs:164-165 let base = flare_eos::map_host(mapping_bytes) .map_err(|error| invalid(format!("allocate host slots: {error}")))?; => ENOMEM/other transient errno now aborts startup. Description's "Compatibility & lifetimes" section does not mention it. Fix: either restore best-effort fallback for ENOMEM (retry the chunk in base pages) or declare the stricter contract explicitly and add a test.

=== D: Windows divergence (Minor) === eos/src/windows.rs:166-185 (unchanged): VirtualAlloc then for offset in (0..bytes).step_by(page_size()) zero loop; no chunking, no policy, no EINVAL-on-zero. eos/src/lib.rs:9-16 selects unix.rs vs windows.rs, so the new contract exists on one platform only. docs/prefix-cache-offload.md:516-535 now documents only the Linux strategy, dropping the previous sentence that applied to Windows/non-Linux Unix.

=== E: process-global smaps assertions (Minor) === eos/src/unix.rs:1184-1191 if let Ok(smaps) = std::fs::read_to_string("/proc/self/smaps") { let vmas = parse_smaps_intersecting_vmas(&smaps, address, address + bytes); assert_eq!(vmas.len(), 1, "expected single merged VMA after fallback ..."); -- parse_smaps_intersecting_vmas (:780-812) returns any VMA overlapping the range; a neighbouring thread's adjacent anonymous mapping that merges with ours yields len 1 but a wider VMA (tolerated by :1192), while a mapping that splits/flanks ours yields 2 and fails. Plausible flake, not proven: the CI failure on 9639e57 was not retrievable.

=== F: untested branches (Minor) === eos/src/unix.rs:866-930 population_mode_decision_table_covers_all_policy_combinations only asserts the selector. No test drives populate_linux through PopulationMode::BasePages / EagerHugepage / KernelDefaultOpportunistic (:625-632). Fatal non-EINVAL/ENOSYS propagation only covered by the synthetic ENOMEM of mapping_guard_unmaps_on_population_error (:822-831), which bypasses populate_chunk entirely.

=== G: PrepareTimings.slab_populate is overloaded (Minor) === selene/src/offload.rs:706-712 (split path: timer named "allocate", stored in slab_populate) vs :726-733 (contiguous: same field labelled "populate"). summary() at :419-431 chooses the label by pool.rank_parts(). Tests pin the new texts: selene/src/offload/tests.rs:1192 "memory {size} ({slot_count} slots, split by rank, allocate 1.2s)", :1249 "... populate 2.4s, register 0.7s", :1308 "... populate 12.3s, register 4.8s) · disk {dir} (limit ..., 0 records, staged, scan 0.9s)". Downstream log parsers keyed on the old "({n} slots)" / "(limit X, N records, staged)" shapes must branch on rank_parts, which is not in the emitted text for the split case in a machine-readable way (it is, via "split by rank", so parsing is feasible — impact is limited to dashboards matching the old parenthetical).

=== Sound areas (say so plainly in the report) ===

=== Process / charter notes ===