{"record":{"id":"5f8f3af3c573e12f","repo":"eyaltoledano/claude-task-master","slug":"task-not-found-5f8f3a","errorCode":"TASK_NOT_FOUND","errorMessage":"Task with ID ${taskId} not found","messagePattern":"Task with ID (.+?) not found","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"mcp-server/src/core/direct-functions/expand-task.js","lineNumber":130,"sourceCode":"\t\t\treturn {\n\t\t\t\tsuccess: false,\n\t\t\t\terror: {\n\t\t\t\t\tcode: 'INVALID_TASKS_FILE',\n\t\t\t\t\tmessage: `No valid tasks found in ${tasksPath}. readJSON returned: ${JSON.stringify(data)}`\n\t\t\t\t}\n\t\t\t};\n\t\t}\n\n\t\t// Find the specific task\n\t\tlog.info(`[expandTaskDirect] Searching for task ID ${taskId} in data`);\n\t\tconst task = data.tasks.find((t) => t.id === taskId);\n\t\tlog.info(`[expandTaskDirect] Task found: ${task ? 'Yes' : 'No'}`);\n\n\t\tif (!task) {\n\t\t\treturn {\n\t\t\t\tsuccess: false,\n\t\t\t\terror: {\n\t\t\t\t\tcode: 'TASK_NOT_FOUND',\n\t\t\t\t\tmessage: `Task with ID ${taskId} not found`\n\t\t\t\t}\n\t\t\t};\n\t\t}\n\n\t\t// Check if task is completed\n\t\tif (task.status === 'done' || task.status === 'completed') {\n\t\t\treturn {\n\t\t\t\tsuccess: false,\n\t\t\t\terror: {\n\t\t\t\t\tcode: 'TASK_COMPLETED',\n\t\t\t\t\tmessage: `Task ${taskId} is already marked as ${task.status} and cannot be expanded`\n\t\t\t\t}\n\t\t\t};\n\t\t}\n\n\t\t// Check for existing subtasks and force flag\n\t\tconst hasExistingSubtasks = task.subtasks && task.subtasks.length > 0;","sourceCodeStart":112,"sourceCodeEnd":148,"githubUrl":"https://github.com/eyaltoledano/claude-task-master/blob/c0c98d367c55296bfe69e65680625b6db437af02/mcp-server/src/core/direct-functions/expand-task.js#L112-L148","documentation":"After loading tasks and searching for the requested ID, expandTaskDirect returns this TASK_NOT_FOUND error when no task in the file matches taskId. The taskId in the message is the parsed integer, so IDs as strings vs numbers are normalized before lookup.","triggerScenarios":"Calling expand_task with an ID that does not exist in tasks.json (typo, out of range, task deleted), or passing a subtask ID ('3.1') to a lookup that only searches top-level tasks, or stale ID references after re-numbering from parse-prd.","commonSituations":"Regenerating tasks invalidates previously known IDs; agent-supplied IDs hallucinated by the LLM; trying to expand a completed/removed task; referencing subtask IDs through the top-level task tool.","solutions":["List tasks (list/read tasks.json) and confirm the exact ID, then retry with a valid one.","If targeting a subtask, use the subtask-specific expansion parameters/tool instead of ID '3.1'.","Re-run parse-prd or check for re-numbering if IDs shifted after regeneration.","Guard the call: verify the task exists in the file before invoking expand."],"exampleFix":"// before\nawait expandTaskDirect({ tasksJsonPath, id: '12' }); // only 9 tasks exist\n// after\nconst { tasks } = JSON.parse(fs.readFileSync(tasksJsonPath, 'utf8'));\nif (tasks.some(t => t.id === 12)) {\n  await expandTaskDirect({ tasksJsonPath, id: '12' });\n}","handlingStrategy":"validation","validationCode":"const fs = require('fs');\nfunction taskExists(p, id) {\n  const data = JSON.parse(fs.readFileSync(p, 'utf8'));\n  return Array.isArray(data.tasks) && data.tasks.some(t => t.id === parseInt(id, 10));\n}\nif (!taskExists(tasksJsonPath, id)) {\n  throw new Error(`Task ${id} not in ${tasksJsonPath}; refresh the task list first`);\n}","typeGuard":"function findTask(data, id) {\n  if (!data || !Array.isArray(data.tasks)) return undefined;\n  return data.tasks.find(t => t.id === parseInt(id, 10));\n}","tryCatchPattern":"const res = await expandTaskDirect(args);\nif (!res.success && res.error?.code === 'TASK_NOT_FOUND') {\n  // re-list tasks and retry with a valid ID instead of failing the workflow\n  const tasks = listTaskIds(tasksJsonPath);\n  console.warn(`ID ${args.id} missing. Available: ${tasks.join(', ')}`);\n}","preventionTips":["Fetch the current task list before referencing IDs in automated flows.","Re-read tasks.json after any regeneration — IDs may be renumbered.","Route subtask expansion to the subtask-specific tool/parameters.","Never trust LLM-recalled IDs; validate against the file first."],"tags":["mcp-server","task-not-found","task-id","lookup"],"backgroundTag":"task-not-found","analyzedSha":"c0c98d367c55296bfe69e65680625b6db437af02","analyzedAt":"2026-08-29T02:56:26.071Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}