{"record":{"id":"35703f360ad26503","repo":"mastra-ai/mastra","slug":"no-threadid-found","errorCode":null,"errorMessage":"No threadId found","messagePattern":"No threadId found","errorType":"http","errorClass":"HTTPException","httpStatus":400,"severity":"error","filePath":"packages/server/src/server/handlers/memory.ts","lineNumber":1101,"sourceCode":"    mastra,\n    agentId,\n    threadId,\n    resourceId,\n    perPage,\n    page,\n    orderBy,\n    include,\n    filter,\n    includeSystemReminders,\n    requestContext,\n  }: any) => {\n    try {\n      const effectiveThreadId = getEffectiveThreadId(requestContext, threadId);\n      const effectiveResourceId = getEffectiveResourceId(requestContext, resourceId);\n      validateBody({ threadId: effectiveThreadId });\n\n      if (!effectiveThreadId) {\n        throw new HTTPException(400, { message: 'No threadId found' });\n      }\n\n      // Gateway proxy: list messages from gateway API\n      const agent = await getAgentFromContext({ mastra, agentId, requestContext });\n      if (agent && (await isGatewayAgentAsync(agent))) {\n        const gwClient = getGatewayClient();\n        if (gwClient) {\n          if (filter?.metadata && Object.keys(filter.metadata).length > 0) {\n            throw new HTTPException(501, {\n              message:\n                'Gateway memory message metadata filters are not supported by this gateway endpoint. Remove filter.metadata or query a local memory store.',\n            });\n          }\n\n          // Validate thread ownership before returning messages\n          const threadResult = await gwClient.getThread(effectiveThreadId);\n          if (threadResult) {\n            await enforceThreadAccess({","sourceCodeStart":1083,"sourceCodeEnd":1119,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/server/src/server/handlers/memory.ts#L1083-L1119","documentation":"The list-messages handler resolves an effective threadId from the path param and request context, then validates the body. If no threadId can be determined it throws HTTPException(400, 'No threadId found') before doing any lookup.","triggerScenarios":"GET messages for a thread without supplying threadId in the request path/body and without an effectiveThreadId in the request context (e.g. missing x-mastra-thread-id style header/context value).","commonSituations":"Client omits the thread id when calling the messages endpoint; a proxy/gateway strips the header or context key the handler reads; SDK call constructed manually without the thread parameter.","solutions":["Pass the threadId explicitly (path param or body) in the request.","Set the thread id in the request context/header the handler reads (getEffectiveThreadId) if relying on context.","Check any gateway/proxy configuration that may strip custom headers.","On the client, ensure a thread is created/selected before fetching its messages."],"exampleFix":"// before\nawait fetch(`/api/memory/threads//messages`);\n// after\nif (!threadId) throw new Error('threadId required before listing messages');\nawait fetch(`/api/memory/threads/${threadId}/messages`);","handlingStrategy":"validation","validationCode":"if (!threadId || typeof threadId !== 'string') {\n  throw new Error('threadId is required before listing messages');\n}","typeGuard":"function hasThreadId(v: unknown): v is { threadId: string } {\n  return !!v && typeof v === 'object' && typeof (v as any).threadId === 'string' && (v as any).threadId.length > 0;\n}","tryCatchPattern":"try {\n  return await listMessages(threadId);\n} catch (e) {\n  if (isHttpException(e, 400) && /threadid/i.test(e.message)) {\n    throw new UsageError('Provide a threadId (path or request context) when listing messages');\n  }\n  throw e;\n}","preventionTips":["Create/select a thread before calling message-list APIs.","Verify proxies/gateways forward custom thread-id headers.","Centralize memory API calls in one client module that asserts threadId presence."],"tags":["http-400","validation","thread"],"backgroundTag":"missing-required-parameter","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}