{"record":{"id":"1fdbff2a3e0a1f80","repo":"mastra-ai/mastra","slug":"conversation-id-and-previous-response-id-must-refe","errorCode":null,"errorMessage":"conversation_id and previous_response_id must reference the same conversation thread when both are provided","messagePattern":"conversation_id and previous_response_id must reference the same conversation thread when both are provided","errorType":"http","errorClass":"HTTPException","httpStatus":400,"severity":"error","filePath":"packages/server/src/server/handlers/responses.ts","lineNumber":178,"sourceCode":" * If `previous_response_id` is present, the request continues on that stored thread.\n * Otherwise, the route only creates or reuses a thread when the caller asked to store\n * the response and the resolved agent actually has memory configured.\n */\nasync function resolveThreadExecutionContext({\n  agent,\n  store,\n  conversationId,\n  previousResponseTurnRecord,\n  requestContext,\n}: {\n  agent: Agent<any, any, any, any>;\n  store: boolean;\n  conversationId?: string;\n  previousResponseTurnRecord: ResponseTurnRecord | null;\n  requestContext: RequestContext;\n}): Promise<ThreadExecutionContext | null> {\n  if (conversationId && previousResponseTurnRecord && previousResponseTurnRecord.thread.id !== conversationId) {\n    throw new HTTPException(400, {\n      message:\n        'conversation_id and previous_response_id must reference the same conversation thread when both are provided',\n    });\n  }\n\n  if (previousResponseTurnRecord) {\n    return {\n      threadId: previousResponseTurnRecord.thread.id,\n      resourceId: previousResponseTurnRecord.thread.resourceId,\n    };\n  }\n\n  const effectiveThreadId = getEffectiveThreadId(requestContext, undefined);\n  const effectiveResourceId = getEffectiveResourceId(requestContext, undefined);\n\n  if (!store && !conversationId && !effectiveThreadId) {\n    return null;\n  }","sourceCodeStart":160,"sourceCodeEnd":196,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/server/src/server/handlers/responses.ts#L160-L196","documentation":"resolveThreadExecutionContext enforces that when a request supplies both conversation_id and previous_response_id, the stored response identified by previous_response_id must live in the same thread as conversation_id. Mixing threads would corrupt conversation continuity, so the server rejects it with this 400 before executing the agent.","triggerScenarios":"POST /api/responses where body.conversation_id = 'thread-A' but the response referenced by body.previous_response_id was stored under 'thread-B' (e.g., resuming a response while pointing at a different conversation, or copying IDs across conversations/agents).","commonSituations":"Clients caching conversation_id from one session and previous_response_id from another; multi-tab UIs mixing state; replaying logged payloads with a changed conversation_id; passing a previous_response_id returned for a different agent/conversation.","solutions":["Align conversation_id with the thread that owns previous_response_id (drop one of the two, or look up the stored response's thread first)","If starting a new conversation, omit previous_response_id and let the server create/resolve the thread from conversation_id alone","Fix client state so conversation_id and previous_response_id are captured from the same request/response pair","If IDs were hardcoded or copied from logs/environment, fetch fresh values from the API instead"],"exampleFix":"// before\nawait client.responses.create({ agent_id: 'a', conversation_id: 'thread-A', previous_response_id: 'resp-from-thread-B', input: 'hi' });\n// after\nawait client.responses.create({ agent_id: 'a', previous_response_id: 'resp-from-thread-B', input: 'hi' }); // thread inferred from stored response","handlingStrategy":"validation","validationCode":"if (conversationId && previousResponseId) {\n  const rec = await getResponseTurnRecord(previousResponseId);\n  if (rec && rec.thread.id !== conversationId) throw new Error('conversation_id and previous_response_id reference different threads');\n}","typeGuard":"null","tryCatchPattern":"null","preventionTips":["Store conversation_id and previous_response_id together as one pair from the same response","Never mix ids across sessions or agents","When starting a new conversation, clear both fields"],"tags":["server","validation","http-400","responses-api"],"backgroundTag":"mismatched-conversation-ids","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}