PR #646: Unify Orbit rank cache, fix GB10 page-cache KV sizing, consolidate NVML, and harden flare-agent

Raw Markdown for agents: https://autobot.eidonix.com/api/v1/cases/a7a224c2-1e21-470c-a661-64cfc9404008

Opened by a workflow run, Nov 30, 2026 1:42 PM EST. decide malicious: all_clear (100%): No malicious content found

explore

Author: lukealonso (COLLABORATOR; one of the charter's three named priority contributors; Discord: lukealonso) Motivation: Orbit agents were evicting and duplicating the shared model cache (once deleting a 490 GiB download store), DGX Spark GB10 hosts were losing over a third of their KV budget to polluted Linux page cache, flare-agent accepted expired grants and could hang on leaked stdio, and five copies of the NVML loader leaked ~1,800 file descriptors an hour. Scale: +2597 / −1217 lines in 29 files Proposal:

Full report · Notes

Value Proposition

Value Proposition — PR #646

Charter alignment. In scope: Orbit placement and rank supervision (goal, line 22), prefix-cache host-memory accounting (line 24), DGX Spark/GB10 focus (line 3), and "reproducible bug / measured memory issue" (line 35). No per-model branches, no new aliases, no dependency churn (Cargo.toml/Cargo.lock untouched). The tension is focus, not direction: four unrelated defect families — Orbit cache layout, GB10/CUDA sizing, agent security/lifecycle, NVML FFI — in one 2,597-line diff across five crates, which strains the charter's compatibility-review standard (line 42).

Novelty & status. Additive — not obsolete, not superseded. flare-cli/src/core_cache.rs is unchanged since 2026-11-22 and #147 (the skip-list fix for #119) has been CHANGES_REQUESTED and frozen since 2026-11-13, so nothing on main blocks the 490 GiB eviction. #625 overlaps only Selene budget logic; #323 was closed as "use --memory-limit", which does not address page-cache reclamation.

Value vs cost. Strong for multi-host Orbit operators and GB10 users, against documented demand: #119 is P1 with real data loss; #629 reports 187 GiB mis-staged and 247 s instead of 2.3 s; #630 is P2. The author is the area owner of every touched file (helios 230 commits/180d, docs 385, flare/src 65), so maintenance risk sits with the person best placed to carry it. The evidence is uneven, though: the #119/#629 fixes have CPU tests but no test against a real flare download store and no live 4-Spark run; "closes #630" delivers only one of three asks (no KV-budget warning, no cuCtxCreate diagnostics) and is declared unmeasured on GB10; the ~1,800 FDs/hr NVML leak has no issue, no reproduction, and no before/after count — short of "bring real evidence" (line 12).

Changes required before merge: split into four independently reviewable changesets; add the GB10 KV-token measurement and an FD count, or soften the claims; notify #147's reviewers/author and #497's author, and rebase against #625 and coordinate with #647 on heliopause/src/export/capture.rs; document the undeclared semantics changes (relaxed rendezvous failure handling at distribution.rs:196–220, free_bytes now meaning the core cache, agent install baking --core-cache into the unit) and state the migration rule for existing flat cores/ data that #361 explicitly requires; justify models/<model>/<entry> over #361's proposed ranks/<id>.

Verdict: Worth it with changes — real, currently-unfixed user-facing defects from a priority contributor and area owner, blocked only on evidence strength, splitting, and honest scoping of #630.

Full report Decide Value: yes (100%): This change is worth reviewing: it provides value to the project in line with its charter.

Classify intake

Selected: triage:review, bug, performance, area:caching, area:memory, area:orbit, area:selene

Threshold: 65%

Triage

Priority

Type

Area

Model

Apply Labels (Intake)

Applied: +triage:review, +bug, +performance, +area:caching, +area:memory, +area:orbit, +area:selene

Subtraction and simplicity

Subtraction/Simplicity/Conventions review of PR #646. The diff is mostly lean — the NVML consolidation is a real ~1,000-line deletion and the selene/helios sizing edits are net simplifications — but six removable items remain.

  1. flare-cli/src/orbit/agent.rs:1148–1164 runs the identical pre-auth/slot-release block twice per loop iteration; timeouts_cleared makes the first copy a pure no-op. Delete lines 1149–1154.
  2. flare-cli/src/core_cache.rs:234–251 HELIOS_CACHE_DIRS is a hand-copied, already-incomplete duplicate of helios/src/core/cache.rs:1589–1603, and after this PR the only cache::evict caller (agent.rs:1461) always passes <agent cache>/bin, so it is unreachable in production and exercised only by its own new test at :1936. This is the exact objection that left PR #147 in CHANGES_REQUESTED.
  3. flare/src/hardware.rs:38,42,46,51,54 use check(..).unwrap_err() and :75–78 uses ?-then-unreachable!(); replacing check (:215) with a non-Result error builder deletes both idioms.
  4. agent.rs:499–517: parse_rank_directory is parse_rank_selector plus a length check — 8 lines reduce to 3; Agent::cores (:1016–1019, :1051) keeps a redundant HashSet with one String clone per entry.
  5. flare-cli/src/cli.rs:377–379 and :406–408 add speculative aliases --model-cache / --package-cache to a brand-new flag that nothing can depend on; AGENTS.md rejects speculative compatibility. Drop both.
  6. helios/src/runtime_core/protection.rs:230–236 ANDs loadable against supporting_verified, which is the same verify_payloads value (:892 vs :2586), making the match dead; the same predicate is then re-inlined at :2696 and :2842. Reduce to one definition.

Noted as lean: helios/src/nvml.rs has no speculative or dead FFI; orbit/store.rs atomic_write_private is itself subtraction; the distribution.rs/fabric_transport.rs skip-and-log arms are verbose but irreducible.

Open questions: whether :892 and :2586 are provably always equal (S6 depends on it); whether the bin/ PUT branch still justifies keeping evict's scan at all; whether the two aliases serve a script outside the repo (nothing in-repo or in docs uses them).

Full report · Notes

Correctness and contracts

PR #646 bundles four independent changesets (Orbit cache unification, GB10/unified-memory sizing, flare-agent hardening, NVML consolidation). The NVML, page-cache-release, input_window, device.ordinal, handshake-timeout, atomic-0600-secret, RoCE-dedup and peer --core-cache parts are sound. The serious gaps are in the Orbit/staging and process-lifecycle halves.

Top findings:

  1. Blocker/Major — <core-cache>/staging/orbit is never reclaimed: the cache::evict call in transfer() was removed (orbit/agent.rs:1444-1454) and Helios collect() never sweeps staging/orbit (helios/src/core/cache.rs:1594-1602), so an abandoned PUT/TRANSFER leaks a full 167 GiB-class core permanently, and re-pushing the same export strands the previous entry because stage_named appends -2/-3 (cache.rs:2076-2103) — re-opening the #119 class of unbounded cache growth.
  2. Major — MAX_PREAUTH_SESSIONS = 256 (agent.rs:296-301) is below a legitimate fabric burst of world(≤16) × streams(≤64) = 960; overflow streams are silently dropped (agent.rs:1113, :1118), breaking large multi-host launches at the least diagnosable moment.
  3. Major — the PID-reuse window the PR claims to close is still open: stop() reads exited under group.log (agent.rs:2206-2216) but the reaper stores it after child.wait() without that lock (agent.rs:2136-2138); a STOP in the gap signals a reused pid.
  4. Major — hard-coded HELIOS_CACHE_DIRS in flare-cli/src/core_cache.rs:236-238 re-lands the exact design yatesdr blocked on #147; it drifts as soon as Root gains a top-level directory. 5–11 (Minor): rendezvous misconfiguration now hangs to timeout (distribution.rs:211-221); intake_warning prints "max concurrency 1" (offload.rs:388-395, :606); [paths].core_cache is not applied to flare agent install (config.rs:138-140 vs main.rs:147-156), contradicting the PR text; best-effort .verified marker writes (agent.rs:804-816); free_bytes now covers only the core FS (agent.rs:917); --hosts silently overrides --gpus (main.rs:448-456); assign_visibility now hard-fails when a dropped device is named (hardware.rs:184-193).

Full report · Notes

Final review

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

Full report

Classify triage

Selected: triage:review

Threshold: 65%

Triage

Apply labels

No label changes Decision to Test: no (100%): Testing will not add significant value as the code stands today. The code is either not yet ready to merge, or adequate testing has already been done to validate the contents of the code, or the available hardware is not suitable to test with.