nikivdev/code · error

Commit blocked by invariant gate ({} finding(s))

Error message

Commit blocked by invariant gate ({} finding(s))

What it means

The invariant gate evaluates a list of findings against project invariants before commit. If any finding is blocking (has_blocking) and the gate mode is "block", the commit is aborted with the total finding count in the message; in "warn" mode it only prints a warning. It encodes team-defined invariants as hard commit prerequisites.

Source

Thrown at src/commit.rs:3388

        .iter()
        .any(|f| f.severity == "critical" || f.severity == "warning");

    // Print findings.
    if !findings.is_empty() {
        eprintln!();
        eprintln!("  invariants: {} finding(s)", findings.len());
        for f in &findings {
            let loc = f.file.as_deref().unwrap_or("(diff)");
            eprintln!(
                "    [{}:{}] {} — {}",
                f.severity, f.category, loc, f.message
            );
        }
    }

    let pass = !has_blocking;
    if !pass && mode == "block" {
        bail!(
            "Commit blocked by invariant gate ({} finding(s))",
            findings.len()
        );
    }
    if !pass {
        eprintln!("  invariants: warning only (mode=warn)");
    }

    Ok(InvariantGateReport { findings })
}

/// Check a package.json for dependencies not on the approved list.
fn check_unapproved_deps(
    package_json: &str,
    approved: &[String],
    file_path: &str,
    findings: &mut Vec<InvariantFinding>,
) {

View on GitHub (pinned to a747e741ae)

Solutions

  1. Read the printed invariant findings and fix each violating spot in your changes.
  2. Re-run the invariant check locally (if exposed) until it reports zero findings, then commit.
  3. If a finding is a false positive, update or scope the invariant rule in config.
  4. Switch mode to "warn" only with team approval; do not bypass shared policy.

Example fix

// before: invariant forbids unwrap() in src/
let v = config.get("k").unwrap();
// after
let v = config.get("k").context("missing key k")?;
Defensive patterns

Strategy: validation

Validate before calling

// Run the invariant check (if exposed) before committing and require zero blocking findings
let findings = run_invariant_check()?;
let has_blocking = findings.iter().any(|f| f.is_blocking);
if has_blocking {
    eprintln!("fix {} blocking invariant finding(s) before committing", findings.len());
}

Try / catch

match commit_flow() {
    Err(e) if e.to_string().starts_with("Commit blocked by invariant gate") => {
        eprintln!("address each printed invariant finding, then re-commit");
    }
    other => other?,
}

Prevention

When it happens

Trigger: Committing when the invariant runner produced findings (e.g. forbidden patterns, missing markers, structural violations) and mode == "block"; the message interpolates findings.len().

Common situations: Introducing code that violates repo invariants (disallowed APIs, missing tests tags, oversized functions); newly added invariants flagging pre-existing code; stale config after invariant rule updates.

Related errors


AI-assisted analysis of nikivdev/code@a747e741ae (2026-09-01). Data as JSON: /api/errors/0524103302711102. Report an issue: GitHub.