{"record":{"id":"d1f68bc267b8f894","repo":"ruvnet/ruflo","slug":"agentadapter-not-initialized-call-initialize-fi","errorCode":null,"errorMessage":"AgentAdapter not initialized. Call initialize() first.","messagePattern":"AgentAdapter not initialized\\. Call initialize\\(\\) first\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"v3/@claude-flow/integration/src/agent-adapter.ts","lineNumber":600,"sourceCode":"    };\n\n    const mappedStatus = statusMap[agenticFlowAgent.status.toLowerCase()];\n    if (mappedStatus && mappedStatus !== agent.status) {\n      agent.status = mappedStatus;\n      this.emit('status-synced', {\n        agentId: agent.id,\n        from: agenticFlowAgent.status,\n        to: mappedStatus,\n      });\n    }\n  }\n\n  /**\n   * Ensure adapter is initialized\n   */\n  private ensureInitialized(): void {\n    if (!this.initialized) {\n      throw new Error('AgentAdapter not initialized. Call initialize() first.');\n    }\n  }\n\n  /**\n   * Debug logging\n   */\n  private logDebug(message: string, data?: unknown): void {\n    if (this.config.debug) {\n      console.debug(`[AgentAdapter] ${message}`, data || '');\n    }\n  }\n}\n\n/**\n * Create and initialize an AgentAdapter\n */\nexport async function createAgentAdapter(\n  config?: Partial<AgentAdapterConfig>","sourceCodeStart":582,"sourceCodeEnd":618,"githubUrl":"https://github.com/ruvnet/ruflo/blob/fa13ee4ad60ac2090b1480656eb233521790d640/v3/@claude-flow/integration/src/agent-adapter.ts#L582-L618","documentation":"Thrown by AgentAdapter#ensureInitialized() (v3/@claude-flow/integration/src/agent-adapter.ts:600). Most operational methods call this guard first, so invoking any of them before await adapter.initialize() completed (or after a failed initialize) raises this error immediately.","triggerScenarios":"Calling adapter.execute/run/register (any guarded method) right after `new AgentAdapter(...)` without awaiting initialize(); calling concurrently with an initialize() that is still in flight; calling after initialize() rejected but the code continued on a rejected-promise path.","commonSituations":"Missing await in an async setup path (fire-and-forget initialize()); early return from a try block that skips initialization; reusing an adapter instance across requests while an earlier failure left it uninitialized.","solutions":["Await initialize() once before any other call: `await adapter.initialize();` then use the adapter.","Create the adapter through the factory/helper (e.g. createAgentAdapter) if available, which initializes for you.","Guard call sites: if (!adapter.isInitialized?.()) await adapter.initialize(); or track an `initialized` boolean in your own wrapper.","If initialize() itself threw, fix that error first — retrying operations on a half-initialized adapter keeps hitting this guard."],"exampleFix":"// before\nconst adapter = new AgentAdapter(config);\nawait adapter.execute(task); // throws\n\n// after\nconst adapter = new AgentAdapter(config);\nawait adapter.initialize();\nawait adapter.execute(task);","handlingStrategy":"validation","validationCode":"const adapter = new AgentAdapter(config);\nif (!adapter.isInitialized?.()) await adapter.initialize();\n// then call operational methods","typeGuard":"function isReady(a: { isInitialized?: () => boolean }): boolean {\n  return typeof a.isInitialized === 'function' && a.isInitialized();\n}","tryCatchPattern":"try {\n  await adapter.execute(input);\n} catch (e) {\n  if ((e as Error).message.includes('not initialized')) {\n    await adapter.initialize();\n    return adapter.execute(input); // retry once after init\n  }\n  throw e;\n}","preventionTips":["Construct + initialize in one factory function so callers can never see an uninitialized adapter.","Await initialization in the async DI bootstrap before serving requests.","Treat a failed initialize() as fatal for that adapter instance."],"tags":["lifecycle","initialization","agent-adapter"],"backgroundTag":"not-initialized-guard","analyzedSha":"fa13ee4ad60ac2090b1480656eb233521790d640","analyzedAt":"2026-08-18T21:34:22.708Z","contentChangedAt":"2026-08-18T21:34:22.708Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}