{"record":{"id":"5f8bbc5c361ef092","repo":"eyaltoledano/claude-task-master","slug":"received-invalid-task-object-from-ai","errorCode":null,"errorMessage":"Received invalid task object from AI.","messagePattern":"Received invalid task object from AI\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"scripts/modules/task-manager/update-task-by-id.js","lineNumber":470,"sourceCode":"\t\t\t\t}\n\n\t\t\t\t// Display AI usage telemetry for CLI users\n\t\t\t\tif (outputFormat === 'text' && aiServiceResponse.telemetryData) {\n\t\t\t\t\tdisplayAiUsageSummary(aiServiceResponse.telemetryData, 'cli');\n\t\t\t\t}\n\n\t\t\t\t// Return the updated task\n\t\t\t\treturn {\n\t\t\t\t\tupdatedTask: taskToUpdate,\n\t\t\t\t\ttelemetryData: aiServiceResponse.telemetryData,\n\t\t\t\t\ttagInfo: aiServiceResponse.tagInfo\n\t\t\t\t};\n\t\t\t}\n\n\t\t\t// Full update mode: Use structured data directly\n\t\t\tconst aiTask = aiServiceResponse.mainResult?.task;\n\t\t\tif (!aiTask || typeof aiTask !== 'object')\n\t\t\t\tthrow new Error('Received invalid task object from AI.');\n\n\t\t\tconst updatedTask = {\n\t\t\t\t...aiTask,\n\t\t\t\tdependencies: aiTask.dependencies ?? [],\n\t\t\t\tpriority: aiTask.priority ?? null,\n\t\t\t\tdetails: aiTask.details ?? null,\n\t\t\t\ttestStrategy: aiTask.testStrategy ?? null\n\t\t\t};\n\t\t\tif (!updatedTask.title || !updatedTask.description)\n\t\t\t\tthrow new Error('Updated task missing required fields.');\n\t\t\t// Preserve ID if AI changed it\n\t\t\tif (updatedTask.id !== taskId) {\n\t\t\t\treport('warn', `AI changed task ID. Restoring original ID ${taskId}.`);\n\t\t\t\tupdatedTask.id = taskId;\n\t\t\t}\n\t\t\t// Preserve status if AI changed it\n\t\t\tif (\n\t\t\t\tupdatedTask.status !== taskToUpdate.status &&","sourceCodeStart":452,"sourceCodeEnd":488,"githubUrl":"https://github.com/eyaltoledano/claude-task-master/blob/c0c98d367c55296bfe69e65680625b6db437af02/scripts/modules/task-manager/update-task-by-id.js#L452-L488","documentation":"In full-update mode, updateTaskById takes the AI response's mainResult.task and merges it over the existing task. If the AI returned no task object (or a non-object), the code throws rather than writing garbage into tasks.json. It indicates the AI service response did not match the expected schema.","triggerScenarios":"The AI provider returns a malformed/empty mainResult (e.g. truncated JSON, refusal message, wrong response shape) during update-task-by-id full update.","commonSituations":"Weak models returning prose instead of structured JSON, API errors surfaced as partial responses, very long tasks exceeding the model's output context, or misconfigured AI provider/baseURL returning an error payload.","solutions":["Retry the update; transient AI failures often resolve on a second call","Switch to a stronger model (e.g. the research model) via --research or provider config","Reduce the size/complexity of the task details being sent","Check the AI provider status/credentials if responses are consistently malformed"],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":null,"typeGuard":"function isAiTask(res) {\n  return !!res && typeof res === 'object' && !!res.mainResult &&\n    typeof res.mainResult.task === 'object' && res.mainResult.task !== null &&\n    typeof res.mainResult.task.title === 'string';\n}","tryCatchPattern":"try {\n  await updateTaskById(...);\n} catch (e) {\n  if (e.message === 'Received invalid task object from AI.') {\n    // retry with stronger model / inspect raw response\n  } else throw e;\n}","preventionTips":["Use capable models that honor structured JSON output","Keep task payloads within model context limits","Log raw AI responses in debug mode to diagnose schema drift","Retry transient malformed responses"],"tags":["ai","response-validation","schema-mismatch","api-response"],"backgroundTag":"invalid-ai-response-schema","analyzedSha":"c0c98d367c55296bfe69e65680625b6db437af02","analyzedAt":"2026-08-29T02:56:26.071Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}