{"record":{"id":"dc2c82736bdfa26f","repo":"mastra-ai/mastra","slug":"sendstatesignal-could-not-load-thread-threadid","errorCode":null,"errorMessage":"sendStateSignal could not load thread ${threadId}","messagePattern":"sendStateSignal could not load thread (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/core/src/agent/thread-stream-runtime.ts","lineNumber":2721,"sourceCode":"    target: SendAgentStateSignalOptions<OUTPUT>,\n    pubsub?: PubSub,\n  ): Promise<SendAgentStateSignalResult<OUTPUT>> {\n    if (!target.resourceId || !target.threadId) {\n      throw new Error('resourceId and threadId are required to send a state signal');\n    }\n    const resourceId = target.resourceId;\n    const threadId = target.threadId;\n\n    const requestContext = target.ifIdle?.streamOptions?.requestContext;\n    const memoryContext = parseMemoryRequestContext(requestContext);\n    const memory = await agent.getMemory({ requestContext });\n    if (!memory) {\n      throw new Error('sendStateSignal requires Mastra memory');\n    }\n\n    const loadedThread = (await memory.getThreadById({ threadId })) ?? memoryContext?.thread;\n    if (!loadedThread) {\n      throw new Error(`sendStateSignal could not load thread ${threadId}`);\n    }\n\n    const thread = {\n      ...loadedThread,\n      id: threadId,\n      resourceId: loadedThread.resourceId ?? resourceId,\n      createdAt: loadedThread.createdAt ?? new Date(),\n      updatedAt: loadedThread.updatedAt ?? new Date(),\n      metadata: loadedThread.metadata,\n    };\n\n    const applied = await applyStateSignal({\n      input: stateInput,\n      memory,\n      thread,\n      resourceId,\n      threadId,\n      memoryConfig: memoryContext?.memoryConfig,","sourceCodeStart":2703,"sourceCodeEnd":2739,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/core/src/agent/thread-stream-runtime.ts#L2703-L2739","documentation":"sendStateSignal() throws this when memory.getThreadById({ threadId }) returns null/undefined and no thread exists in the parsed memory request context. The signal needs an existing thread to attach state to; the runtime will not silently create one.","triggerScenarios":"Calling sendStateSignal with a threadId that was never created (no prior agent run persisted a thread with that ID), a typo'd/deleted thread ID, or a storage backend that doesn't contain the thread (wrong database/connection).","commonSituations":"Generating thread IDs client-side without first creating the thread via memory; pointing at a different storage instance in dev vs prod; thread expired/evicted by storage TTL; cross-resource thread ID collision.","solutions":["Create or run the thread once (agent.stream/generate with the same resourceId/threadId) so it persists before sending state signals.","Verify memory.getThreadById({ threadId }) returns the thread with the same storage config the agent uses.","Check that you are connected to the storage backend where the thread actually lives (env-specific DB URLs, table prefixes)."],"exampleFix":"// before\nawait runtime.sendStateSignal(agent, state, { resourceId, threadId: 'thread-1' }); // thread may not exist\n// after\nif (!(await memory.getThreadById({ threadId }))) {\n  await memory.createThread({ resourceId, threadId, title: 'thread' });\n}\nawait runtime.sendStateSignal(agent, state, { resourceId, threadId });","handlingStrategy":"validation","validationCode":"const existing = await memory.getThreadById({ threadId });\nif (!existing) await memory.createThread({ resourceId, threadId, title: 'auto' });","typeGuard":"null","tryCatchPattern":"try {\n  return await runtime.sendStateSignal(agent, state, target);\n} catch (e) {\n  if (e instanceof Error && e.message.startsWith('sendStateSignal could not load thread')) {\n    await memory.createThread({ resourceId: target.resourceId, threadId: target.threadId, title: 'recovered' });\n    return runtime.sendStateSignal(agent, state, target);\n  }\n  throw e;\n}","preventionTips":["Create threads before signaling; don't invent thread IDs client-side","Verify storage backend/env matches between thread creation and signal sending","Check for TTL/eviction policies that delete threads","Log threadId on failure to spot typos"],"tags":["agent","memory","storage","thread-not-found"],"backgroundTag":"thread-not-found","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}