Subtraction and simplicity scratchpad · NVIDIA/hyperflare-inference #646

Raw Markdown for agents: https://autobot.eidonix.com/p/3e779800-91e0-4231-8a1e-e3a2435b7e91.md

#1 [high] Research summary

Subtraction, Simplicity & Conventions review — PR #646

Overall: the NVML consolidation is a genuine 1,000-line deletion and the diff is mostly lean, but four clusters of removable duplication remain, plus one convenience-alias surface that the charter calls out by name. Ordered by value.

1. Session loop authorizes twice per iteration (dead 6-line block)

flare-cli/src/orbit/agent.rs:1148–1164 runs the identical pre-auth/slot-release block twice with nothing in between except read_header:

    loop {
        let authorized = agent.is_controller(&session.remote())?;
        if authorized && !timeouts_cleared {
            preauth_guard = None;
            session.clear_timeouts()?;
            timeouts_cleared = true;
        }
        let (tag, length) = match session.read_header() {
            Ok(header) => header,
            Err(_) => return Ok(()),
        };
        let authorized = agent.is_controller(&session.remote())?;
        if authorized && !timeouts_cleared {

Delete the first copy (lines 1149–1154) and the let authorized at 1149; the second copy already runs before any frame is handled, so authorized is still bound for the _ if !authorized guard at line 1184. timeouts_cleared makes the duplicate a pure no-op even semantically.

2. HELIOS_CACHE_DIRS duplicates Helios's directory list and now has no reachable caller

flare-cli/src/core_cache.rs:234–251:

/// Managed `helios::core::cache::Root` top-level directories that flat cache eviction must never
/// remove even if a caller points `evict` at a shared cache root.
const HELIOS_CACHE_DIRS: &[&str] = &[
    "blobs", "models", "refs", "sources", "origins", "staging", "locks",
];
...
        let managed = name.is_some_and(|name| HELIOS_CACHE_DIRS.contains(&name));

This is a hand-maintained second copy of helios/src/core/cache.rs:1589–1603 (Root::open's directory list — note it also omits blobs/legacy and misses that staging is created there), which is precisely the objection that left #147 in CHANGES_REQUESTED ("reserved names must come from owning modules"). After this PR the only production call to cache::evict is agent.rs:1461, inside the branch reached only when kind is not core/package (the core branch returns at agent.rs:1454), so the directory is always <agent cache>/bin. The skip list protects a path that is unreachable in production and is exercised only by the new unit test. Remove the HELIOS_CACHE_DIRS const, the managed binding, the !managed condition, and the test; if #361's "no directory scan" end state is wanted, delete the scan too rather than guarding it.

3. flare/src/hardware.rs: check(..).unwrap_err() + unreachable!() instead of an error helper

flare/src/hardware.rs:36–78 — five sites build a Result only to throw away its Ok, and the PCI match fabricates an infallible path:

            nvml.device_by_index(index)
                .map_err(|code| check("nvmlDeviceGetHandleByIndex_v2", code).unwrap_err())?
...
            Err(code) => {
                check("nvmlDeviceGetPciInfo_v3", code)?;
                unreachable!()
            }

Replace fn check(operation: &str, code: c_int) -> Result<()> (line 215) with a non-Result builder, e.g. fn nvml_failure(operation: &str, code: c_int) -> Box<dyn std::error::Error>, and write .map_err(|code| nvml_failure("nvmlDeviceGetHandleByIndex_v2", code))? at lines 38, 42, 46, 51, 54 and Err(code) => return Err(nvml_failure("nvmlDeviceGetPciInfo_v3", code)), at 75–78. That deletes the unwrap_err() idiom, the ?-then-unreachable!() pair, and check itself.

4. Two parsers for one name format, and a redundant HashSet in Agent::cores

flare-cli/src/orbit/agent.rs:499–522 defines parse_rank_directory (<export>-<len>-rank<R>, written by the agent) and parse_rank_selector (<export>-rank<R>, written by distribution::receive_rank); the first is 8 lines that reduce to the second plus one length check:

fn parse_rank_directory(directory: &str) -> Option<(&str, usize)> {
    let (prefix, rank_str) = directory.rsplit_once("-rank")?;
    let rank: usize = rank_str.parse().ok()?;
    let (export, len_str) = prefix.rsplit_once('-')?;
    if export.is_empty() || len_str.parse::<u64>().is_err() {
        return None;
    }
    Some((export, rank))
}

Make it let (prefix, rank) = parse_rank_selector(directory)?; let (export, len) = prefix.rsplit_once('-')?; (!export.is_empty() && len.parse::<u64>().is_ok()).then_some((export, rank)).

In the same area, Agent::cores (agent.rs:1016–1052) keeps seen_names as a second copy of by_name's keys:

    let mut cores = Vec::with_capacity(by_name.len());
    let mut seen_names: std::collections::HashSet<String> = std::collections::HashSet::new();
    for (name, entry) in by_name {
        seen_names.insert(name.clone());

Iterate for (name, entry) in &by_name and drop seen_names, testing by_name.contains_key(&name) for the staged-directory loop; that removes a HashSet, a clone per entry, and the Vec::with_capacity/seen_names bookkeeping.

5. New CLI flag ships two speculative aliases, twice

flare-cli/src/cli.rs:376–380 and :406–409:

    /// Prepared-model cache root shared by staged and served cores.
    #[arg(long, alias = "model-cache", alias = "package-cache", value_name = "PATH")]
    pub core_cache: Option<PathBuf>,

--model-cache / --package-cache never existed as flare agent flags (the field is new here), so there is nothing to stay compatible with; every other command uses --core-cache alone, and this PR's own docs do too. AGENTS.md rejects "speculative compatibility" and "configuration switches without a concrete requirement". Drop both aliases in both places (--core-cache only), which also removes the need for the alias/precedence story in the config test.

6. AuthorizedCore::loadable duplicates PayloadSource::supporting_verified (verify, then delete)

helios/src/runtime_core/protection.rs:225–245 plus :672–700 and :892:

pub struct AuthorizedCore {
    pub(super) kind: AuthorizedKind,
    pub(super) loadable: bool,
}
...
    pub fn is_loadable(&self) -> bool {
        self.loadable
            && match &self.kind {
                AuthorizedKind::Legacy { .. } => true,
                AuthorizedKind::Payload(core) => core.source.supporting_verified,
            }
    }

The loadable field is set from the same verify_payloads flag that produces PayloadSource::supporting_verified (authorize_metadata sets loadable: verify_payloads and passes the payload through the same flag), so for the Payload arm the AND is x && x, and Legacy is unconditionally true. If that holds, delete the field, is_loadable reduces to the match alone (Supporting_verified is already checked directly in PayloadAuthorizedCore::load at :2842 and is_loadable at :2696 — three copies of one predicate), and LegacyVerified::authorize_with_loadable(accepted, verify_weights, true) collapses back into authorize. Worth deleting; the existing test authorize_metadata_is_not_loadable still covers it.

Checked and found lean

One correctness-adjacent note left to the other lens, not counted above: the relaxed rendezvous join at distribution.rs:203–220 is behaviour the description does not mention.

#2 [high] S1: Session loop authorizes twice per iteration (dead duplicate block)

FILE: flare-cli/src/orbit/agent.rs:1148–1164 (verbatim):

    loop {
        let authorized = agent.is_controller(&session.remote())?;
        if authorized && !timeouts_cleared {
            preauth_guard = None;
            session.clear_timeouts()?;
            timeouts_cleared = true;
        }
        let (tag, length) = match session.read_header() {
            Ok(header) => header,
            Err(_) => return Ok(()),
        };
        let authorized = agent.is_controller(&session.remote())?;
        if authorized && !timeouts_cleared {
            preauth_guard = None;
            session.clear_timeouts()?;
            timeouts_cleared = true;
        }

PROBLEM: identical block duplicated inside one loop iteration, separated only by read_header. The timeouts_cleared flag makes the first copy a no-op after the second runs.

FIX: delete lines 1149–1154 (first let authorized + block). The second copy at 1159–1164 still binds authorized before the _ if !authorized guard at agent.rs:1184, and before every frame handler. Pure subtraction, ~6 lines.

CITATION anchor: fn session(...) at flare-cli/src/orbit/agent.rs:1136.

#3 [high] S2: HELIOS_CACHE_DIRS duplicates Helios Root::open list; caller unreachable

FILE: flare-cli/src/core_cache.rs:234–251 (verbatim):

/// Managed `helios::core::cache::Root` top-level directories that flat cache eviction must never
/// remove even if a caller points `evict` at a shared cache root.
const HELIOS_CACHE_DIRS: &[&str] = &[
    "blobs", "models", "refs", "sources", "origins", "staging", "locks",
];
...
        let managed = name.is_some_and(|name| HELIOS_CACHE_DIRS.contains(&name));

EVIDENCE:

  1. It is a second, hand-maintained copy of the authoritative list in helios/src/core/cache.rs:1589–1603 (Root::open: "blobs", "blobs/legacy", "models", "refs", "sources", "origins", "staging/incoming", "staging/wrapped", "staging/trees", "locks/models", "locks/entries", "locks/blobs", "locks/staging"). The copy is already incomplete (no "blobs/legacy") and will drift.
  2. This is exactly the objection that left PR #147 in CHANGES_REQUESTED (yatesdr 2026-11-18: reserved names must come from the owning modules) — the dossier records it.
  3. After this PR the only production call to cache::evict is flare-cli/src/orbit/agent.rs:1461, in the branch reached only when kind is NOT "core"/"package" (the core/package branch returns early at agent.rs:1443–1455). So unit.parent() is always <agent cache>/bin; the managed list is unreachable in production and is only exercised by the new unit test evict_never_removes_managed_helios_cache_subdirectories (core_cache.rs:1939+).

FIX: delete the const, the managed binding, the !managed condition in evict, and that test. If #361's stated end state ("remove the directory scan and the skip list") is wanted, delete the scan instead of guarding it. AGENTS.md line 188-193: "Do not add frameworks, extension points, speculative compatibility, fallback layers..."