nikivdev/code · error
LM Studio returned unknown task: {}
Error message
LM Studio returned unknown task: {} What it means
run_with_tasks receives a task_name (resolved by LM Studio) and looks it up case-insensitively in the discovered task list. If no task matches, it throws 'LM Studio returned unknown task: {task_name}', meaning the model produced a task name that does not exist in the registry.
Source
Thrown at src/task_match.rs:247
let task_list: Vec<_> = tasks.iter().map(|t| t.task.name.as_str()).collect();
bail!(
"No direct match for '{}'. LM Studio error: {}\n\nAvailable tasks:\n {}",
query_display,
e,
task_list.join("\n ")
);
}
};
// Parse the response to get the task name (no args for LLM matches)
(extract_task_name(&response, &tasks)?, Vec::new(), false)
};
// Find the matched task
let matched = tasks
.iter()
.find(|t| t.task.name.eq_ignore_ascii_case(&task_name))
.ok_or_else(|| anyhow::anyhow!("LM Studio returned unknown task: {}", task_name))?;
// Show what was matched
if matched.relative_dir.is_empty() {
println!("Matched: {} – {}", matched.task.name, matched.task.command);
} else {
println!(
"Matched: {} ({}) – {}",
matched.task.name, matched.relative_dir, matched.task.command
);
}
if opts.execute {
// Check if confirmation is needed (only for LLM matches on tasks with confirm_on_match)
let needs_confirm = !was_direct_match && matched.task.confirm_on_match;
if needs_confirm {
print!("Press Enter to confirm, Ctrl+C to cancel: ");
io::stdout().flush()?;View on GitHub (pinned to a747e741ae)
Solutions
- Re-run and inspect the printed candidate list to pick the task manually
- Add/restore the named task to the task config, or fix its spelling there
- Normalize the model output (trim, lowercase, collapse spaces/underscores) before matching
- Constrain the model prompt to output exactly one of the listed task names, or validate against a fuzzy matcher before this error
Example fix
// before
.find(|t| t.task.name.eq_ignore_ascii_case(&task_name))
.ok_or_else(|| anyhow::anyhow!("LM Studio returned unknown task: {}", task_name))?;
// after
let normalized = task_name.trim().to_lowercase().replace(['_', '-'], " ");
tasks.iter().find(|t| t.task.name.trim().to_lowercase().replace(['_', '-'], " ") == normalized)
.ok_or_else(|| anyhow::anyhow!("LM Studio returned unknown task: {} (valid: {:?})", task_name, tasks.iter().map(|t| &t.task.name).collect::<Vec<_>>()))?; Defensive patterns
Strategy: validation
Validate before calling
let valid: Vec<&str> = tasks.iter().map(|t| t.task.name.as_str()).collect();
let norm = task_name.trim().to_lowercase();
if !valid.iter().any(|v| v.eq_ignore_ascii_case(&norm)) {
eprintln!("model proposed unknown task '{}'; valid: {:?}", task_name, valid);
return; // don't dispatch
} Try / catch
match run_with_tasks(task_name) {
Ok(m) => println!("matched {}", m),
Err(e) if e.to_string().contains("unknown task") => {
eprintln!("{}", e);
eprintln!("pick a task from the printed candidate list and re-run");
}
Err(e) => return Err(e),
} Prevention
- Prompt the model with the exact task list and require verbatim output
- Normalize (trim/lowercase) model output before matching
- Keep task names simple and distinct to reduce hallucination surface
- Log the raw model response alongside the error for diagnosis
When it happens
Trigger: Calling run_with_tasks (via run, run_implicit, or run_global) when the LLM's response names a task not present in `tasks` — hallucinated name, truncated output, name changed in config after the model was prompted, or case/format drift the eq_ignore_ascii_case comparison does not cover (extra whitespace, underscores vs spaces).
Common situations: Small/local model hallucinating plausible task names; task removed or renamed in a project's task config; model echoing a command string instead of a task name; fuzzy matching picking a wrong candidate earlier in the pipeline.
Related errors
- No prompt provided. Usage: f agents run {} "your prompt here
- No prompt provided for flow agent.
- agent run requires a non-empty query
- empty resolver command for {}
- resolver {} returned empty output for {}
AI-assisted analysis of nikivdev/code@a747e741ae (2026-09-01).
Data as JSON: /api/errors/7e0c9195a30ebf13.
Report an issue: GitHub.