{"record":{"id":"f489adceea053477","repo":"eyaltoledano/claude-task-master","slug":"ai-service-did-not-return-the-expected-object-stru","errorCode":null,"errorMessage":"AI service did not return the expected object structure.","messagePattern":"AI service did not return the expected object structure\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"scripts/modules/task-manager/add-task.js","lineNumber":443,"sourceCode":"\t\t\t\tconst serviceRole = useResearch ? 'research' : 'main';\n\t\t\t\treport('DEBUG: Calling generateObjectService...', 'debug');\n\n\t\t\t\taiServiceResponse = await generateObjectService({\n\t\t\t\t\t// Capture the full response\n\t\t\t\t\trole: serviceRole,\n\t\t\t\t\tsession: session,\n\t\t\t\t\tprojectRoot: projectRoot,\n\t\t\t\t\tschema: COMMAND_SCHEMAS['add-task'],\n\t\t\t\t\tobjectName: 'newTaskData',\n\t\t\t\t\tsystemPrompt: systemPrompt,\n\t\t\t\t\tprompt: userPrompt,\n\t\t\t\t\tcommandName: commandName || 'add-task', // Use passed commandName or default\n\t\t\t\t\toutputType: outputType || (isMCP ? 'mcp' : 'cli') // Use passed outputType or derive\n\t\t\t\t});\n\t\t\t\treport('DEBUG: generateObjectService returned successfully.', 'debug');\n\n\t\t\t\tif (!aiServiceResponse || !aiServiceResponse.mainResult) {\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t'AI service did not return the expected object structure.'\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\t// Prefer mainResult if it looks like a valid task object, otherwise try mainResult.object\n\t\t\t\tif (\n\t\t\t\t\taiServiceResponse.mainResult.title &&\n\t\t\t\t\taiServiceResponse.mainResult.description\n\t\t\t\t) {\n\t\t\t\t\ttaskData = aiServiceResponse.mainResult;\n\t\t\t\t} else if (\n\t\t\t\t\taiServiceResponse.mainResult.object &&\n\t\t\t\t\taiServiceResponse.mainResult.object.title &&\n\t\t\t\t\taiServiceResponse.mainResult.object.description\n\t\t\t\t) {\n\t\t\t\t\ttaskData = aiServiceResponse.mainResult.object;\n\t\t\t\t} else {\n\t\t\t\t\tthrow new Error('AI service did not return a valid task object.');","sourceCodeStart":425,"sourceCodeEnd":461,"githubUrl":"https://github.com/eyaltoledano/claude-task-master/blob/c0c98d367c55296bfe69e65680625b6db437af02/scripts/modules/task-manager/add-task.js#L425-L461","documentation":"After calling generateObjectService for AI task generation, addTask() checks that the service returned a response object containing a mainResult. A null response or a missing mainResult means the AI service layer returned something unexpected (or nothing), so the raw result cannot be safely unwrapped.","triggerScenarios":"generateObjectService returns undefined/null (internal failure swallowed) or returns an object without mainResult — e.g. an unexpected provider response shape, an error object, or a version of the AI service module that changed its return contract.","commonSituations":"Misconfigured AI provider (bad API key causing an empty result), provider outage returning malformed JSON that fails schema parsing, or a custom/older ai-services-client whose generateObjectService returns the object directly instead of wrapping it in { mainResult }.","solutions":["Verify the AI provider configuration (API key, model, base URL) and retry, since a failed/empty generation is the most common cause.","Check that generateObjectService is the expected version and returns { mainResult } — update task-master or fix the custom service wrapper.","Inspect logs/debug output around the generateObjectService call for provider errors and fall back to manual task creation (title + description)."],"exampleFix":"// before (custom wrapper)\nconst response = await myGenerateObject(...); // returns object directly\nreturn response; // addTask expects response.mainResult\n// after\nconst response = await myGenerateObject(...);\nreturn { mainResult: response, telemetry: [] };","handlingStrategy":"try-catch","validationCode":null,"typeGuard":"function hasMainResult(res) {\n  return !!res && typeof res === 'object' && 'mainResult' in res && res.mainResult !== null;\n}","tryCatchPattern":"try {\n  await addTask(tasksPath, { prompt });\n} catch (err) {\n  if (err.message.includes('did not return the expected object structure')) {\n    logger.error('AI service failed; check provider config/API key, then retry or add manually.');\n  } else throw err;\n}","preventionTips":["Keep AI provider API keys and model config valid (task-master models).","Don't wrap generateObjectService with code that changes its { mainResult } contract.","Keep task-master and its ai-services dependency versions in sync."],"tags":["ai-service","unexpected-response-shape","add-task"],"backgroundTag":"ai-response-missing-field","analyzedSha":"c0c98d367c55296bfe69e65680625b6db437af02","analyzedAt":"2026-08-29T02:56:26.071Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}