{"record":{"id":"ea5ba59471bba159","repo":"mastra-ai/mastra","slug":"resourceid-and-threadid-are-required-to-send-a-sta","errorCode":null,"errorMessage":"resourceId and threadId are required to send a state signal","messagePattern":"resourceId and threadId are required to send a state signal","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/core/src/agent/thread-stream-runtime.ts","lineNumber":2707,"sourceCode":"      };\n    }\n\n    return this.sendSignal<OUTPUT>(\n      agent,\n      signal,\n      { ...target, runId, resourceId, threadId, ifIdle: { ...target.ifIdle, behavior: 'wake' } },\n      pubsub,\n    );\n  }\n\n  async sendStateSignal<OUTPUT = unknown>(\n    agent: Agent<any, any, any, any>,\n    stateInput: AgentStateSignalInput,\n    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,","sourceCodeStart":2689,"sourceCodeEnd":2725,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/core/src/agent/thread-stream-runtime.ts#L2689-L2725","documentation":"AgentThreadStreamRuntime.sendStateSignal() throws this when target.resourceId or target.threadId is missing. Unlike queueMessage, sendStateSignal performs no inference from active run records — the caller must supply both IDs up front so the state signal can be persisted to the correct memory thread.","triggerScenarios":"Calling runtime.sendStateSignal(agent, stateInput, target) with resourceId or threadId undefined/null in the SendAgentStateSignalOptions target.","commonSituations":"Partially constructed options objects when routing signals dynamically; type-looseness letting { resourceId } without threadId compile; migrating code that previously targeted an active run by runId only.","solutions":["Pass both resourceId and threadId in the target options before calling sendStateSignal.","Add a pre-call guard that asserts both IDs are non-empty strings.","If the IDs come from a request/session object, validate them at the API boundary instead of at signal time."],"exampleFix":"// before\nawait runtime.sendStateSignal(agent, state, {});\n// after\nawait runtime.sendStateSignal(agent, state, { resourceId: 'user-1', threadId: 'thread-1' });","handlingStrategy":"validation","validationCode":"if (!target?.resourceId || !target?.threadId) {\n  throw new Error('sendStateSignal requires resourceId and threadId');\n}","typeGuard":"function isStateSignalTarget<T>(t: SendAgentStateSignalOptions<T>): t is SendAgentStateSignalOptions<T> & { resourceId: string; threadId: string } {\n  return Boolean(t.resourceId && t.threadId);\n}","tryCatchPattern":"try {\n  return await runtime.sendStateSignal(agent, state, target);\n} catch (e) {\n  if (e instanceof Error && e.message.includes('required to send a state signal')) {\n    // surface a 400-style validation error to the caller\n  }\n  throw e;\n}","preventionTips":["Validate signal options at the API/route boundary before reaching the runtime","Keep resourceId/threadId in one typed object threaded through your code","Add unit tests asserting the error for missing IDs"],"tags":["agent","memory","signal","missing-argument"],"backgroundTag":"missing-thread-context","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}