{"record":{"id":"9ee64197155a072b","repo":"eyaltoledano/claude-task-master","slug":"task-completed","errorCode":"TASK_COMPLETED","errorMessage":"Task ${taskId} is already marked as ${task.status} and cannot be expanded","messagePattern":"Task (.+?) is already marked as (.+?) and cannot be expanded","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"mcp-server/src/core/direct-functions/expand-task.js","lineNumber":141,"sourceCode":"\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;\n\t\tif (hasExistingSubtasks && !forceFlag) {\n\t\t\tlog.info(\n\t\t\t\t`Task ${taskId} already has ${task.subtasks.length} subtasks. Use --force to overwrite.`\n\t\t\t);\n\t\t\treturn {\n\t\t\t\tsuccess: true,\n\t\t\t\tdata: {\n\t\t\t\t\tmessage: `Task ${taskId} already has subtasks. Expansion skipped.`,\n\t\t\t\t\ttask,\n\t\t\t\t\tsubtasksAdded: 0,\n\t\t\t\t\thasExistingSubtasks","sourceCodeStart":123,"sourceCodeEnd":159,"githubUrl":"https://github.com/eyaltoledano/claude-task-master/blob/c0c98d367c55296bfe69e65680625b6db437af02/mcp-server/src/core/direct-functions/expand-task.js#L123-L159","documentation":"expandTaskDirect refuses to expand a task that is already marked 'done' or 'completed'. Task Master treats expansion as a planning operation only valid for open work; expanding a finished task would generate meaningless subtasks. The MCP tool returns a structured {success:false, error:{code:'TASK_COMPLETED'}} result instead of throwing.","triggerScenarios":"Calling the expand_task MCP tool with a taskId whose status is 'done' or 'completed' in tasks.json (and no early bypass).","commonSituations":"AI agents iterating a task list after finishing work and forgetting to skip completed IDs; stale client caches pointing at a task another session closed; replaying an old expand call after the task was marked complete.","solutions":["Check task.status before calling expand_task and skip tasks marked done/completed","Pick a different open task ID to expand","If the task truly needs rework, set its status back to 'pending' (or via update_task_status) then re-run expand_task","If subtasks already exist and you intended regeneration, use force:true instead — but that still requires a non-completed task"],"exampleFix":"// before\nawait mcp.call('expand_task', { projectId, taskId: '5' }); // task 5 is done\n// after\nconst task = await mcp.call('get_task', { projectId, taskId: '5' });\nif (task.status !== 'done' && task.status !== 'completed') {\n  await mcp.call('expand_task', { projectId, taskId: '5' });\n}","handlingStrategy":"validation","validationCode":"const task = await getTask(projectRoot, taskId);\nif (task.status === 'done' || task.status === 'completed') {\n  throw new Error(`Skip expand_task: task ${taskId} is ${task.status}`);\n}","typeGuard":"function isExpandable(task) {\n  return typeof task === 'object' && task !== null &&\n    task.status !== 'done' && task.status !== 'completed';\n}","tryCatchPattern":"try {\n  const res = await callTool('expand_task', { taskId, projectRoot });\n  if (!res.success && res.error?.code === 'TASK_COMPLETED') {\n    console.warn(`Task ${taskId} already completed; skipping expansion`);\n  }\n} catch (e) { console.error(e.message); }","preventionTips":["Fetch task status before every expand call in loops","Filter task lists to pending/in-progress before expanding","Use force:true only deliberately, and never on completed tasks","Cache task state briefly but revalidate before mutating calls"],"tags":["task-management","mcp","validation"],"backgroundTag":"task-already-completed","analyzedSha":"c0c98d367c55296bfe69e65680625b6db437af02","analyzedAt":"2026-08-29T02:56:26.071Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}