{"record":{"id":"f476878b6f4fba66","repo":"mastra-ai/mastra","slug":"slackprovider-not-attached-to-mastra-call-attac","errorCode":null,"errorMessage":"SlackProvider not attached to Mastra. Call __attach() first.","messagePattern":"SlackProvider not attached to Mastra\\. Call __attach\\(\\) first\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"channels/slack/src/provider.ts","lineNumber":649,"sourceCode":"   * Only needed if not using Mastra server config.\n   */\n  setBaseUrl(baseUrl: string): void {\n    this.#baseUrl = stripTrailingSlash(baseUrl);\n  }\n\n  /**\n   * Restore active Slack installations from storage.\n   *\n   * For each active installation in the database, this creates a SlackAdapter\n   * and injects AgentChannels into the corresponding Agent so it can receive\n   * Slack events immediately on startup.\n   *\n   * Does NOT auto-provision new apps. Use `connect(agentId, options)` to\n   * create a new Slack app for an agent.\n   */\n  async initialize(): Promise<void> {\n    if (!this.#mastra) {\n      throw new Error('SlackProvider not attached to Mastra. Call __attach() first.');\n    }\n\n    // Concurrent callers share the same in-flight initialization\n    if (this.#initPromise) return this.#initPromise;\n\n    this.#initPromise = this.#doInitialize();\n\n    try {\n      await this.#initPromise;\n    } catch (err) {\n      // Allow retry on failure\n      this.#initPromise = null;\n      throw err;\n    }\n  }\n\n  async #doInitialize(): Promise<void> {\n    // Load stored tokens if available (these are fresher than constructor tokens)","sourceCodeStart":631,"sourceCodeEnd":667,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/channels/slack/src/provider.ts#L631-L667","documentation":"SlackProvider.initialize() requires the provider to have been attached to a Mastra instance via __attach(). The #mastra private field is null until that happens, and initialize() throws rather than proceeding, because initialization depends on the instance (storage, agents, server config).","triggerScenarios":"Calling provider.initialize() directly (or triggering #activateAdapter / #resolveChannelsForInstallation / #autoInitialize) on a SlackProvider that was constructed but never attached to a Mastra instance.","commonSituations":"Manually instantiating SlackProvider outside the Mastra channel registration flow; calling initialize() in a test before setup; ordering bug where initialize() runs before the framework attaches the provider.","solutions":["Register the Slack channel through Mastra's channels configuration so the framework calls __attach() for you.","If managing manually, call provider.__attach(mastra) before provider.initialize().","Reorder code so initialization happens after the Mastra instance is constructed and attached."],"exampleFix":"// before\nconst provider = new SlackProvider();\nawait provider.initialize();\n// after\nconst provider = new SlackProvider();\nprovider.__attach(mastra);\nawait provider.initialize();","handlingStrategy":"try-catch","validationCode":"if (typeof provider.__attach !== 'function') {\n  // construct via Mastra channels config so the framework attaches it\n}\n// Or check indirectly: only call initialize() after Mastra construction.","typeGuard":null,"tryCatchPattern":"try {\n  await provider.initialize();\n} catch (err) {\n  if (err instanceof Error && err.message.includes('not attached to Mastra')) {\n    provider.__attach(mastra);\n    await provider.initialize();\n  } else throw err;\n}","preventionTips":["Register Slack through Mastra's channels config instead of instantiating SlackProvider manually.","Never call initialize() before the Mastra instance exists.","In tests, replicate the framework's attach step before initializing."],"tags":["lifecycle","initialization","slack"],"backgroundTag":"provider-not-initialized","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}