{"record":{"id":"7e0c9195a30ebf13","repo":"nikivdev/code","slug":"lm-studio-returned-unknown-task","errorCode":null,"errorMessage":"LM Studio returned unknown task: {}","messagePattern":"LM Studio returned unknown task: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/task_match.rs","lineNumber":247,"sourceCode":"                let task_list: Vec<_> = tasks.iter().map(|t| t.task.name.as_str()).collect();\n                bail!(\n                    \"No direct match for '{}'. LM Studio error: {}\\n\\nAvailable tasks:\\n  {}\",\n                    query_display,\n                    e,\n                    task_list.join(\"\\n  \")\n                );\n            }\n        };\n\n        // Parse the response to get the task name (no args for LLM matches)\n        (extract_task_name(&response, &tasks)?, Vec::new(), false)\n    };\n\n    // Find the matched task\n    let matched = tasks\n        .iter()\n        .find(|t| t.task.name.eq_ignore_ascii_case(&task_name))\n        .ok_or_else(|| anyhow::anyhow!(\"LM Studio returned unknown task: {}\", task_name))?;\n\n    // Show what was matched\n    if matched.relative_dir.is_empty() {\n        println!(\"Matched: {} – {}\", matched.task.name, matched.task.command);\n    } else {\n        println!(\n            \"Matched: {} ({}) – {}\",\n            matched.task.name, matched.relative_dir, matched.task.command\n        );\n    }\n\n    if opts.execute {\n        // Check if confirmation is needed (only for LLM matches on tasks with confirm_on_match)\n        let needs_confirm = !was_direct_match && matched.task.confirm_on_match;\n\n        if needs_confirm {\n            print!(\"Press Enter to confirm, Ctrl+C to cancel: \");\n            io::stdout().flush()?;","sourceCodeStart":229,"sourceCodeEnd":265,"githubUrl":"https://github.com/nikivdev/code/blob/a747e741ae92c09071d0ae946ab48488adcff1ce/src/task_match.rs#L229-L265","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","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"],"exampleFix":"// before\n.find(|t| t.task.name.eq_ignore_ascii_case(&task_name))\n.ok_or_else(|| anyhow::anyhow!(\"LM Studio returned unknown task: {}\", task_name))?;\n// after\nlet normalized = task_name.trim().to_lowercase().replace(['_', '-'], \" \");\ntasks.iter().find(|t| t.task.name.trim().to_lowercase().replace(['_', '-'], \" \") == normalized)\n    .ok_or_else(|| anyhow::anyhow!(\"LM Studio returned unknown task: {} (valid: {:?})\", task_name, tasks.iter().map(|t| &t.task.name).collect::<Vec<_>>()))?;","handlingStrategy":"validation","validationCode":"let valid: Vec<&str> = tasks.iter().map(|t| t.task.name.as_str()).collect();\nlet norm = task_name.trim().to_lowercase();\nif !valid.iter().any(|v| v.eq_ignore_ascii_case(&norm)) {\n    eprintln!(\"model proposed unknown task '{}'; valid: {:?}\", task_name, valid);\n    return; // don't dispatch\n}","typeGuard":null,"tryCatchPattern":"match run_with_tasks(task_name) {\n    Ok(m) => println!(\"matched {}\", m),\n    Err(e) if e.to_string().contains(\"unknown task\") => {\n        eprintln!(\"{}\", e);\n        eprintln!(\"pick a task from the printed candidate list and re-run\");\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["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"],"tags":["llm","task-matching","lm-studio","validation"],"backgroundTag":"llm-hallucinated-task-name","analyzedSha":"a747e741ae92c09071d0ae946ab48488adcff1ce","analyzedAt":"2026-09-01T22:43:55.719Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}