mastra-ai/mastra · error

OrchestrationWorker: call init() before start()

Error message

OrchestrationWorker: call init() before start()

What it means

OrchestrationWorker's start() creates the PullTransport and begins consuming events, which requires the deps (pubsub, logger, strategy wiring) set by init(). start() throws this error when deps are missing, i.e. start was called before init completed or at all.

Source

Thrown at packages/core/src/worker/workers/orchestration-worker.ts:78

    // The strategy reads MASTRA_WORKER_AUTH_TOKEN itself and forwards it
    // through the server's normal Mastra auth provider — there is no
    // separate "worker secret" gate.
    const remoteUrl = process.env.MASTRA_STEP_EXECUTION_URL;
    if (remoteUrl) {
      this.#strategy = new HttpRemoteStrategy({
        serverUrl: remoteUrl,
      });
    }

    this.#processor = new WorkflowEventProcessor({
      mastra: deps.mastra,
      stepExecutionStrategy: this.#strategy,
    });
  }

  async start(): Promise<void> {
    if (this.#running) return;
    if (!this.deps) throw new Error('OrchestrationWorker: call init() before start()');

    const group = this.#config.group ?? DEFAULT_GROUP;
    this.#transport = new PullTransport({ pubsub: this.deps.pubsub, group, logger: this.deps.logger });

    await this.#transport.start({
      route: (event, ack, nack) => this.#processEvent(event, ack, nack),
    });

    this.#running = true;
  }

  async stop(): Promise<void> {
    if (!this.#running) return;

    try {
      if (this.#transport) {
        await this.#transport.stop();
        this.#transport = undefined;

View on GitHub (pinned to 75dd419e61)

Solutions

  1. await worker.init(deps) before calling start()
  2. Ensure init's promise resolves before start (no floating promises)
  3. Register the worker through Mastra's workers config so the framework handles init/start ordering

Example fix

// before
const w = new OrchestrationWorker({ name: 'o' });
w.start();
// after
await w.init({ mastra, storage, logger, pubsub });
await w.start();
Defensive patterns

Strategy: try-catch

Validate before calling

if (!worker.deps) await worker.init(deps);

Type guard

function isInitialized(worker) { return !!worker.deps; }

Try / catch

try {
  await worker.start();
} catch (e) {
  if (e.message === 'OrchestrationWorker: call init() before start()') {
    await worker.init(deps);
    await worker.start();
  } else throw e;
}

Prevention

When it happens

Trigger: Calling start() on a freshly constructed OrchestrationWorker, or calling start() and init() concurrently so init hasn't assigned this.deps yet.

Common situations: Bootstrap ordering mistakes in custom servers; fire-and-forget init without await followed by start(); framework-managed lifecycle expectations confused with standalone usage.

Related errors


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