eyaltoledano/claude-task-master · error
AI response did not include a valid subtasks array.
Error message
AI response did not include a valid subtasks array.
What it means
expandTask() asks the AI service to generate subtasks via generateObjectService and expects the response's mainResult to contain a subtasks array (structured generateObject output). If mainResult is missing or subtasks is not an array, it cannot append anything and throws before mutating the task.
Source
Thrown at scripts/modules/task-manager/expand-task.js:332
const role = useResearch ? 'research' : 'main';
// Call generateObjectService with the determined prompts and telemetry params
aiServiceResponse = await generateObjectService({
prompt: promptContent,
systemPrompt: systemPrompt,
role,
session,
projectRoot,
schema: COMMAND_SCHEMAS['expand-task'],
objectName: 'subtasks',
commandName: 'expand-task',
outputType: outputFormat
});
// With generateObject, we expect structured data – verify it before use
const mainResult = aiServiceResponse?.mainResult;
if (!mainResult || !Array.isArray(mainResult.subtasks)) {
throw new Error('AI response did not include a valid subtasks array.');
}
generatedSubtasks = mainResult.subtasks.map((subtask) => ({
...subtask,
dependencies: subtask.dependencies ?? [],
status: subtask.status ?? 'pending',
testStrategy: subtask.testStrategy ?? null
}));
logger.info(`Received ${generatedSubtasks.length} subtasks from AI.`);
} catch (error) {
if (loadingIndicator) stopLoadingIndicator(loadingIndicator);
logger.error(
`Error during AI call or parsing for task ${taskId}: ${error.message}`, // Added task ID context
'error'
);
throw error;
} finally {
if (loadingIndicator) stopLoadingIndicator(loadingIndicator);
}View on GitHub (pinned to c0c98d367c)
Solutions
- Retry the expand command; transient provider issues often produce empty results.
- Verify your model configuration (task-master models) and use a model that reliably follows JSON schemas.
- Check that the zod schema passed to generateObjectService requires a subtasks array so failures are retried upstream, and confirm ai-services-client version matches task-master's expectation of { mainResult: { subtasks: [...] } }.
Example fix
// before (service layer)
return { mainResult: parsed }; // parsed = { subtask: {...} }
// after
return { mainResult: { subtasks: Array.isArray(parsed.subtasks) ? parsed.subtasks : [parsed.subtask] } }; Defensive patterns
Strategy: try-catch
Type guard
function hasSubtasksArray(res) {
return !!res?.mainResult && Array.isArray(res.mainResult.subtasks);
} Try / catch
try {
await expandTask(taskId, context);
} catch (err) {
if (err.message.includes('valid subtasks array')) {
console.error('AI returned no subtasks array — check model config and retry, or add subtasks manually.');
} else throw err;
} Prevention
- Use a schema-compliant model for subtask generation (task-master models).
- Ensure the generation schema strictly requires subtasks: z.array().
- Retry once automatically; provider hiccups often cause empty results.
When it happens
Trigger: generateObjectService returns undefined/absent mainResult, or mainResult lacks a subtasks array — e.g. the model returned a single object instead of an array, schema validation silently degraded, or the service returned an error envelope.
Common situations: Weak/non-schema-following models returning { subtask: {...} } or { subtasks: {...} } (object not array); provider errors from bad API keys or rate limits surfaced as empty results; version drift between task-master and the AI services module changing the response shape.
Related errors
- AI service did not return a valid task object.
- Schema validation failed: ${errors}
- AI service did not return the expected object structure.
- Warning: Invalid Claude Code settings in config: ${error.mes
- Warning: Invalid Codex CLI settings in config: ${error.messa
AI-assisted analysis of eyaltoledano/claude-task-master@c0c98d367c (2026-08-29).
Data as JSON: /api/errors/32e1a8fdb4fdae83.
Report an issue: GitHub.