{"record":{"id":"9050ef5536d62a91","repo":"mastra-ai/mastra","slug":"orchestrationworker-call-init-before-start","errorCode":null,"errorMessage":"OrchestrationWorker: call init() before start()","messagePattern":"OrchestrationWorker: call init\\(\\) before start\\(\\)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/core/src/worker/workers/orchestration-worker.ts","lineNumber":78,"sourceCode":"    // The strategy reads MASTRA_WORKER_AUTH_TOKEN itself and forwards it\n    // through the server's normal Mastra auth provider — there is no\n    // separate \"worker secret\" gate.\n    const remoteUrl = process.env.MASTRA_STEP_EXECUTION_URL;\n    if (remoteUrl) {\n      this.#strategy = new HttpRemoteStrategy({\n        serverUrl: remoteUrl,\n      });\n    }\n\n    this.#processor = new WorkflowEventProcessor({\n      mastra: deps.mastra,\n      stepExecutionStrategy: this.#strategy,\n    });\n  }\n\n  async start(): Promise<void> {\n    if (this.#running) return;\n    if (!this.deps) throw new Error('OrchestrationWorker: call init() before start()');\n\n    const group = this.#config.group ?? DEFAULT_GROUP;\n    this.#transport = new PullTransport({ pubsub: this.deps.pubsub, group, logger: this.deps.logger });\n\n    await this.#transport.start({\n      route: (event, ack, nack) => this.#processEvent(event, ack, nack),\n    });\n\n    this.#running = true;\n  }\n\n  async stop(): Promise<void> {\n    if (!this.#running) return;\n\n    try {\n      if (this.#transport) {\n        await this.#transport.stop();\n        this.#transport = undefined;","sourceCodeStart":60,"sourceCodeEnd":96,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/core/src/worker/workers/orchestration-worker.ts#L60-L96","documentation":"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.","triggerScenarios":"Calling start() on a freshly constructed OrchestrationWorker, or calling start() and init() concurrently so init hasn't assigned this.deps yet.","commonSituations":"Bootstrap ordering mistakes in custom servers; fire-and-forget init without await followed by start(); framework-managed lifecycle expectations confused with standalone usage.","solutions":["await worker.init(deps) before calling start()","Ensure init's promise resolves before start (no floating promises)","Register the worker through Mastra's workers config so the framework handles init/start ordering"],"exampleFix":"// before\nconst w = new OrchestrationWorker({ name: 'o' });\nw.start();\n// after\nawait w.init({ mastra, storage, logger, pubsub });\nawait w.start();","handlingStrategy":"try-catch","validationCode":"if (!worker.deps) await worker.init(deps);","typeGuard":"function isInitialized(worker) { return !!worker.deps; }","tryCatchPattern":"try {\n  await worker.start();\n} catch (e) {\n  if (e.message === 'OrchestrationWorker: call init() before start()') {\n    await worker.init(deps);\n    await worker.start();\n  } else throw e;\n}","preventionTips":["Await init() before start() in a single async bootstrap function","Avoid fire-and-forget init promises","Use a small lifecycle wrapper (init → start → stop) shared by all workers"],"tags":["lifecycle","worker","initialization"],"backgroundTag":"worker-not-initialized","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}