{"record":{"id":"29eeb4666efcaf88","repo":"eyaltoledano/claude-task-master","slug":"generated-subtask-ids-must-be-positive-integers","errorCode":null,"errorMessage":"Generated subtask ids must be positive integers","messagePattern":"Generated subtask ids must be positive integers","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"scripts/modules/task-manager/scope-adjustment.js","lineNumber":452,"sourceCode":"\t\t// Don't fail the whole operation if subtask regeneration fails\n\t\treturn {\n\t\t\tupdatedTask: task,\n\t\t\tregenerated: false,\n\t\t\tpreserved: preservedSubtasks.length,\n\t\t\tgenerated: 0,\n\t\t\terror: error.message\n\t\t};\n\t}\n}\n\nfunction ensureSequentialSubtaskIds(subtasks) {\n\tif (!Array.isArray(subtasks) || subtasks.length === 0) {\n\t\treturn;\n\t}\n\n\tconst ids = subtasks.map((subtask) => subtask.id);\n\tif (ids.some((id) => !Number.isInteger(id) || id < 1)) {\n\t\tthrow new Error('Generated subtask ids must be positive integers');\n\t}\n\tconst uniqueIds = new Set(ids);\n\tif (uniqueIds.size !== ids.length) {\n\t\tthrow new Error('Generated subtasks must have unique ids');\n\t}\n\n\tconst sortedIds = [...uniqueIds].sort((a, b) => a - b);\n\tfor (let index = 0; index < sortedIds.length; index += 1) {\n\t\tif (sortedIds[index] !== index + 1) {\n\t\t\tthrow new Error(\n\t\t\t\t'Generated subtask ids must be sequential starting from 1'\n\t\t\t);\n\t\t}\n\t}\n}\n\n/**\n * Generates AI prompt for scope adjustment","sourceCodeStart":434,"sourceCodeEnd":470,"githubUrl":"https://github.com/eyaltoledano/claude-task-master/blob/c0c98d367c55296bfe69e65680625b6db437af02/scripts/modules/task-manager/scope-adjustment.js#L434-L470","documentation":"ensureSequentialSubtaskIds() validates the subtask array produced by AI-driven scope adjustments. Each subtask.id must be an integer >= 1; if the LLM-generated or parsed output contains 0, negative numbers, floats, or non-numeric ids, this error is thrown before the data is written. It is a guard against corrupting tasks.json with malformed subtask ids.","triggerScenarios":"Calling scopeUpTask/scopeDownTask (via regenerateSubtasksForComplexity) where the model returns JSON with subtask ids like 0, -1, 1.5, \"one\", or ids omitted (undefined), typically when the AI response is malformed or the parsing step mis-extracts ids.","commonSituations":"Weak/small LLM models producing off-spec JSON, prompt responses truncated so id fields are lost, custom prompts that change the expected output schema, or API responses wrapped in unexpected formats that break id extraction.","solutions":["Re-run the scope-up/scope-down command; LLM output variance often produces valid ids on retry.","Use a stronger model (e.g. switch the research/complexity role model in .taskmaster/config.json) that follows the JSON schema reliably.","Inspect the raw model response (enable debug logging) to see why ids came back invalid, and remove any customPrompt that alters the subtask format.","Validate the generated subtasks yourself before calling, or sanitize ids (map to Math.max(1, Math.round(id))) if your wrapper allows pre-processing."],"exampleFix":"// before (malformed AI output)\n{ \"subtasks\": [{ \"id\": 0, \"title\": \"a\" }, { \"id\": -2, \"title\": \"b\" }] }\n// after (valid)\n{ \"subtasks\": [{ \"id\": 1, \"title\": \"a\" }, { \"id\": 2, \"title\": \"b\" }] }","handlingStrategy":"validation","validationCode":"function subtaskIdsAreValidInts(subtasks) {\n  return Array.isArray(subtasks) && subtasks.length > 0 &&\n    subtasks.every((s) => Number.isInteger(s.id) && s.id >= 1);\n}\nif (!subtaskIdsAreValidInts(generated.subtasks)) {\n  // regenerate or repair before calling scope functions\n  generated.subtasks.forEach((s, i) => { if (!Number.isInteger(s.id) || s.id < 1) s.id = i + 1; });\n}","typeGuard":"function isValidSubtask(s) {\n  return typeof s === 'object' && s !== null && Number.isInteger(s.id) && s.id >= 1;\n}","tryCatchPattern":"try {\n  await scopeUpTask([taskId], strength);\n} catch (err) {\n  if (err.message.includes('must be positive integers')) {\n    console.error('AI returned malformed subtask IDs; retry or switch to a stronger model');\n  } else throw err;\n}","preventionTips":["Use a model that reliably emits schema-conformant JSON for subtask generation","Keep custom prompts aligned with the expected subtask output format","Sanitize/renumber AI output ids before persisting","Retry once on LLM validation failures — output variance usually resolves it"],"tags":["validation","llm-output","subtasks"],"backgroundTag":"invalid-identifier-value","analyzedSha":"c0c98d367c55296bfe69e65680625b6db437af02","analyzedAt":"2026-08-29T02:56:26.071Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}