{"record":{"id":"bceb163bb1acd55b","repo":"mastra-ai/mastra","slug":"backgroundtaskworker-failed-to-initialize-backgro","errorCode":null,"errorMessage":"BackgroundTaskWorker: failed to initialize background task manager","messagePattern":"BackgroundTaskWorker: failed to initialize background task manager","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/core/src/worker/workers/background-task-worker.ts","lineNumber":118,"sourceCode":"        },\n      });\n    }\n  }\n\n  async start(): Promise<void> {\n    if (this.#running) return;\n    if (!this.deps) {\n      throw new Error('BackgroundTaskWorker: call init() before start()');\n    }\n    // An owned manager has a terminal shutdown lifecycle. Recreate it on a\n    // direct stop → start cycle instead of attempting to reinitialize a\n    // manager whose subscriptions and executor registry were released.\n    if (!this.#manager) {\n      this.#createOwnedManager(this.deps);\n    }\n    const manager = this.#manager;\n    if (!manager) {\n      throw new Error('BackgroundTaskWorker: failed to initialize background task manager');\n    }\n    // When sharing Mastra's manager, Mastra has already fired off init() in\n    // its constructor as fire-and-forget. Don't re-await it here — that would\n    // surface init errors twice (the constructor's `.catch` already reports\n    // them) and serialize startWorkers() behind the manager's full bootstrap.\n    if (this.#ownsManager) {\n      await manager.init(this.deps.pubsub);\n    }\n    this.#running = true;\n  }\n\n  async stop(): Promise<void> {\n    if (!this.#running) return;\n    // Only tear down the manager if this worker owns it. When sharing Mastra's\n    // manager, Mastra's stopWorkers() / shutdown is responsible.\n    if (this.#manager && this.#ownsManager) {\n      try {\n        await this.#manager.shutdown();","sourceCodeStart":100,"sourceCodeEnd":136,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/core/src/worker/workers/background-task-worker.ts#L100-L136","documentation":"After ensuring dependencies exist and creating the owned BackgroundTaskManager if needed, start() verifies that a manager instance is actually available. If this.#manager is still falsy, manager creation silently failed and the worker cannot run, so it throws this explicit initialization-failure error.","triggerScenarios":"this.#createOwnedManager(this.deps) not producing a manager (e.g. misconfigured worker deps so manager construction short-circuits), or an external code path clearing #manager between creation and use.","commonSituations":"Custom or partial WorkerDeps missing fields the manager factory expects; subclass overriding manager creation; running an older worker build where owned-manager creation is conditional and skipped.","solutions":["Inspect your WorkerDeps for missing/invalid fields and supply a complete deps object in init()","Check earlier logs for errors thrown inside createOwnedManager/manager init (the constructor's catch handler reports them)","Upgrade @mastra/core to a version where owned-manager recreation on stop→start is present","As a workaround, construct and inject your own BackgroundTaskManager via deps instead of relying on the owned manager"],"exampleFix":"// before\nawait worker.init({ storage, logger }); // manager factory gets nothing it can use\n// after\nawait worker.init({ mastra, storage, logger, pubsub });\nawait worker.start();","handlingStrategy":"try-catch","validationCode":"await worker.init(deps);\nif (!worker.deps) throw new Error('deps missing');","typeGuard":null,"tryCatchPattern":"try {\n  await worker.start();\n} catch (e) {\n  if (e.message === 'BackgroundTaskWorker: failed to initialize background task manager') {\n    logger.error('manager init failed — check deps and prior init logs', { deps: Object.keys(deps) });\n  } else throw e;\n}","preventionTips":["Supply a complete WorkerDeps (mastra, storage, logger, pubsub)","Watch constructor/init logs for manager init errors","Keep @mastra/core updated so owned-manager recreation bugs are fixed","Inject your own manager when you need guaranteed lifecycle control"],"tags":["worker","initialization","manager"],"backgroundTag":"worker-not-initialized","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}