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

  1. Re-run and inspect the printed candidate list to pick the task manually
  2. Add/restore the named task to the task config, or fix its spelling there
  3. Normalize the model output (trim, lowercase, collapse spaces/underscores) before matching
  4. 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

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


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