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.

Solutions

  1. Retry the expand command; transient provider issues often produce empty results.
  2. Verify your model configuration (task-master models) and use a model that reliably follows JSON schemas.
  3. 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

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-assisted analysis of eyaltoledano/claude-task-master@c0c98d367c (2026-08-29). Data as JSON: /api/errors/32e1a8fdb4fdae83. Report an issue: GitHub.

Appendix: 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)