mastra-ai/mastra · error

InProcessStrategy requires Mastra instance. Call __registerM

Error message

InProcessStrategy requires Mastra instance. Call __registerMastra() first.

What it means

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.

Source

Thrown at packages/core/src/worker/strategies/in-process-strategy.ts:25

/**
 * Executes workflow steps in the same process by delegating to StepExecutor.
 * This is the default strategy used when the worker runs co-located with the server.
 */
export class InProcessStrategy implements StepExecutionStrategy {
  #mastra?: Mastra;

  constructor({ mastra }: { mastra?: Mastra } = {}) {
    this.#mastra = mastra;
  }

  __registerMastra(mastra: Mastra): void {
    this.#mastra = mastra;
  }

  async executeStep(params: StepExecutionParams): Promise<StepResult<any, any, any, any>> {
    if (!this.#mastra) {
      throw new Error('InProcessStrategy requires Mastra instance. Call __registerMastra() first.');
    }

    // Use getWorkflowById — events carry the workflow's `id` property
    // (e.g. "scheduled-workflow"), not the config key ("scheduledWorkflow").
    const workflow = this.#mastra.getWorkflowById(params.workflowId);
    const entry = getStepEntry(workflow, params.executionPath);

    if (!entry) {
      throw new Error(
        `InProcessStrategy: could not resolve step "${params.stepId}" at executionPath [${params.executionPath.join(',')}] in workflow "${params.workflowId}"`,
      );
    }

    const rc = new RequestContext<unknown>(Object.entries(params.requestContext ?? {}));

    let abortController: AbortController | undefined;
    if (params.abortSignal) {
      abortController = new AbortController();

View on GitHub (pinned to 75dd419e61)

Solutions

  1. Call strategy.__registerMastra(mastra) with your Mastra instance before any executeStep call
  2. In tests, register Mastra in a beforeAll/beforeEach hook that runs before step execution
  3. Verify wiring order if using a DI container — register Mastra first, then strategies

Example fix

// before
const strategy = new InProcessStrategy();
await strategy.executeStep(params);
// after
const strategy = new InProcessStrategy();
strategy.__registerMastra(mastra);
await strategy.executeStep(params);
Defensive patterns

Strategy: try-catch

Validate before calling

if (typeof (strategy as any).__registerMastra !== 'function') throw new Error('not an InProcessStrategy');

Try / catch

try {
  await strategy.executeStep(params);
} catch (e) {
  if (e instanceof Error && e.message.includes('__registerMastra')) {
    strategy.__registerMastra(mastra);
    return strategy.executeStep(params);
  }
  throw e;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of mastra-ai/mastra@75dd419e61 (2026-08-30). Data as JSON: /api/errors/67e09e1093785b78. Report an issue: GitHub.