{"record":{"id":"94135030ef052fb1","repo":"eyaltoledano/claude-task-master","slug":"generated-subtask-ids-must-be-sequential-starting","errorCode":null,"errorMessage":"Generated subtask ids must be sequential starting from 1","messagePattern":"Generated subtask ids must be sequential starting from 1","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"scripts/modules/task-manager/scope-adjustment.js","lineNumber":462,"sourceCode":"\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\n * @param {Object} task - The task to adjust\n * @param {string} direction - 'up' or 'down'\n * @param {string} strength - 'light', 'regular', or 'heavy'\n * @param {string} customPrompt - Optional custom instructions\n * @returns {string} The generated prompt\n */\nfunction generateScopePrompt(task, direction, strength, customPrompt) {\n\tconst isUp = direction === 'up';\n\tconst strengthDescriptions = {\n\t\tlight: isUp ? 'minor enhancements' : 'slight simplifications',","sourceCodeStart":444,"sourceCodeEnd":480,"githubUrl":"https://github.com/eyaltoledano/claude-task-master/blob/c0c98d367c55296bfe69e65680625b6db437af02/scripts/modules/task-manager/scope-adjustment.js#L444-L480","documentation":"The final check in ensureSequentialSubtaskIds(): after sorting the unique ids, they must form the sequence 1,2,3,... with no gaps. Ids like [1,3,4] or [2,3] fail. This guarantees subtask numbering is contiguous so future insertions and id-based references remain stable.","triggerScenarios":"scopeUpTask/scopeDownTask where the model outputs ids starting at 0, skips a number ([1,2,4]), starts at an arbitrary number ([3,4,5]), or returns more/fewer subtasks than ids suggest, leaving a gap after deduplication.","commonSituations":"Models that index from 0 (programming habit), partially valid responses where one subtask was dropped by a prior validation, or manual renumbering attempts in custom prompts.","solutions":["Retry the scope operation to get a properly sequenced generation.","Renumber programmatically before persisting if you control the flow: subtasks.forEach((s, i) => { s.id = i + 1; }).","Reinforce the prompt: 'number subtasks sequentially starting at 1 with no gaps' or provide a JSON schema example.","Check whether a previous validation step removed a subtask and created the gap; fix the upstream filtering instead."],"exampleFix":"// before\n[{ \"id\": 1, \"title\": \"a\" }, { \"id\": 3, \"title\": \"b\" }]\n// after (renumber)\nsubtasks.forEach((s, i) => { s.id = i + 1; });\n// => [{ \"id\": 1, \"title\": \"a\" }, { \"id\": 2, \"title\": \"b\" }]","handlingStrategy":"validation","validationCode":"function idsAreSequentialFromOne(subtasks) {\n  const sorted = [...new Set(subtasks.map((s) => s.id))].sort((a, b) => a - b);\n  return sorted.every((id, i) => id === i + 1);\n}\nif (!idsAreSequentialFromOne(generated.subtasks)) {\n  generated.subtasks.forEach((s, i) => { s.id = i + 1; }); // renumber\n}","typeGuard":"function isSequentialInts(subtasks) {\n  const ids = subtasks.map((s) => s.id).sort((a, b) => a - b);\n  return ids.length > 0 && ids.every((id, i) => id === i + 1);\n}","tryCatchPattern":"try {\n  await scopeUpTask([taskId], strength);\n} catch (err) {\n  if (err.message.includes('sequential starting from 1')) {\n    console.error('Subtask IDs had gaps or wrong start; renumber and retry');\n  } else throw err;\n}","preventionTips":["Renumber subtask arrays to 1..n before passing them downstream","Check upstream filters that may drop a subtask and create a gap","Instruct the model to index from 1, not 0","Validate the full 1..n sequence as part of your pre-write checks"],"tags":["validation","sequence","llm-output"],"backgroundTag":"invalid-identifier-value","analyzedSha":"c0c98d367c55296bfe69e65680625b6db437af02","analyzedAt":"2026-08-29T02:56:26.071Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}