{"record":{"id":"bfc5053cde9f66af","repo":"mastra-ai/mastra","slug":"agentscheduleworker-requires-mastra-instance","errorCode":null,"errorMessage":"AgentScheduleWorker requires Mastra instance","messagePattern":"AgentScheduleWorker requires Mastra instance","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/core/src/schedules/worker.ts","lineNumber":66,"sourceCode":" */\nexport class AgentScheduleWorker extends MastraWorker {\n  readonly name = 'agent-schedule';\n\n  #config: AgentScheduleWorkerConfig;\n  #transport?: WorkerTransport;\n  #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;","sourceCodeStart":48,"sourceCodeEnd":84,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/core/src/schedules/worker.ts#L48-L84","documentation":"AgentScheduleWorker.init() requires a Mastra instance in its WorkerDeps; it throws a plain Error when deps.mastra is missing. Unlike other workers, the agent schedule worker depends on the Mastra instance to execute agent schedules.","triggerScenarios":"Calling worker.init(deps) with a deps object whose mastra property is undefined/null.","commonSituations":"Manually wiring workers in a custom server setup and forgetting the mastra field; constructing deps programmatically where mastra is attached later; partial dependency injection after refactors.","solutions":["Pass the Mastra instance in deps: worker.init({ ...deps, mastra }).","Construct the worker after your Mastra instance exists and inject it directly.","If using a framework helper (e.g. Mastra.startWorkers), let it provide deps instead of manual init."],"exampleFix":"// before\nworker.init({ pubsub, storage });\n// after\nworker.init({ pubsub, storage, mastra });","handlingStrategy":"validation","validationCode":"if (!deps.mastra) throw new Error('AgentScheduleWorker: deps.mastra required');\nawait worker.init(deps);","typeGuard":"function hasMastra(deps: Partial<WorkerDeps>): deps is WorkerDeps & { mastra: Mastra } {\n  return Boolean(deps.mastra);\n}","tryCatchPattern":"try {\n  await worker.init(deps);\n} catch (e) {\n  if (String((e as Error).message).includes('requires Mastra')) {\n    throw new Error('Worker bootstrap misconfigured: pass mastra in deps');\n  }\n  throw e;\n}","preventionTips":["Type deps as requiring mastra so TypeScript enforces it at the call site.","Build workers only after the Mastra instance is constructed.","Prefer Mastra's built-in worker startup over hand-rolled init sequences."],"tags":["worker","initialization","schedules"],"backgroundTag":"missing-dependency","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T08:17:16.595Z"}