{"record":{"id":"76609aa2dc21be9e","repo":"mastra-ai/mastra","slug":"thread-not-found-76609a","errorCode":null,"errorMessage":"Thread not found","messagePattern":"Thread not found","errorType":"http","errorClass":"HTTPException","httpStatus":404,"severity":"error","filePath":"packages/server/src/server/handlers/memory.ts","lineNumber":1032,"sourceCode":"            };\n          }\n          const thread = toLocalThread(result.thread);\n          await enforceThreadAccess({\n            mastra,\n            requestContext,\n            threadId: effectiveThreadId!,\n            thread,\n            effectiveResourceId,\n          });\n          return thread;\n        }\n      }\n\n      const memory = await getMemoryFromContext({ mastra, agentId, requestContext, allowMissingAgent: true });\n      if (memory) {\n        const thread = await memory.getThreadById({ threadId: effectiveThreadId! });\n        if (!thread) {\n          throw new HTTPException(404, { message: 'Thread not found' });\n        }\n        await enforceThreadAccess({\n          mastra,\n          requestContext,\n          threadId: effectiveThreadId!,\n          thread,\n          effectiveResourceId,\n        });\n        return thread;\n      }\n\n      // Fallback to storage (covers stored agents whose memory can't be resolved)\n      const storage = getStorageFromContext({ mastra });\n      if (storage) {\n        const memoryStore = await storage.getStore('memory');\n        if (memoryStore) {\n          const thread = await memoryStore.getThreadById({ threadId: effectiveThreadId! });\n          if (!thread) {","sourceCodeStart":1014,"sourceCodeEnd":1050,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/server/src/server/handlers/memory.ts#L1014-L1050","documentation":"The GET thread handler in the Mastra server resolves memory via the agent's memory instance and calls getThreadById. When no thread row exists for the requested threadId, it throws HTTPException(404, 'Thread not found'). This is a deliberate 404 so clients can distinguish 'unknown thread' from storage/authorization failures.","triggerScenarios":"GET /api/memory/threads/:threadId (get thread by id) where memory is resolvable from the agent/context but memory.getThreadById({ threadId }) returns undefined — i.e. the threadId does not exist in the configured memory storage.","commonSituations":"Client uses a thread id from a different environment/database; thread was deleted by memory TTL/cleanup or a prior delete call; typo'd or stale thread id cached in the frontend; point-in-time restore of the storage DB removed recent threads; pointing at a different storage backend via env (e.g. different Postgres/Upstash database).","solutions":["Verify the threadId exists by listing threads (GET /api/memory/threads?resourceid=...) and using a returned id.","Check that the server's memory storage configuration (connection string/env) points to the same database the thread was created in.","If the thread was deleted intentionally, create a new thread (e.g. via a new agent run) instead of reusing the stale id.","Confirm the resourceid association if your storage scopes threads per resource."],"exampleFix":"// before\nconst res = await fetch(`/api/memory/threads/${staleThreadId}`);\n// after\nconst threads = await fetch(`/api/memory/threads?resourceid=${resourceId}`).then(r => r.json());\nconst id = threads.find(t => t.id === desiredTitle)?.id ?? threads[0]?.id;\nconst res = await fetch(`/api/memory/threads/${id}`);","handlingStrategy":"try-catch","validationCode":"const threads = await fetch(`/api/memory/threads?resourceid=${resourceId}`).then(r => r.json());\nif (!threads.some(t => t.id === threadId)) throw new Error(`Thread ${threadId} does not exist for resource ${resourceId}`);","typeGuard":"function isThread(t: unknown): t is { id: string } {\n  return !!t && typeof t === 'object' && typeof (t as any).id === 'string';\n}","tryCatchPattern":"try {\n  const thread = await getThread(threadId);\n} catch (e) {\n  if (isHttpException(e, 404)) {\n    thread = await createNewThread(resourceId); // recover by starting fresh\n  } else throw e;\n}","preventionTips":["Always obtain thread ids from list/create APIs, never hardcode them.","Treat 404 as 'start a new thread' in UI navigation code.","Keep storage connection env identical across environments you share ids between."],"tags":["http-404","memory","thread"],"backgroundTag":"resource-not-found","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}