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

Raw Markdown for agents: https://autobot.eidonix.com/p/9768a6e3-2ac3-4c0d-b03d-94c789b7569d.md

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

Head a3ec4b6e; one changed file, flare/src/hub.rs (+41/−1). The diff adds one map_err wrapper in resolve_primary_target and a 3-line assertion inside one existing test loop.

Key findings

  1. High — ~23 of the 41 added lines are dead typed-error machinery. RevisionLookupError (flare/src/hub.rs:3398-3419) has exactly one construction site and zero readers; its Display already interpolates the source string that Error::source() re-exports. The file's own idiom for this exact wrapper is format!(...).into(). Delete the struct and collapse the map_err to a 6-line closure: net ≈30 lines removed, no behavior or message change, existing test unaffected. Backed by AGENTS.md:188-193.
  2. Medium (do not block) — the new guard is the third verbatim copy of the same 404 test in ~1300 lines (:3383 pre-existing, :2142 pre-existing, :3431 new). The file already owns this classification next door in transient_hub_error (:5460-5472); one fn hub_404(&ureq::Error) -> bool collapses the sites and makes the two 404 literals in resolve_revision self-documenting. Optional on its own; natural to do together with finding 1.
  3. Low — the new items carry no doc comment while both neighbouring helpers do (transient_hub_error :5457-5459, transport_hint :5508-5510), and AGENTS.md:43-50 requires the prose skill for code-produced text including errors. A /// line on the replacement helper fixes this for free.
  4. Everything else is lean. No new flags, no HubOptions field, no env read, no fallback branch, no unused imports, no duplicated retry logic; the retry and -tp1 decisions still run first. The test delta is 3 lines inside an existing loop and is not worth restructuring.

Finding 1 (high) — delete RevisionLookupError; the wrapper should be a format! in map_err

The code to delete — 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: &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())
    }
}

Its sole use — 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
        }
    })?;

Why it is dead plumbing (verified this run)

The replacement

Follow the same file's precedent. transport_hint at flare/src/hub.rs:5511-5521 is the established shape — early-return the original error, then format! and .into():

fn transport_hint(root: &Path, error: Box<dyn std::error::Error>) -> Box<dyn std::error::Error> {
    let text = error.to_string();
    if !content_failure(&text) {
        return error;
    }
    format!(
        "{text}; no transport bytes were removed. Inspect {} with `flare models downloads` ...",
        root.display()
    )
    .into()
}

refresh_model_at already wraps the same resolve_revision result with a one-line format! (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))?;

So the whole added surface at :3427-3441 becomes six lines:

    let info = resolve_revision(api, repo, progress).map_err(|error| {
        if !hub_404(&error) {
            return error;
        }
        format!("cannot resolve {}@{}: {error}", repo.url(), repo.revision()).into()
    })?;

(A named helper beside transport_hint is equally acceptable and gives a /// doc-comment slot, which finding 3 wants.)

Test compatibility: the new assertion at flare/src/hub.rs:8620-8622

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

only checks contains("owner/model@{revision}") on the rendered string. The replacement produces byte-identical text, so the test stands unchanged.

Cost of not simplifying: the two remaining resolution sites — refresh_model_at (:2279-2280) and RevisionClient::revision (:2130-2151) — would each need a 23-line struct copy to gain the same diagnostic, versus two lines with the closure. That asymmetry is the concrete, demonstrable cost argument.


Finding 2 (medium, optional) — third copy of the 404 test; name the classification once

Three sites, verbatim:

flare/src/hub.rs:3382-3384 (pre-existing, inside resolve_revision):

        Err(ApiError::RequestError(error))
            if matches!(error.as_ref(), ureq::Error::StatusCode(404))
                && tp1_revision_alias(revision) =>

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

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

flare/src/hub.rs:2141-2143 (pre-existing, RevisionClient::revision):

        let body = match get(revision) {
            Err(ureq::Error::StatusCode(404)) if tp1_revision_alias(revision) => {

The file already owns the neighbouring classification with a doc comment — 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 {

Add the positive counterpart beside it and use it at both ApiError-shaped sites:

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

Then :3382-3384 keeps only if hub_404(&error) && tp1_revision_alias(revision) and the new closure reads if !hub_404(&error). Note this is genuine simplification, not refactoring churn: it removes the duplication the PR itself adds and makes the two 404 literals in one 40-line neighbourhood differ only in their -tp1 condition. If reviewers prefer the smallest possible diff, this can be dropped — finding 1 is the bulk of the value.


Finding 3 (low) — the new items are the only undocumented ones in the neighbourhood

flare/src/hub.rs:3398 opens straight into #[derive(Debug)] struct RevisionLookupError, while transient_hub_error (:5457-5459) and transport_hint (:5508-5510) both lead with /// prose explaining why the wrapper exists. AGENTS.md:43-50 requires the repository prose skill for "docstrings, names, errors" produced by code. Folding this into finding 1 (a /// on the replacement helper) costs one line and removes the inconsistency.


What this diff does not add — the rest is lean, stated plainly

Checked and clean; recording it so the report does not manufacture nitpicks:

  1. No knobs, no branches. The production delta is one map_err closure plus a private struct. No flag, no HubOptions field (use crate::options::HubOptions; at :27 untouched), no environment read (which would violate AGENTS.md:452-455), no fallback path.
  2. No unused imports or dead leftovers. ApiError was already imported (flare/src/hub.rs:20) and already used at :3382 and :5460; the new downcast_ref::<ApiError>() adds no import. resolve_revision still has its other caller at :2279.
  3. Retry/fallback ordering is preserved, not duplicated. The wrap sits after with_transient_retry (:3381, :3390) and after the -tp1 fallback (:3383-3391), so no retry logic is copied into the diagnostic. Consequence: the message names the originally requested revision (owner/model@gb10), not @gb10-tp1 — which is what the assertion at :8620-8622 checks via the loop value at :8603.
  4. Test delta is minimal and idiomatic. Three lines guarded by if status == 404 inside the existing for (revision, status) in [("gb10", 401), ("gb10-tp1", 404), ("custom", 404)] loop (flare/src/hub.rs:8603). The guard makes the 401 path provably unwrapped while the 404 iterations prove the wrap, in one loop. Leave it alone.
  5. No existing public abstraction is duplicated. search_code 'cannot resolve' in flare/src yields only :3409 (the new one) plus two unrelated home-directory messages (flare/src/environment.rs:28 (not opened), flare/src/trust.rs:191 (not opened)). The closest analogue, missing_source (flare/src/hub.rs:2527-2544), formats a cache-miss message (core {repository}@{revision} ... is not available in the Flare cache) with no source error — a different error class, correctly not reused.

Net recommendation: one blocking-ish simplification (finding 1, ~30 lines with identical text and an unchanged test), one optional predicate (finding 2), one doc line (finding 3). Beyond that the diff is lean and idiomatic for this file.


Open questions