{"record":{"id":"7d7c78f0e3ae3d3d","repo":"mastra-ai/mastra","slug":"agentscheduleworker-call-init-before-start","errorCode":null,"errorMessage":"AgentScheduleWorker: call init() before start()","messagePattern":"AgentScheduleWorker: call init\\(\\) before start\\(\\)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/core/src/schedules/worker.ts","lineNumber":72,"sourceCode":"  #pushCb?: EventCallback;\n  #running = false;\n\n  constructor(config: AgentScheduleWorkerConfig = {}) {\n    super();\n    this.#config = config;\n  }\n\n  async init(deps: WorkerDeps): Promise<void> {\n    await super.init(deps);\n\n    if (!deps.mastra) {\n      throw new Error('AgentScheduleWorker requires Mastra instance');\n    }\n  }\n\n  async start(): Promise<void> {\n    if (this.#running) return;\n    if (!this.deps) throw new Error('AgentScheduleWorker: call init() before start()');\n\n    // Push-only pubsubs (EventEmitter, UnixSocketPubSub) don't support the\n    // grouped pull subscription a PullTransport requires. They deliver every\n    // event to every in-process subscriber, so subscribe directly without a\n    // group — mirroring how Mastra.startWorkers handles workflow events for\n    // push-only transports instead of running the pull-based worker.\n    const modes = this.deps.pubsub.supportedModes ?? ['pull'];\n    if (!modes.includes('pull')) {\n      const cb: EventCallback = (event, ack, nack) => {\n        void this.#handleEvent(event, ack, nack);\n      };\n      this.#pushCb = cb;\n      await this.deps.pubsub.subscribe(TOPIC_AGENT_SCHEDULES, cb);\n      this.#running = true;\n      return;\n    }\n\n    const group = this.#config.group ?? DEFAULT_GROUP;","sourceCodeStart":54,"sourceCodeEnd":90,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/core/src/schedules/worker.ts#L54-L90","documentation":"AgentScheduleWorker.start() was called before init(), so this.deps is unset. The worker needs initialized dependencies (including the Mastra instance) before it can subscribe and process schedule events.","triggerScenarios":"Calling worker.start() on a fresh AgentScheduleWorker without a prior successful worker.init(deps) call.","commonSituations":"Custom bootstrap code that starts workers before initializing them; error-swallowed init failure followed by start; reordering of statements after refactor.","solutions":["Call worker.init(deps) and await it before calling worker.start().","Await init so any init error surfaces instead of being followed by start().","Guard startup: only call start() when init completed successfully (e.g. after a successful await)."],"exampleFix":"// before\nawait worker.start();\n// after\nawait worker.init({ pubsub, storage, mastra });\nawait worker.start();","handlingStrategy":"validation","validationCode":"if (!worker.isInitialized?.()) await worker.init(deps);\nawait worker.start();","typeGuard":null,"tryCatchPattern":"try {\n  await worker.start();\n} catch (e) {\n  if (String((e as Error).message).includes('call init()')) {\n    await worker.init(deps);\n    await worker.start();\n  } else throw e;\n}","preventionTips":["Enforce an init-then-start lifecycle in a single bootstrap function.","Never swallow errors from init(); always await it.","Add a startup assertion/test that start() succeeds after init()."],"tags":["worker","initialization","lifecycle"],"backgroundTag":"not-initialized","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}