Subtraction and simplicity report · NVIDIA/hyperflare-inference #603

Raw Markdown for agents: https://autobot.eidonix.com/p/ad14fc66-06a2-47b1-8d49-d5ba2f774603.md

Subtraction, Simplicity & Conventions review — PR #603 "Report the repository and revision on Hub lookup errors"

Scope reviewed: the single changed file, flare/src/hub.rs (+41/−1), in three parts — new private error type (:3398-3419), the map_err wrapper in resolve_primary_target (:3427-3441), and the strengthened fixture assertion (:8620-8622).

Key findings

  1. [high] The new RevisionLookupError type (flare/src/hub.rs:3398-3419) and its ApiError downcast (:3427-3441) are 22 lines of boilerplate for a message string that no consumer reads as a typed error. The type's only advantage over format!(...).into() is Error::source(), and nothing in flare/ or flare-cli/ walks the cause chain: the crate alias is Box<dyn std::error::Error> (flare/src/hub.rs:29), the CLI prints Display only (eprintln!("Error: {error}"), flare-cli/src/main.rs:64), and Orbit flattens to String twice (flare-cli/src/orbit/controller.rs:2533-2536 format!("{node}: {error}"), :2545 errors.push(error.to_string())). The change can be a 6-line map_err, matching the file's dominant idiom.
  2. [medium] The diff is the third inline copy of the "is this a Hub 404" walk over ApiError/ureq::Error::StatusCode(404) in one file — flare/src/hub.rs:2142, :3383, and the new :3431 — while the file already establishes the named-predicate idiom for exactly this (transient_hub_error, flare/src/hub.rs:5460-5472).
  3. [medium] The context lands at the second of two callers of resolve_revision, duplicating an existing hand-written twin. resolve_primary_target gets the new wrap (:3427) while refresh_model_at already writes the same repo@revision context by hand (flare/src/hub.rs:2279-2280). Producing the context inside resolve_revision (:3374-3396) would cover both callers and need no downcast at all, because the 404 arm at :3381 still holds a concrete ApiError.
  4. [low, conventions] The new operator-visible text has no documentation delta. docs/cli-design.md:920-929 specifies the -tp1 404 retry and records behavior but says nothing about the message; AGENTS.md:52-58 treats error text as specification and routes unresolved defects to docs/TODO.txt, which is precisely the path #489's reviewer (original-el8, CHANGES_REQUESTED 2026-11-28) chose and this PR bypasses without adding the entry.
  5. What is already fine: no dead code, no flags/config knobs, no new dependencies, no added fallback branches, no public surface change (the struct is private), and the test change (:8620-8622) is minimal and proportional. The subtraction problem is localized to suggestion 1.

Suggestion 1 [high] — Delete RevisionLookupError; the Error::source() it exists for is never read

flare/src/hub.rs:3398-3419, verbatim (new code):

#[derive(Debug)]
struct RevisionLookupError {
    repository: String,
    revision: String,
    source: Box<dyn std::error::Error>,
}

impl std::fmt::Display for RevisionLookupError {
    fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        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())
    }
}

and its only construction site, 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
        }
    })?;

Evidence that source() is unread:

Concrete replacement — remove the struct and both impl blocks entirely (:3398-3419) and write the wrapper as a one-line format!, deleting the nested matches! guard's boxing branch:

    let info = resolve_revision(api, repo, progress).map_err(|error| {
        if matches!(
            error.downcast_ref::<ApiError>(),
            Some(ApiError::RequestError(error))
                if matches!(error.as_ref(), ureq::Error::StatusCode(404))
        ) {
            format!("cannot resolve {}@{}: {error}", repo.url(), repo.revision()).into()
        } else {
            error
        }
    })?;

Box<dyn Error>: From<String>, and {error} still embeds the original ApiError, so the PR's stated guarantee ("the message retains HTTP 404 without assigning a cause", PR body) is preserved verbatim. Saves ~22 lines plus two hand-written trait impls.

This is the module's dominant pattern, not a taste preference:

AGENTS.md:188-190 ("Reject unsupported abstractions and churn… Do not add frameworks, extension points, speculative compatibility, fallback layers, or configuration switches without a concrete requirement") is the convention this trip: a private typed error whose source() no code reads is a speculative extension point where a formatted string is what the callers actually consume.

Suggestion 2 [medium] — Name the Hub-404 predicate instead of adding a third inline copy

The same match now appears three times in one file. Instance A (pre-existing), flare/src/hub.rs:2141-2146:

        let body = match get(revision) {
            Err(ureq::Error::StatusCode(404)) if tp1_revision_alias(revision) => {
                get(&format!("{revision}-tp1"))?
            }
            result => result?,
        };

