eyaltoledano/claude-task-master · warning

Could not gather context: ${contextError.message}

Error message

Could not gather context: ${contextError.message}

What it means

During task expansion, expandTask tries to gather research context (e.g. from Perplexity) to enrich the expansion prompt. If context gathering throws (API error, missing key, network failure), the error is caught and only logged as a warning — expansion continues without the extra context.

Source

Thrown at scripts/modules/task-manager/expand-task.js:144

			const searchResults = fuzzySearch.findRelevantTasks(searchQuery, {
				maxResults: 5,
				includeSelf: true
			});
			const relevantTaskIds = fuzzySearch.getTaskIds(searchResults);

			const finalTaskIds = [
				...new Set([taskId.toString(), ...relevantTaskIds])
			];

			if (finalTaskIds.length > 0) {
				const contextResult = await contextGatherer.gather({
					tasks: finalTaskIds,
					format: 'research'
				});
				gatheredContext = contextResult.context || '';
			}
		} catch (contextError) {
			logger.warn(`Could not gather context: ${contextError.message}`);
		}
		// --- End Context Gathering ---

		// --- Complexity Report Integration ---
		let finalSubtaskCount;
		let complexityReasoningContext = '';
		let taskAnalysis = null;

		logger.info(
			`Looking for complexity report at: ${complexityReportPath}${tag !== 'master' ? ` (tag-specific for '${tag}')` : ''}`
		);

		try {
			if (fs.existsSync(complexityReportPath)) {
				const complexityReport = readJSON(complexityReportPath);
				taskAnalysis = complexityReport?.complexityAnalysis?.find(
					(a) => a.taskId === task.id
				);

View on GitHub (pinned to c0c98d367c)

Solutions

  1. Ignore if acceptable: expansion proceeds without research context; check earlier warnings for the root cause.
  2. Set/verify the research provider API key (e.g. PERPLEXITY_API_KEY) in .env or mcp.json.
  3. Re-run with a working network or switch the research provider via 'task-master models --set-research'.
  4. Inspect contextError.message in logs to address the underlying provider error.

Example fix

// before: expansion run with research but no key set
// .env missing PERPLEXITY_API_KEY
// after
# .env
PERPLEXITY_API_KEY=pplx-xxxxxxxx
Defensive patterns

Strategy: fallback

Validate before calling

const hasKey = !!(process.env.PERPLEXITY_API_KEY || mcpKeyFor('perplexity'));
if (!hasKey) console.warn('Research context will be skipped: no API key');

Try / catch

try {
  await expandTask(taskId, { research: true });
} catch (e) {
  // expandTask rarely throws for context issues; check warnings instead
  console.error('Expansion failed:', e.message);
}

Prevention

When it happens

Trigger: expandTask called (directly or via the 'result' path) with research enabled / 'research' format, and the context-gathering call (contextGatherer) rejects — e.g. missing PERPLEXITY_API_KEY, network failure, or API error.

Common situations: No research API key configured; offline or rate-limited; the chosen research provider returns an error; contextGatherer misconfigured for the requested format.

Related errors


AI-assisted analysis of eyaltoledano/claude-task-master@c0c98d367c (2026-08-29). Data as JSON: /api/errors/48f53c5f020f7bce. Report an issue: GitHub.