nikivdev/code · error

ai auto-fix failed

Error message

ai auto-fix failed

What it means

This error is raised by `run_fix_f_commit_ai` after spawning the external `ai --prompt <task>` process with inherited stdio: the command ran (no spawn error) but exited with a non-zero status. The library maps that to 'ai auto-fix failed' so the secret-fix flow aborts and the user can fall back to manual remediation.

Source

Thrown at src/commit.rs:488

    Ok(!scan_diff_for_secrets(repo_root).is_empty())
}

fn run_fix_f_commit_ai(repo_root: &Path, task: &str) -> Result<()> {
    if which::which("ai").is_err() {
        bail!("ai not found in PATH");
    }

    let status = Command::new("ai")
        .args(["--prompt", task])
        .current_dir(repo_root)
        .stdin(Stdio::inherit())
        .stdout(Stdio::inherit())
        .stderr(Stdio::inherit())
        .status()
        .context("failed to run ai")?;

    if !status.success() {
        bail!("ai auto-fix failed");
    }

    Ok(())
}

fn build_fix_f_commit_task(findings: &[(String, usize, String, String)]) -> String {
    let mut summary = String::new();
    for (file, line, pattern, matched) in findings {
        summary.push_str(&format!(
            "- {}:{} — {} ({})\n",
            file, line, pattern, matched
        ));
    }

    let task = format!(
        "Fix f commit secret detection.\n\n\
Findings:\n{summary}\n\
Please remove or mask real secrets, replace with placeholders if needed, \

View on GitHub (pinned to a747e741ae)

Solutions

  1. Re-run the ai command manually with the printed task prompt to see the underlying error output (stdio is inherited, so the cause was shown above this error).
  2. Fix the ai CLI's own configuration/auth (e.g. its API key) and retry the commit flow.
  3. Apply the secret fixes manually (edit files per the findings) and re-run the commit.
  4. Set `FLOW_FIX_COMMIT_AGENT=off` to skip the AI path entirely and remediate by hand.

Example fix

// before: relies on ai CLI, which fails
run_fix_f_commit_ai(repo_root, &task)?;
// after: skip the flaky AI path and fix manually
// $ FLOW_FIX_COMMIT_AGENT=off flow commit ...
Defensive patterns

Strategy: fallback

Validate before calling

// smoke-test the ai CLI with a trivial prompt before the real fix task
let ok = std::process::Command::new("ai")
    .args(["--prompt", "reply with ok"])
    .status()
    .map(|s| s.success())
    .unwrap_or(false);
if !ok { eprintln!("ai CLI is failing; fix its auth/config first"); }

Try / catch

match run_fix_f_commit_ai(repo_root, task) {
    Err(e) if e.to_string().contains("ai auto-fix failed") => {
        // fallback: manual remediation from the printed findings
        eprintln!("AI fix failed; redact findings manually and re-run");
    }
    Err(e) => return Err(e),
    Ok(_) => {}
}

Prevention

When it happens

Trigger: `warn_secrets_in_diff` invokes `run_fix_f_commit_ai`; `Command::new("ai").args(["--prompt", task]).status()` succeeds in spawning but `status.success()` is false — e.g. the ai CLI hit an API error, was denied auth, or the user aborted the interactive session (Ctrl-C), producing a non-zero exit code.

Common situations: The ai CLI's own API credentials are missing/expired, the generated fix task fails validation inside the tool, network outage while the AI tool calls its backend, or the user cancels the interactive AI session causing a non-zero exit.

Related errors


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