{"record":{"id":"67e09e1093785b78","repo":"mastra-ai/mastra","slug":"inprocessstrategy-requires-mastra-instance-call","errorCode":null,"errorMessage":"InProcessStrategy requires Mastra instance. Call __registerMastra() first.","messagePattern":"InProcessStrategy requires Mastra instance\\. Call __registerMastra\\(\\) first\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/core/src/worker/strategies/in-process-strategy.ts","lineNumber":25,"sourceCode":"\n/**\n * Executes workflow steps in the same process by delegating to StepExecutor.\n * This is the default strategy used when the worker runs co-located with the server.\n */\nexport class InProcessStrategy implements StepExecutionStrategy {\n  #mastra?: Mastra;\n\n  constructor({ mastra }: { mastra?: Mastra } = {}) {\n    this.#mastra = mastra;\n  }\n\n  __registerMastra(mastra: Mastra): void {\n    this.#mastra = mastra;\n  }\n\n  async executeStep(params: StepExecutionParams): Promise<StepResult<any, any, any, any>> {\n    if (!this.#mastra) {\n      throw new Error('InProcessStrategy requires Mastra instance. Call __registerMastra() first.');\n    }\n\n    // Use getWorkflowById — events carry the workflow's `id` property\n    // (e.g. \"scheduled-workflow\"), not the config key (\"scheduledWorkflow\").\n    const workflow = this.#mastra.getWorkflowById(params.workflowId);\n    const entry = getStepEntry(workflow, params.executionPath);\n\n    if (!entry) {\n      throw new Error(\n        `InProcessStrategy: could not resolve step \"${params.stepId}\" at executionPath [${params.executionPath.join(',')}] in workflow \"${params.workflowId}\"`,\n      );\n    }\n\n    const rc = new RequestContext<unknown>(Object.entries(params.requestContext ?? {}));\n\n    let abortController: AbortController | undefined;\n    if (params.abortSignal) {\n      abortController = new AbortController();","sourceCodeStart":7,"sourceCodeEnd":43,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/core/src/worker/strategies/in-process-strategy.ts#L7-L43","documentation":"InProcessStrategy executes steps directly against a Mastra instance, which must be registered first via __registerMastra(). Executing a step before registration means there is no workflow registry to look up, so the strategy throws this setup-order error.","triggerScenarios":"Calling strategy.executeStep() in unit tests or bootstrap code before calling __registerMastra(mastra); constructing the strategy in one module while registration happens later in app startup.","commonSituations":"Test harness instantiating the strategy in isolation; DI wiring order where the strategy is created before the Mastra app; forgetting registration after switching from HttpRemoteStrategy to InProcessStrategy.","solutions":["Call strategy.__registerMastra(mastra) with your Mastra instance before any executeStep call","In tests, register Mastra in a beforeAll/beforeEach hook that runs before step execution","Verify wiring order if using a DI container — register Mastra first, then strategies"],"exampleFix":"// before\nconst strategy = new InProcessStrategy();\nawait strategy.executeStep(params);\n// after\nconst strategy = new InProcessStrategy();\nstrategy.__registerMastra(mastra);\nawait strategy.executeStep(params);","handlingStrategy":"try-catch","validationCode":"if (typeof (strategy as any).__registerMastra !== 'function') throw new Error('not an InProcessStrategy');","typeGuard":null,"tryCatchPattern":"try {\n  await strategy.executeStep(params);\n} catch (e) {\n  if (e instanceof Error && e.message.includes('__registerMastra')) {\n    strategy.__registerMastra(mastra);\n    return strategy.executeStep(params);\n  }\n  throw e;\n}","preventionTips":["Register Mastra immediately after constructing the strategy","Use a factory function that constructs and registers in one step","In tests, register Mastra in beforeAll hooks","Add a startup assertion that strategies have their Mastra instance"],"tags":["worker","initialization","in-process","lifecycle"],"backgroundTag":"not-initialized","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}