nikivdev/code · error
moon build failed for AI task '{}' with status {}
Error message
moon build failed for AI task '{}' with status {} What it means
Thrown by build_task_cached in src/ai_tasks.rs when the `moon build` invocation for an AI task exits with a non-zero status. The cached binary could not be produced, so the cached-run path aborts.
Source
Thrown at src/ai_tasks.rs:336
let mut cmd = Command::new("moon");
cmd.arg("build")
.arg("--target")
.arg("native")
.arg("--release");
if std::env::var("FLOW_AI_TASK_NO_FROZEN").is_err() {
cmd.arg("--frozen");
}
cmd.arg(&run_path).current_dir(&workspace_dir);
let status = cmd.status().with_context(|| {
format!(
"failed to build AI task '{}' with moon build (workspace: {})",
task.id,
workspace_dir.display()
)
})?;
if !status.success() {
bail!(
"moon build failed for AI task '{}' with status {}",
task.id,
status
);
}
let built_binary = find_built_binary(&workspace_dir)?;
fs::copy(&built_binary, &binary_path).with_context(|| {
format!(
"failed to copy built binary {} -> {}",
built_binary.display(),
binary_path.display()
)
})?;
#[cfg(unix)]
{
let mut perms = fs::metadata(&binary_path)
.with_context(|| format!("failed to stat {}", binary_path.display()))?View on GitHub (pinned to a747e741ae)
Solutions
- Inspect moon build output above the error for the compiler diagnostics
- Run `moon build` manually in the workspace and fix the reported errors
- Update/refresh dependencies (moon update) or the moon toolchain, clean _build, and retry
Defensive patterns
Strategy: try-catch
Try / catch
match build_task_cached(task, root, force) {
Ok(a) => Ok(a),
Err(e) if e.to_string().contains("moon build failed") => {
eprintln!("Fix compiler errors shown by moon build output, then retry.");
Err(e)
}
Err(e) => Err(e),
} Prevention
- Run `moon build` in CI to catch build breakage early
- Keep moon dependencies updated and the toolchain version pinned
- Clean _build when the moon version changes
When it happens
Trigger: build_task_cached (via run_task_cached/run_task_cached_output) shells out to moon build in the workspace and the compiler/build fails — syntax errors, missing deps, or target config problems.
Common situations: Broken MoonBit source after refactors; unresolved moon module dependencies; mismatched moon toolchain version; stale _build directory interfering.
Related errors
- AI task '{}' failed with status {}
- AI task '{}' has no moon workspace root; cannot build cached
- moon build output directory missing: {}
- no task name provided
- no previous task found for this project
AI-assisted analysis of nikivdev/code@a747e741ae (2026-09-01).
Data as JSON: /api/errors/9d8c1c2f539b41c0.
Report an issue: GitHub.