Instance B (pre-existing), flare/src/hub.rs:3381-3384:

    let info = match with_transient_retry(|| api.repo(repo.clone()).info()) {
        Err(ApiError::RequestError(error))
            if matches!(error.as_ref(), ureq::Error::StatusCode(404))
                && tp1_revision_alias(revision) =>

Instance C (added by this PR), flare/src/hub.rs:3428-3432:

        if matches!(
            source.downcast_ref::<ApiError>(),
            Some(ApiError::RequestError(error))
                if matches!(error.as_ref(), ureq::Error::StatusCode(404))
        ) {

The repo already establishes the named-predicate idiom over ApiError for this exact purpose, flare/src/hub.rs:5457-5472:

/// Errors from Hub resolution or file identity that may succeed when retried.
/// Authentication, missing repositories, missing files, and malformed responses
/// are permanent and are never retried, so the signed binding is unchanged.
fn transient_hub_error(error: &ApiError) -> bool {
    let ApiError::RequestError(request) = error else {
        return false;
    };
    match request.as_ref() {
        ureq::Error::Timeout(_)
        | ureq::Error::Io(_)
        | ureq::Error::HostNotFound
        | ureq::Error::ConnectionFailed => true,
        ureq::Error::StatusCode(status) => matches!(status, 408 | 429 | 500..=599),
        _ => false,
    }
}

Concrete simplification — add one sibling predicate next to transient_hub_error (:5472) and use it at all three sites:

/// Whether a Hub revision request failed because the reference does not exist.
fn hub_not_found(error: &ApiError) -> bool {
    matches!(error, ApiError::RequestError(request) if matches!(request.as_ref(), ureq::Error::StatusCode(404)))
}

Then B becomes Err(error) if hub_not_found(&error) && tp1_revision_alias(revision) => and C becomes if error.downcast_ref::<ApiError>().is_some_and(hub_not_found). This removes the nested matches! guard at :3428-3432 and — the maintainability point — keeps the retry decision (:3383) and the diagnostic decision (:3431) from drifting apart, since they must stay pinned to the same status to remain truthful about what was retried.

Suggestion 3 [medium] — Put the context where the concrete ApiError still exists; the wrap site duplicates an existing message

The same repo@revision context now exists twice in one file for two callers of one function.

New wrapper, flare/src/hub.rs:3427-3441 (quoted in suggestion 1), applies only to resolve_primary_target (:3421), reached from acquisition and from the test-only fetch_primary_with_progress (:3480).

The other caller already writes it by hand, flare/src/hub.rs:2279-2280:

    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))?;

If the context were produced inside resolve_revision (flare/src/hub.rs:3374-3396), both callers would get it and the entire downcast_ref::<ApiError> guard at :3428-3432 would disappear, because at the retry match on :3381 the error is still a concrete ApiError:

    let info = match with_transient_retry(|| api.repo(repo.clone()).info()) {
        Err(ApiError::RequestError(error))
            if matches!(error.as_ref(), ureq::Error::StatusCode(404))
                && tp1_revision_alias(revision) =>
        {
            check_cancel(progress)?;
            let alias = format!("{revision}-tp1");
            log::info!("Hugging Face revision {revision} returned 404, trying {alias}");
            let repo = Repo::with_revision(repo.url(), RepoType::Model, alias);
            with_transient_retry(|| api.repo(repo.clone()).info())?
        }
        result => result?,
    };

Type information is lost only at the result => result? arm on :3392. A 404 arm there can return the formatted message directly, and refresh_model_at's duplicated {}@{revision} fragment (:2280) then becomes removable, keeping only its unique content ("cannot check … for updates: …; the local version is unchanged (use --offline to skip the check)").

This is offered as placement, not as a correctness claim: the -tp1 naming consequence (a message reporting the originally requested @gb10 after the alias retry also 404s) belongs to the Correctness & Contracts lens; under this lens it is simply a symptom of wrapping outside resolve_revision.

Scope note (state, do not fix here): RevisionClient::revision (flare/src/hub.rs:2130-2151) still returns a bare ureq::Error::StatusCode(404); scan_revisions swallows it (:2171, let Ok(remote) = self.revision(&key.0, &key.1) else { continue; };), and the update check check_core_updates (flare-cli/src/cache_commands.rs:272 (not opened)) rides that path. The cited diagnostic gap therefore narrows for flare download / flare run / flare acquire and Orbit agent downloads rather than closing repo-wide — a scoping sentence in the PR body would be honest and costs nothing.

Suggestion 4 [low, conventions] — The new operator-facing message has no specification clause

The PR changes an operator-visible message but touches no documentation. docs/cli-design.md:920-929 specifies the -tp1 retry:

An explicit `--revision` overrides `@revision` and hardware detection. It accepts
a branch, tag, or commit, and permits downloading on a machine without NVIDIA
hardware. For any platform revision beginning with `gb`, the shared CLI and
desktop downloader tries the corresponding `-tp1` revision if the initial revision
lookup returns HTTP 404; Ampere (`ga*`) revisions are not retried. Flare

— with no mention of what the resulting failure says. AGENTS.md:52-58: "Every repository document has one or both of two purposes: it specifies the architecture… Record unresolved defects, unrun checks, and pending measurements in docs/TODO.txt, not in design documents." A one-clause addition at docs/cli-design.md:924-926 stating that a failed lookup reports the attempted repository@revision while retaining the HTTP status would keep the specification and the message aligned. The related process gap: #489 (the only place this defect is recorded) is a docs PR whose reviewer asked for a docs/TODO.txt entry, and #603 adds none and does not link back.


What is already lean (no action)

Open questions