{"record":{"id":"5be6a4d34112a88f","repo":"nikivdev/code","slug":"ai-auto-fix-failed","errorCode":null,"errorMessage":"ai auto-fix failed","messagePattern":"ai auto-fix failed","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/commit.rs","lineNumber":488,"sourceCode":"    Ok(!scan_diff_for_secrets(repo_root).is_empty())\n}\n\nfn run_fix_f_commit_ai(repo_root: &Path, task: &str) -> Result<()> {\n    if which::which(\"ai\").is_err() {\n        bail!(\"ai not found in PATH\");\n    }\n\n    let status = Command::new(\"ai\")\n        .args([\"--prompt\", task])\n        .current_dir(repo_root)\n        .stdin(Stdio::inherit())\n        .stdout(Stdio::inherit())\n        .stderr(Stdio::inherit())\n        .status()\n        .context(\"failed to run ai\")?;\n\n    if !status.success() {\n        bail!(\"ai auto-fix failed\");\n    }\n\n    Ok(())\n}\n\nfn build_fix_f_commit_task(findings: &[(String, usize, String, String)]) -> String {\n    let mut summary = String::new();\n    for (file, line, pattern, matched) in findings {\n        summary.push_str(&format!(\n            \"- {}:{} — {} ({})\\n\",\n            file, line, pattern, matched\n        ));\n    }\n\n    let task = format!(\n        \"Fix f commit secret detection.\\n\\n\\\nFindings:\\n{summary}\\n\\\nPlease remove or mask real secrets, replace with placeholders if needed, \\","sourceCodeStart":470,"sourceCodeEnd":506,"githubUrl":"https://github.com/nikivdev/code/blob/a747e741ae92c09071d0ae946ab48488adcff1ce/src/commit.rs#L470-L506","documentation":"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.","triggerScenarios":"`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.","commonSituations":"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.","solutions":["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).","Fix the ai CLI's own configuration/auth (e.g. its API key) and retry the commit flow.","Apply the secret fixes manually (edit files per the findings) and re-run the commit.","Set `FLOW_FIX_COMMIT_AGENT=off` to skip the AI path entirely and remediate by hand."],"exampleFix":"// before: relies on ai CLI, which fails\nrun_fix_f_commit_ai(repo_root, &task)?;\n// after: skip the flaky AI path and fix manually\n// $ FLOW_FIX_COMMIT_AGENT=off flow commit ...","handlingStrategy":"fallback","validationCode":"// smoke-test the ai CLI with a trivial prompt before the real fix task\nlet ok = std::process::Command::new(\"ai\")\n    .args([\"--prompt\", \"reply with ok\"])\n    .status()\n    .map(|s| s.success())\n    .unwrap_or(false);\nif !ok { eprintln!(\"ai CLI is failing; fix its auth/config first\"); }","typeGuard":null,"tryCatchPattern":"match run_fix_f_commit_ai(repo_root, task) {\n    Err(e) if e.to_string().contains(\"ai auto-fix failed\") => {\n        // fallback: manual remediation from the printed findings\n        eprintln!(\"AI fix failed; redact findings manually and re-run\");\n    }\n    Err(e) => return Err(e),\n    Ok(_) => {}\n}","preventionTips":["Keep the ai CLI's own credentials/config valid — its failures surface as this error","Test the ai CLI interactively once before relying on it in the commit flow","Provide a manual redaction checklist as the fallback for CI runs","Set FLOW_FIX_COMMIT_AGENT=off where the AI path is not dependable"],"tags":["external-process","cli","secrets","exit-code"],"backgroundTag":"external-command-nonzero-exit","analyzedSha":"a747e741ae92c09071d0ae946ab48488adcff1ce","analyzedAt":"2026-09-01T22:43:55.719Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}