nikivdev/code · error · anyhow::Error

ai-task.sh failed: {}

Error message

ai-task.sh failed: {}

What it means

`call_ai_explain` delegates explanation to an external `ai-task.sh` script. When the script runs but exits non-zero, this error surfaces the script's trimmed stderr. It is an integration failure of the external AI helper, not a git or parsing problem.

Source

Thrown at src/explain_commits.rs:246

            "--prompt",
            &prompt,
            "--max-steps",
            "5",
        ])
        .output();

    match output {
        Ok(out) if out.status.success() => {
            let text = String::from_utf8_lossy(&out.stdout).trim().to_string();
            if text.is_empty() {
                Ok("(AI returned empty response)".to_string())
            } else {
                Ok(text)
            }
        }
        Ok(out) => {
            let stderr = String::from_utf8_lossy(&out.stderr);
            bail!("ai-task.sh failed: {}", stderr.trim());
        }
        Err(e) => {
            bail!("failed to run ai-task.sh: {e}");
        }
    }
}

// -- Markdown output --

fn slugify(s: &str) -> String {
    s.chars()
        .map(|c| {
            if c.is_alphanumeric() || c == '-' {
                c.to_ascii_lowercase()
            } else if c == ' ' || c == '_' || c == '/' {
                '-'
            } else {
                '\0'

View on GitHub (pinned to a747e741ae)

Solutions

  1. Run ai-task.sh manually with the same input to see its full stderr
  2. Check the AI provider credentials/keys the script relies on (env vars like API keys)
  3. Verify script config/quota — rate limits or exhausted credits commonly cause non-zero exits
  4. Update or repair ai-task.sh if it references a changed provider API
  5. As a workaround, write the commit explanation manually without the AI path
Defensive patterns

Strategy: fallback

Validate before calling

// check the AI script and its credentials before invoking
let cfg = std::path::Path::new("scripts/ai-task.sh");
if !cfg.exists() { bail!("ai-task.sh missing — AI explanation unavailable"); }
if std::env::var("AI_API_KEY").is_err() { bail!("AI_API_KEY not set — ai-task.sh will fail"); }

Try / catch

match result {
    Err(e) if e.to_string().starts_with("ai-task.sh failed") => {
        eprintln!("AI explanation unavailable ({e}); falling back to raw commit list");
        print_raw_commit_list()?;
    }
    other => other?,
}

Prevention

When it happens

Trigger: The spawned ai-task.sh process completes with a non-zero exit status (the `Ok(out)` arm at src/explain_commits.rs:246); stderr from the script is included in the message.

Common situations: AI provider API key missing/expired inside the script; ai-task.sh updated to a version requiring new env vars or config; network outage inside the script; script's own error paths (prompt too large, quota exhausted).

Related errors


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