{"record":{"id":"04430d610a2fd543","repo":"mastra-ai/mastra","slug":"conversation-conversationid-was-not-found-04430d","errorCode":null,"errorMessage":"Conversation ${conversationId} was not found","messagePattern":"Conversation (.+?) was not found","errorType":"http","errorClass":"HTTPException","httpStatus":404,"severity":"error","filePath":"packages/server/src/server/handlers/responses.ts","lineNumber":212,"sourceCode":"  if (!store && !conversationId && !effectiveThreadId) {\n    return null;\n  }\n\n  const memory = await agent.getMemory({ requestContext });\n  if (!memory) {\n    if (conversationId) {\n      throw new HTTPException(400, {\n        message: 'conversation_id requires the target agent to have memory configured',\n      });\n    }\n\n    return null;\n  }\n\n  if (conversationId) {\n    const existingThread = await memory.getThreadById({ threadId: conversationId });\n    if (!existingThread) {\n      throw new HTTPException(404, { message: `Conversation ${conversationId} was not found` });\n    }\n\n    await enforceThreadAccess({\n      mastra: agent.getMastraInstance(),\n      requestContext,\n      threadId: conversationId,\n      thread: existingThread,\n      effectiveResourceId,\n    });\n    return {\n      threadId: existingThread.id,\n      resourceId: effectiveResourceId ?? existingThread.resourceId,\n    };\n  }\n\n  if (!effectiveThreadId) {\n    if (!store) {\n      return null;","sourceCodeStart":194,"sourceCodeEnd":230,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/server/src/server/handlers/responses.ts#L194-L230","documentation":"When conversation_id is provided and the agent has memory, the server looks up the thread via memory.getThreadById. If no thread exists with that ID, it throws this 404 — the API does not silently create threads for arbitrary user-supplied conversation IDs.","triggerScenarios":"POST /api/responses with a conversation_id that was never created (no prior request created the thread), a deleted thread, a typo in the ID, or a thread belonging to a different storage backend/environment (e.g., staging DB vs production).","commonSituations":"Client generating its own UUID for conversation_id instead of using one returned by a previous response; pointing at a fresh database; running against a different environment than where the conversation was created; thread cleanup jobs deleting old threads.","solutions":["Create the conversation first (send a request without conversation_id and use the returned thread/conversation id, or explicitly create a thread via memory API)","Verify the conversation_id exists in the storage backend the server is actually connected to","Check for typos or stale cached IDs in the client; refresh from the last API response","Point the server at the environment/database where the thread was created"],"exampleFix":"// before\nconst r = await client.responses.create({ agent_id: 'a', conversation_id: crypto.randomUUID(), input: 'hi' }); // never created\n// after\nconst first = await client.responses.create({ agent_id: 'a', input: 'hi' });\nconst r = await client.responses.create({ agent_id: 'a', conversation_id: first.threadId, input: 'next' });","handlingStrategy":"try-catch","validationCode":"const thread = conversationId ? await memory.getThreadById({ threadId: conversationId }) : null;\nif (conversationId && !thread) throw new Error(`Conversation ${conversationId} does not exist yet`);","typeGuard":"null","tryCatchPattern":"try {\n  await client.responses.create({ agent_id, conversation_id: id, input });\n} catch (e) {\n  if (e?.status === 404 && /was not found/.test(e.message)) {\n    const first = await client.responses.create({ agent_id, input }); // create conversation, then retry\n    return client.responses.create({ agent_id, conversation_id: first.threadId, input });\n  }\n  throw e;\n}","preventionTips":["Create threads via the API instead of inventing UUIDs client-side","Persist conversation ids returned by prior responses","Point client and server at the same storage environment"],"tags":["server","http-404","storage","responses-api"],"backgroundTag":"resource-not-found","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}