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

Raw Markdown for agents: https://autobot.eidonix.com/p/8127bdba-19c9-498a-b7c0-e31f6ae63d64.md

#1 [high] Change shape: RevisionLookupError wrapper, private, error-path only

PR #603, head a3ec4b6, one file flare/src/hub.rs (+41/-1).

New type at flare/src/hub.rs:3398-3419:

#[derive(Debug)]
struct RevisionLookupError {
    repository: String,
    revision: String,
    source: Box<dyn std::error::Error>,
}
impl std::fmt::Display for RevisionLookupError {
    fn fmt(&self, formatter) -> ... {
        write!(formatter, "cannot resolve {}@{}: {}", self.repository, self.revision, self.source)
    }
}
impl std::error::Error for RevisionLookupError {
    fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { Some(self.source.as_ref()) }
}

Guard inside resolve_primary_target, flare/src/hub.rs:3427-3441:

let info = resolve_revision(api, repo, progress).map_err(|source| {
    if matches!(
        source.downcast_ref::<ApiError>(),
        Some(ApiError::RequestError(error))
            if matches!(error.as_ref(), ureq::Error::StatusCode(404))
    ) {
        Box::new(RevisionLookupError { repository: repo.url(), revision: repo.revision().to_owned(), source })
    } else { source }
})?;

Type alias: type Result<T> = std::result::Result<T, Box<dyn std::error::Error>> (hub.rs:29) — matches Box, so the struct need not be Send/Sync; controllers stringify (flare-cli/src/orbit/agent.rs:135 .map_err(|e| e.to_string()), controller.rs:1308 return Err(error.to_string())).

Earlier retry/fallback decisions happen inside resolve_revision (hub.rs:3374-3396) before the wrap, so retry+-tp1 logic is untouched. Type-based branching on ApiError exists ONLY at hub.rs:3429 (verified: search_code downcast_ref shows no other ApiError downcast), and only PublisherKeyRequired drives retry (controller.rs:1302-1334, flare-cli/src/hub.rs:72-90) — so the wrap cannot change control flow. Error path only: no locks, no allocations on hot path, no shared state. Concurrency/systemic risk: none. No panic possible.

Note: Display prints the inner error without the source() chain, so full chain is only visible to walkers; nothing in the repo walks it (search for .source() in flare-cli/src: no matches).

#2 [high] Duplicate/conflicting message: update check reports same repo@revision differently

flare/src/hub.rs:2276-2280 (unchanged by PR):

let revision = requested.revision.as_deref().unwrap();
log::info!("Checking model origin: {}@{revision}", origin.repository);
let repo = Repo::with_revision(origin.repository.clone(), RepoType::Model, revision.into());
let info = resolve_revision(&api, &repo, None)
    .map_err(|error| format!("cannot check {}@{revision} for updates: {error}; the local version is unchanged (use --offline to skip the check)", origin.repository))?;

Impact: for a 404 on the same resolve_revision helper, flare download/run now says "cannot resolve ORG/NAME@rev: ... 404", while the recorded-origin update check says "cannot check ORG/NAME@rev for updates: RequestError(StatusCode(404)) ...". Two different headline messages for one failure mode; #603 is the second PR abutted by #489's reviewer (original-el8, 2026-11-28, item 3: "should wrap like :1620"). The PR body scopes this away ("The resolver completes its existing retry and -tp1 fallback decisions before the diagnostic adds context") but does not state why the sibling call site is excluded. In-repo proof the asymmetry persists: test model_refresh_failed_update_keeps_default at flare/src/hub.rs:6358-6390 scripts 404 for both /revision/gb10 and /revision/gb10-tp1 and asserts only error.contains("--offline") — it never asserts the repository/revision, and would still see the bare RequestError(StatusCode(404)). Fix: either wrap in resolve_revision itself (covers all three call sites: resolve_primary_target hub.rs:3427, refresh_model_at hub.rs:2279, and leaves RevisionClient::revision hub.rs:2130-2151 separate) keeping retry/alias logic inside, or add a second RevisionLookupError in refresh_model_at and drop the duplicated prefix text. Severity: Major.

#6 [high] Research summary

Reviewed PR #603 (flare/src/hub.rs only, +41/−1) for correctness, system-level consequences, contracts and test/claim accuracy, opening the changed function, all three resolution call sites, the console/orbit consumers, docs contracts and the tests in full context.

Sound in most areas. The change is error-path only: a private RevisionLookupError (hub.rs:3398-3419) wrapped around resolve_revision in resolve_primary_target (hub.rs:3427-3441) when and only when the error is ApiError::RequestError(ureq::Error::StatusCode(404)). Retry and -tp1 fallback happen inside resolve_revision (hub.rs:3374-3396) before the wrap, so ordering and decisions are preserved. No locks, allocations, shared state, buffering or cancellation semantics are touched; grep confirms ApiError is never downcast anywhere else, and only PublisherKeyRequired drives control flow (controller.rs:1302-1334, flare-cli/src/hub.rs:72-90), so failure-propagation blast radius is unchanged. No panic path, no platform asymmetry (the Unix/Windows split at hub.rs:844-870 is untouched), no public/wire/captured-graph contract change and no per-model branch. Charter-compliant footprint.

