mastra-ai/mastra · error · HTTPException
Conversation ${conversationId} was not found
Error message
Conversation ${conversationId} was not found What it means
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.
Source
Thrown at packages/server/src/server/handlers/responses.ts:212
if (!store && !conversationId && !effectiveThreadId) {
return null;
}
const memory = await agent.getMemory({ requestContext });
if (!memory) {
if (conversationId) {
throw new HTTPException(400, {
message: 'conversation_id requires the target agent to have memory configured',
});
}
return null;
}
if (conversationId) {
const existingThread = await memory.getThreadById({ threadId: conversationId });
if (!existingThread) {
throw new HTTPException(404, { message: `Conversation ${conversationId} was not found` });
}
await enforceThreadAccess({
mastra: agent.getMastraInstance(),
requestContext,
threadId: conversationId,
thread: existingThread,
effectiveResourceId,
});
return {
threadId: existingThread.id,
resourceId: effectiveResourceId ?? existingThread.resourceId,
};
}
if (!effectiveThreadId) {
if (!store) {
return null;View on GitHub (pinned to 75dd419e61)
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
Example fix
// before
const r = await client.responses.create({ agent_id: 'a', conversation_id: crypto.randomUUID(), input: 'hi' }); // never created
// after
const first = await client.responses.create({ agent_id: 'a', input: 'hi' });
const r = await client.responses.create({ agent_id: 'a', conversation_id: first.threadId, input: 'next' }); Defensive patterns
Strategy: try-catch
Validate before calling
const thread = conversationId ? await memory.getThreadById({ threadId: conversationId }) : null;
if (conversationId && !thread) throw new Error(`Conversation ${conversationId} does not exist yet`); Type guard
null
Try / catch
try {
await client.responses.create({ agent_id, conversation_id: id, input });
} catch (e) {
if (e?.status === 404 && /was not found/.test(e.message)) {
const first = await client.responses.create({ agent_id, input }); // create conversation, then retry
return client.responses.create({ agent_id, conversation_id: first.threadId, input });
}
throw e;
} Prevention
- 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
When it happens
Trigger: 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).
Common situations: 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.
Understand the failure class
Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.
Related errors
- Stored response ${body.previous_response_id} was not found
- Stored response ${responseId} was not found
- Scorer with id ${scorerId} not found
- Version with id ${versionId} not found
- AcpAgent does not support resuming suspended generate calls
AI-assisted analysis of mastra-ai/mastra@75dd419e61 (2026-08-30).
Data as JSON: /api/errors/04430d610a2fd543.
Report an issue: GitHub.