{"record":{"id":"3836bcaaec4b48c2","repo":"ruvnet/ruflo","slug":"agent-this-id-not-initialized-call-initialize","errorCode":null,"errorMessage":"Agent ${this.id} not initialized. Call initialize() first.","messagePattern":"Agent (.+?) not initialized\\. Call initialize\\(\\) first\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"v3/@claude-flow/integration/src/agentic-flow-agent.ts","lineNumber":763,"sourceCode":"  protected async localExecuteTask(task: Task): Promise<unknown> {\n    // Minimal processing delay for timing metrics\n    await this.delay(1);\n\n    // This is a basic implementation that should be overridden by subclasses\n    // For now, just return the task input as output\n    return {\n      message: `Task ${task.id} processed by agent ${this.id}`,\n      input: task.input,\n      timestamp: Date.now(),\n    };\n  }\n\n  /**\n   * Ensure agent is initialized before operations\n   */\n  private ensureInitialized(): void {\n    if (!this.initialized) {\n      throw new Error(`Agent ${this.id} not initialized. Call initialize() first.`);\n    }\n  }\n\n  /**\n   * Estimate memory usage in MB (rough estimate)\n   */\n  private estimateMemoryUsage(): number {\n    // Rough estimate: 1MB base + 100KB per task completed\n    return 1 + (this.metrics!.tasksCompleted * 0.1);\n  }\n\n  /**\n   * Generate a unique ID with prefix\n   */\n  private generateId(prefix: string): string {\n    return `${prefix}_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;\n  }\n","sourceCodeStart":745,"sourceCodeEnd":781,"githubUrl":"https://github.com/ruvnet/ruflo/blob/fa13ee4ad60ac2090b1480656eb233521790d640/v3/@claude-flow/integration/src/agentic-flow-agent.ts#L745-L781","documentation":"Thrown by AgenticFlowAgent#ensureInitialized (v3/@claude-flow/integration/src/agentic-flow-agent.ts:763). Guard methods (executeTask, checkpointing, metric snapshots) call it before doing work, so any operation on an agent whose initialize() has not completed (or failed) fails fast with the agent id embedded in the message.","triggerScenarios":"executeTask() immediately after construction without await agent.initialize(); calling during a concurrent initialize() that is still awaiting external resources; calling after initialize() rejected (e.g. adapter dependency down) without recovery.","commonSituations":"Missing await on initialize() in async setup code; batch-creating agents with Promise.all but dispatching before all resolves; reusing pooled agents where one failed to initialize and was never recycled.","solutions":["Always `await agent.initialize()` before dispatching, and create agents via a factory that returns an initialized instance.","On initialize() failure, either retry initialization or drop the agent from the pool — do not dispatch to it.","In pools, gate acquisition on the agent being initialized (filter on a tracked flag).","Add a unit test that asserts every public entry point fails with this exact message pre-initialize, so regressions surface early."],"exampleFix":"// before\nconst agent = new AgenticFlowAgent(cfg);\nagent.executeTask(task); // forgot await initialize()\n\n// after\nconst agent = new AgenticFlowAgent(cfg);\nawait agent.initialize();\nawait agent.executeTask(task);","handlingStrategy":"validation","validationCode":"await agent.initialize();\n// only then:\nawait agent.executeTask(task);","typeGuard":"function isAgentReady(a: { initialized?: boolean }): boolean {\n  return a.initialized === true;\n}","tryCatchPattern":"try {\n  await agent.executeTask(task);\n} catch (e) {\n  if (/not initialized\\. Call initialize\\(\\) first/.test((e as Error).message)) {\n    await agent.initialize();\n    return agent.executeTask(task);\n  }\n  throw e;\n}","preventionTips":["Gate pool acquisition on an initialization flag you track per agent.","Never dispatch in the same tick as construction — always await the init promise.","On init failure, recycle the agent instead of leaving it half-alive in a pool."],"tags":["lifecycle","initialization","agent"],"backgroundTag":"not-initialized-guard","analyzedSha":"fa13ee4ad60ac2090b1480656eb233521790d640","analyzedAt":"2026-08-18T21:34:22.708Z","schemaVersion":2},"datasetVersion":"2026-08-22T04:17:13.399Z"}