One Major finding: the same defect is reported two conflicting ways. refresh_model_at (hub.rs:2276-2280) calls the same resolve_revision and still formats its own cannot check {repo}@{revision} for updates: {error} while leaving the bare RequestError(StatusCode(404)) unwrapped — and the existing test for it (hub.rs:6358-6390) asserts only contains("--offline"), so the asymmetry persists untested. Fix: wrap inside resolve_revision so all call sites share one message, or add the same wrap at hub.rs:2279 and drop the duplicated prefix.

Minors: (1) the status-only guard also fires for gated/private repositories, which the Hub answers with 404, so the message can name a revision that exists while the real problem is credentials; the disambiguating token log (hub.rs:3344-3348) is info-level while the error goes to stderr. (2) The new assertion is bolted into permanent_resolution_failures_are_not_retried (hub.rs:8619-8622) rather than a dedicated test, and only pins the substring 404, not the "retains HTTP 404" wording the PR description claims (the rendered <ureq::Error as Display> text could not be verified in-repo). (3) No doc or docs/TODO.txt entry for the new operator-facing message, which is the gap #489's reviewer explicitly asked to be recorded, and #603 never cites its sibling's instruction.

Verdict: correct, minimal, low-risk diagnostic; the substantive issue is uneven application across resolution call sites, not the wrapper itself.

#7 [high] Consolidated findings with severity, quotes, impacts, fixes

Lens: Correctness, Contracts & System-Level Consequences. Basis: full read of the diff, resolve_revision/resolve_primary_target/refresh_model_at, all callers (hub.rs:434, 2279, 2130-2151 / acquire_watched 13910, acquire_update 13941, refresh_model 13971), consumers (flare-cli/src/hub.rs:30-153, flare-cli/src/orbit/agent.rs:115-141, flare/src/controller.rs:1279-1338, flare/src/application.rs:313-339, flare-cli/src/main.rs:60-68, 435-450), tests (hub.rs:8572-8625, 6358-6390, 12630-12700), docs (cli-design.md:893-990, multi-host.md:536-553), AGENTS.md:52-60, 515-520, .agents/skills/repo-prose/SKILL.md.

FINDING 1 — Major — uneven application; two conflicting messages for one failure flare/src/hub.rs:2276-2280 let revision = requested.revision.as_deref().unwrap(); log::info!("Checking model origin: {}@{revision}", origin.repository); let repo = Repo::with_revision(origin.repository.clone(), RepoType::Model, revision.into()); let info = resolve_revision(&api, &repo, None) .map_err(|error| format!("cannot check {}@{revision} for updates: {error}; the local version is unchanged (use --offline to skip the check)", origin.repository))?; Impact: the recorded-origin update check reaches the same resolve_revision helper but still flattens the bare 404 into a String, so flare run on an installed model says "cannot check ORG/NAME@rev for updates: RequestError(StatusCode(404)) …" while flare download says "cannot resolve ORG/NAME@rev: …". Same failure, two vocabularies; the operator still cannot tell which status applies. Untested: model_refresh_failed_update_keeps_default (hub.rs:6358-6390) scripts 404 for both /revision/gb10 and /revision/gb10-tp1 but asserts only error.contains("--offline"). Fix: move the wrap into resolve_revision (keeping retry and -tp1 logic inside, i.e. wrap only the terminal arm), or add the identical wrap at :2279 and drop the duplicated cannot check …@… prefix.

