mastra-ai/mastra · error · HTTPException

Conversation ${conversationId} was not found

Error message

Conversation ${conversationId} was not found

What it means

The get-conversation handler searches all agents' memory stores for a thread matching conversationId via findConversationThreadAcrossAgents and throws HTTP 404 when no thread is found. The conversation ID either never existed or is not in any storage reachable by the configured agents.

Source

Thrown at packages/server/src/server/handlers/conversations.ts:102

  },
});

export const GET_CONVERSATION_ROUTE = createRoute({
  method: 'GET',
  path: '/v1/conversations/:conversationId',
  responseType: 'json',
  pathParamSchema: conversationIdPathParams,
  responseSchema: conversationObjectSchema,
  summary: 'Retrieve a conversation',
  description: 'Returns a conversation object backed by a Mastra memory thread',
  tags: ['Responses'],
  requiresAuth: true,
  requiresPermission: MastraFGAPermissions.AGENTS_READ,
  handler: async ({ mastra, requestContext, conversationId }) => {
    try {
      const match = await findConversationThreadAcrossAgents({ mastra, conversationId, requestContext });
      if (!match) {
        throw new HTTPException(404, { message: `Conversation ${conversationId} was not found` });
      }

      return buildConversationObject({ thread: match.thread });
    } catch (error) {
      return handleError(error, 'Error retrieving conversation');
    }
  },
});

export const GET_CONVERSATION_ITEMS_ROUTE = createRoute({
  method: 'GET',
  path: '/v1/conversations/:conversationId/items',
  responseType: 'json',
  pathParamSchema: conversationIdPathParams,
  responseSchema: conversationItemsListSchema,
  summary: 'List conversation items',
  description: 'Returns OpenAI-style conversation items derived from the stored thread messages',
  tags: ['Responses'],

View on GitHub (pinned to 75dd419e61)

Solutions

  1. Verify the conversation ID exists by listing conversations (GET conversations for the agent) and using a returned ID
  2. Confirm the server's memory storage points at the same database that contains the thread
  3. Check the agent that owned the conversation is registered on this Mastra instance
  4. If the thread was deleted, create a new conversation instead of expecting recovery

Example fix

// before
await client.getConversation('hardcoded-thread-id');
// after
const convs = await client.listConversations({ agentId: 'agent-1' });
const conv = await client.getConversation(convs.conversations[0].id);
Defensive patterns

Strategy: validation

Validate before calling

const convs = await client.listConversations({ agentId });
const target = convs.conversations.find(c => c.id === conversationId);
if (!target) throw new Error(`Conversation ${conversationId} not found in ${agentId}`);

Try / catch

try {
  const conv = await client.getConversation(conversationId);
} catch (e) {
  if (e.status === 404) {
    // re-fetch conversation list or surface 'conversation not found' to user
  }
  throw e;
}

Prevention

When it happens

Trigger: GETting /api/conversations/:conversationId where no agent's memory store contains a thread with that ID — deleted thread, wrong ID, storage backend changed, or the agent with that thread isn't registered on this server.

Common situations: Hard-coding a conversation ID from a different environment/database; switching storage adapters between dev and prod so old thread IDs don't resolve; thread deleted by a concurrent user; typos in the ID; server pointing at a fresh database.

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


AI-assisted analysis of mastra-ai/mastra@75dd419e61 (2026-08-30). Data as JSON: /api/errors/54d0ad11cea3a207. Report an issue: GitHub.