Final review report · NVIDIA/hyperflare-inference #646

Raw Markdown for agents: https://autobot.eidonix.com/p/1b7b1e23-b547-4583-a8f7-32ee6a901682.md

Recommendation: Changes Requested

This PR tackles four real, high-impact operational defects (Orbit rank-cache collision and duplicate staging, GB10 page-cache/KV/offload memory sizing, flare-agent hardening, and NVML FFI/FD-leak consolidation), and the core fixes—including PayloadSource::release_page_cache, once-only input_window accounting, the OnceLock NVML consolidation, device.ordinal visibility matching, handshake magic/timeout hardening, and atomic_write_private—are clean and well-tested. However, verification surfaced one blocker (permanently leaked staged cores under <core-cache>/staging/orbit/ with no reclamation path) and several concrete correctness gaps, including a newly identified marker-ordering bug that defeats .flare-verified.json (not opened) fast-path reuse on multi-file cores after orbit push, an undersized pre-auth session cap for multi-host fabric bursts, a still-open PID-reuse race in agent::stop, and [paths].core_cache not being wired into flare agent install.

Merge Risk

Level: High

Walkthrough

Pre-merge Checks

Blockers

  1. Abandoned <core-cache>/staging/orbit/ transfers leak whole cores permanently with no reclamation path (flare-cli/src/orbit/agent.rs:1443-1455, helios/src/core/cache.rs:3158-3214):
    • put() stages controller-uploaded core files under <core-cache>/staging/orbit/cores/<dir>/ and returns early at agent.rs:1454 without ever running eviction.
    • Normal TRANSFER completion (agent.rs:803) and verification failure (agent.rs:1623) remove staged_dir, but if a PUT is interrupted (controller Ctrl-C, network drop before TRANSFER, or agent restart), those tens/hundreds of GiB stay in staging/orbit/cores/ forever.
    • helios::core::cache::Root::collect() (helios/src/core/cache.rs:3158-3214) only sweeps staging/trees, staging/incoming, and staging/wrapped—staging/orbit is completely invisible to flare models gc and every agent cleanup path. (Additionally, if a fresh re-push stages and commits a second copy, stage_named creates a -2 suffix at cache.rs:2088-2097 while Root::collect() treats every models/*/* directory as live at cache.rs:3153-3156, leaving the superseded entry until manual flare models remove.)
    • Fix: Evict unpinned/unleased entries inside cache::cores_directory(&agent.staging_root()) on PUT (and/or agent startup) using core_cache::evict—which is safe there because staging/orbit/cores/ contains only Orbit staging dirs, never Helios managed dirs—or teach Root::collect() to reclaim unleased entries in staging/orbit/. Add a regression test verifying abandoned staged dirs are reclaimed.

Should Fix

  1. publish_orbit_entry writes .flare-verified.json (not opened) in unsorted fs::read_dir order, breaking fast-path cache reuse on multi-file cores (flare-cli/src/orbit/agent.rs:546-590, 790-816, flare-cli/src/distribution.rs:643-671, 720-723):

    • move_staged_tree() (agent.rs:560-588) pushes filenames into entry_files in filesystem-arbitrary fs::read_dir order (despite its doc comment at :547 saying "sorted") and publish_orbit_entry() passes &entry_files directly to distribution::write_verified_marker_for() (agent.rs:809-815), which records marker.files in that exact slice order (distribution.rs:652-670).
    • When orbit run starts peer ranks, distribution::verified_marker_matches() (distribution.rs:720-723) zips plan.files (ordered by runtime_core::rank_ranges: primary first, then companions in manifest order) positionally against marker.files and returns false on the first name mismatch.
    • On multi-file (directory/payload) cores, this causes .flare-verified.json (not opened) written by orbit push to miss on the first orbit run, forcing a full SHA-256 disk re-verification of the entire rank payload.
    • Fix: Match files by name (e.g., sort both sides by filename or index marker.files by name) in write_verified_marker_for() / verified_marker_matches(), and sort entry_files in move_staged_tree() to match its doc comment. Add a multi-file orbit push → receive_rank marker-hit test.
  2. MAX_PREAUTH_SESSIONS = 256 can silently drop legitimate multi-host FETCH_FABRIC bursts (flare-cli/src/orbit/agent.rs:296-301, 1116-1120, 1749, 1775, flare-cli/src/orbit/controller.rs:1502):

    • Every incoming stream holds a preauth_guard slot until fetch_fabric()/fetch() verifies the grant (agent.rs:1749, 1775).
    • Controller triggers peer TRANSFERs concurrently (controller.rs:1502), and each peer may open up to 64 streams (agent.rs:1543). With world up to 16 (distribution.rs:141), a direct burst from 5+ peers × 64 streams (320–960 concurrent handshakes) exceeds MAX_PREAUTH_SESSIONS = 256—and even 4 peers × 64 = 256 has zero margin for a concurrent controller session or probe. Overflow connections are silently dropped (drop(stream); continue; at agent.rs:1118) with no log, aborting cluster transfers without diagnostics.
    • Fix: Raise MAX_PREAUTH_SESSIONS (or release the pre-auth slot once the authenticated peer key/framing is checked, or split unauthenticated probe slots from authenticated-peer slots) and log when shedding connections at the cap.
  3. PID-reuse signal window in agent::stop() is narrowed, not closed (flare-cli/src/orbit/agent.rs:2135-2139, 2204-2221):

    • In the reaper (agent.rs:2136-2138), child.wait() reaps the child (returning group.pid to the kernel pool) before finished.exited.store(true, Ordering::Release) runs, and without taking any lock shared with stop().
    • stop() (agent.rs:2207-2216) locks group.log (which the reaper does not hold around wait() or exited.store), checks !group.exited.load(Ordering::Acquire), and calls libc::kill(-group.pid, SIGTERM) (plus fallback libc::kill(group.pid, SIGTERM) on ESRCH). Thus stop() can still race with reaping and signal a recycled PID, making the SAFETY comment at :2212 and the PR's claim that the window is closed inaccurate.
    • Fix: Do not hold a lock across blocking child.wait() (that would deadlock stop()). Instead, on Linux wait without reaping first via libc::waitid(P_PID, pid, &mut info, WEXITED | WNOWAIT) (keeping the zombie so the PID cannot be recycled), then acquire a dedicated reap: Mutex<()> lock, set exited = true, and call now-nonblocking child.wait() under that lock; have stop() hold the same reap mutex across its exited check and kill() calls.
  4. [paths].core_cache (and top-level --core-cache) is not applied to flare agent install (flare-cli/src/config.rs:138-140, flare-cli/src/main.rs:147-157, flare-cli/src/orbit/agent.rs:2316-2324):

    • Configuration::apply() (config.rs:138-140) only sets args.core_cache.get_or_insert(cache) on cli::Command::Agent(args), leaving AgentCommand::Install { core_cache, .. } as None. main.rs:147-157 passes only the subcommand's core_cache to orbit::agent::install(), ignoring both [paths].core_cache and flare agent --core-cache PATH install.
    • This contradicts the PR description ("Command::Agent and AgentCommand::Install accept --core-cache … and apply [paths].core_cache"), and the new test in config.rs:762-786 only covers flare agent.
    • Additionally, agent.rs:2317 interpolates path.display() unquoted into systemd ExecStart=, which breaks paths containing spaces or %.
    • Fix: Propagate agent_args.core_cache / [paths].core_cache into AgentCommand::Install (or, if install intentionally relies on runtime config loading when --core-cache is omitted, update the PR description and still forward agent_args.core_cache), shell/systemd-quote the path in ExecStart, and add a config test for flare agent install.
  5. Rendezvous loop ignores well-formed version-mismatch and duplicate-rank Joins, turning misconfigurations into timeouts (flare-cli/src/distribution.rs:211-221):

    • Lines 200-210 properly skip malformed/unparseable LAN probes. However, lines 211-221 also continue on a valid, parsed Join with join.version != VERSION || join.rank == 0 || join.rank >= world || peers[join.rank].is_some().
    • A genuine protocol-version mismatch or duplicate-rank cluster misconfiguration now loops until deadline and fails only with "timed out waiting for serving ranks" (:196) rather than failing fast with the root cause. This behavior change is not disclosed in the PR description.
    • Fix: Fail fast on valid Join frames with join.version != VERSION or out-of-range/duplicate rank (keeping continue only for malformed/unparseable connections), or explicitly justify and document the timeout semantics if stale-peer tolerance is required.
  6. Best-effort marker writes in publish_orbit_entry can silently publish entries reported as unverified (flare-cli/src/orbit/agent.rs:804-816):

    • Both fs::write(entry.directory().join(VERIFIED), ...) (:804) and distribution::write_verified_marker_for(...) (:809) discard errors via let _ = ....
    • On ENOSPC or I/O error right after committing a multi-GiB entry, publish_orbit_entry still publishes source refs and reports "verified": true, while Agent::cores() (:1024-1025) and placement (plan::Pool::holds, plan.rs:212-214) subsequently treat the entry as "verified": false.
    • Fix: Propagate errors from writing .verified and (when real_core is true) .flare-verified.json (not opened) before publishing source refs.

Subtract / Simplify

  1. Delete hardcoded HELIOS_CACHE_DIRS skip list (or source it from helios::core::cache) (flare-cli/src/core_cache.rs:234-251, 1936-1958):
    • After this PR, the only production caller of core_cache::evict() is flare-cli/src/orbit/agent.rs:1461, which only runs for non-core/non-package uploads (<agent.cache>/bin) and can never touch a Helios cache root.
    • Hardcoding ["blobs", "models", "refs", "sources", "origins", "staging", "locks"] duplicates helios/src/core/cache.rs:1589-1603 and re-introduces the exact module-ownership concern that left #147 in CHANGES_REQUESTED. Either remove HELIOS_CACHE_DIRS (and its test) outright, or export pub const ROOT_DIRECTORIES: &[&str] from helios::core::cache if defense-in-depth is desired.
  2. Avoid double controllers.toml (not opened) read/verify per frame in session() (flare-cli/src/orbit/agent.rs:1148-1164):
    • agent.is_controller(&session.remote())? reads and verifies controllers.toml (not opened) from disk twice per frame even after timeouts_cleared is true. Guard the pre-read_header block with if !timeouts_cleared so already-authorized controllers still clear timeouts and drop preauth_guard before blocking in read_header(), while steady-state frames only re-check is_controller once after read_header() (preserving mid-session controller revocation).
  3. Replace check(..).unwrap_err() and check(..)?; unreachable!() with a direct NVML error builder (flare/src/hardware.rs:38-78, 215-223, helios/src/runtime_core/device_memory.rs:33-36, heliopause/src/export/capture.rs:2144-2152):
    • Converting check(op, code) -> Result<()> into an error-formatting helper (matching flare-cli/src/orbit/gpu.rs:149-152) removes 7 unwrap_err() sites and 3 unreachable!() branches.
  4. Minor cleanups in agent.rs and protection.rs (flare-cli/src/orbit/agent.rs:499-517, 1016-1053, helios/src/runtime_core/protection.rs:229-236, 2842):
    • parse_rank_directory can delegate its -rank<R> split to parse_rank_selector; Agent::cores() can iterate &by_name and check by_name.contains_key(&name) at :1051 instead of cloning keys into a separate seen_names: HashSet<String>; and because AuthorizedCore.loadable and PayloadSource.supporting_verified are always set to the same verify_payloads boolean (protection.rs:889-893, 2586, model.rs:274-278), AuthorizedCore::is_loadable() simplifies to self.loadable and PayloadAuthorizedCore::load (:2842) can call self.is_loadable().

Nits

Dropped on verification