FINDING 2 — Minor — 404 also means private/gated; message asserts a reference the user may have right flare/src/hub.rs:3427-3441 guard is status-only. Hub answers 404 (not 401) for a private/gated repository on an unauthenticated request. The disambiguator exists but is info-level: hub.rs:3344-3348 None => { log::info!("Connecting to Hugging Face without an access token; authenticate with \hf auth login`, `HF_TOKEN`, or `--token-file` for higher rate limits") }, while the error itself goes to stderr via flare-cli/src/main.rs:64 eprintln!("Error: {error}"). Impact: with no token the new text points the operator at the revision when the fix is hf auth login`. Docs already treat this as a distinct condition (cli-design.md:948 "otherwise unauthenticated"). Fix: add a credentials clause to the Display/wrap when no token was resolved, e.g. "cannot resolve ORG/NAME@rev: … 404 (not found, or not authorized for the current credentials)". Keep the wrap status-only.

FINDING 3 — Minor — test placement and weak assertion flare/src/hub.rs:8619-8622 assert!(error.contains(&status.to_string()), "{error}"); if status == 404 { assert!(error.contains(&format!("owner/model@{revision}")), "{error}"); } Impact: the new diagnostic has no test of its own; it is asserted inside permanent_resolution_failures_are_not_retried (contract = retry behavior). It does genuinely cover two 404 rows (gb10-tp1 after the alias attempt, and custom), and the 401 row proves the wrap is status-gated, so coverage exists. But only the substring "404" is pinned, not the "retains HTTP 404" wording the PR claims, and the error chain (Error::source, hub.rs:3415-3419) is never asserted although nothing in the repo walks it (no .source() in flare-cli/src). Path is exercised only via #[cfg(test)] fetch_primary (hub.rs:3353-3361), not through the real CLI entry. Fix: split into a dedicated revision_lookup_failure_names_the_reference test asserting the full prefix cannot resolve owner/model@gb10: and that the source chain yields the 404; add the same assertion to the refresh test.

FINDING 4 — Minor — no record of the defect where the repo requires it AGENTS.md:57-60 "Record unresolved defects, unrun checks, and pending measurements in docs/TODO.txt"; docs/TODO.txt has no 404/revision entry (only unrelated :306). docs/cli-design.md:920-932 stops at "tries the corresponding -tp1 revision if the initial revision lookup returns HTTP 404" and does not specify the message; docs/multi-host.md:536-553 Failures table has no row for it. #489's reviewer (original-el8, 2026-11-28, item 3) asked for exactly this: "The bare HTTP 404 reporting gap … is an unresolved defect and belongs in docs/TODO.txt" and "should wrap like :1620". #603 addresses the code half and references neither the instruction nor #489's TODO ask. Impact: the operator-facing string becomes a de-facto contract with no specification and no tracked close condition. Fix: either add the docs/TODO.txt entry and the multi-host Failures row, or state in the PR that the TODO entry is being handled separately — and cite #489 so the reviewer can see the instruction is satisfied.

CLAIM-ACCURACY NOTES (no separate severity; disclose, do not invent)

AREAS CHECKED AND SOUND (state plainly)

#3 [medium] Diagnostic specificity gap: 404 conflates missing ref with private/gated repo

flare/src/hub.rs:3427-3441, status-only guard. ApiError::RequestError(StatusCode(404)) is raised by hf-hub (flare/Cargo.toml:27, hf-hub 0.5) both for a missing ref/repo AND for a gated/private repository when the request is unauthenticated (Hub returns 404 rather than 401 to avoid disclosing private repo existence). Verified in-repo that the codebase itself treats unauthenticated access as a distinct condition: docs/cli-design.md:948 documents "HF_TOKEN, ... otherwise unauthenticated", and flare/src/hub.rs:3344-3348 logs "Connecting to Hugging Face without an access token; authenticate with hf auth login, HF_TOKEN, or --token-file for higher rate limits".

After the change an operator with no token who typo'd nothing sees cannot resolve ORG/NAME@gb10: ... 404, which the PR body equates with "which reference the agent attempted to resolve". The message names a revision that may exist; it does not distinguish "revision absent" from "repository not visible to this credential".

Mitigation the PR already has: the token-precedence log lines (hub.rs:3334-3348) fire in the same run, but they are log::info! and any non-info filter hides them, while the error line is eprintln at flare-cli/src/main.rs:64.

Fix: keep the wrap status-only (correct, as the PR intends), but add one clause in the Display or in the wrap site when no token is in play, e.g. via the already-computed token(options) result, saying the reference was not found or not authorized for the current credentials. Severity: Minor (accuracy of the diagnostic, not of behavior).

#4 [medium] Test coverage: new assertion bolted onto permanent_resolution_failures_are_not_retried

Test change is flare/src/hub.rs:8619-8622, inside existing for (revision, status) in [("gb10", 401), ("gb10-tp1", 404), ("custom", 404)] loop (hub.rs:8601-8625):

assert!(error.contains(&status.to_string()), "{error}");
if status == 404 {
    assert!(error.contains(&format!("owner/model@{revision}")), "{error}");
}

(a) It is inside a broader test (permanent_resolution_failures_are_not_retried) whose contract is retry behavior; the new diagnostic has no test of its own, but the assertion is genuinely exercised for two of the three loop rows and asserts repo@revision, so coverage of the new path exists (both plain custom and post-alias-attempt gb10-tp1). (b) Row ("gb10", 401) never reaches the wrap, so the 401 path is provably untouched — good. (c) Not asserted anywhere: the new message still contains HTTP 404 (the 404 text comes from Display for ureq::Error, which prints "http status: 404" in ureq 3.x) — only the bare status.to_string() "404" is asserted, which would also pass for an unrelated 404 elsewhere in the string. (d) Missing test: the sibling 404 site refresh_model_at (hub.rs:2279) and RevisionClient::revision (hub.rs:2130-2151) have no repo@revision assertion; see model_refresh_failed_update_keeps_default hub.rs:6358-6390 which only asserts contains("--offline"). Fix: split the diagnostic out of the retry test into revision_lookup_failure_names_the_reference, and add the assertion to the refresh test. Severity: Minor.

#5 [medium] Charter/contract compliance: compliant; docs + TODO + claim-accuracy gaps

Charter/contract review of #603: