{"record":{"id":"189d2d245cf85265","repo":"ruvnet/ruflo","slug":"attentioncoordinator-not-initialized-call-initial","errorCode":null,"errorMessage":"AttentionCoordinator not initialized. Call initialize() first.","messagePattern":"AttentionCoordinator not initialized\\. Call initialize\\(\\) first\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"v3/@claude-flow/integration/src/attention-coordinator.ts","lineNumber":677,"sourceCode":"    const len = Math.min(a.length, b.length);\n    for (let i = 0; i < len; i++) {\n      sum += a[i] * b[i];\n    }\n    return sum;\n  }\n\n  private cosineSimilarity(a: number[], b: number[]): number {\n    const dot = this.dotProduct(a, b);\n    const normA = Math.sqrt(this.dotProduct(a, a));\n    const normB = Math.sqrt(this.dotProduct(b, b));\n\n    if (normA === 0 || normB === 0) return 0;\n    return dot / (normA * normB);\n  }\n\n  private ensureInitialized(): void {\n    if (!this.initialized) {\n      throw new Error('AttentionCoordinator not initialized. Call initialize() first.');\n    }\n  }\n}\n\n/**\n * Create and initialize an AttentionCoordinator\n */\nexport async function createAttentionCoordinator(\n  config?: Partial<AttentionConfiguration>\n): Promise<AttentionCoordinator> {\n  const coordinator = new AttentionCoordinator(config);\n  await coordinator.initialize();\n  return coordinator;\n}\n","sourceCodeStart":659,"sourceCodeEnd":692,"githubUrl":"https://github.com/ruvnet/ruflo/blob/fa13ee4ad60ac2090b1480656eb233521790d640/v3/@claude-flow/integration/src/attention-coordinator.ts#L659-L692","documentation":"Thrown by AttentionCoordinator#ensureInitialized (v3/@claude-flow/integration/src/attention-coordinator.ts:677). Public computation/metrics methods call this guard, so using a coordinator before `await coordinator.initialize()` completes — or after a failed initialize — fails fast. The exported helper createAttentionCoordinator() initializes before returning and avoids the trap entirely.","triggerScenarios":"new AttentionCoordinator(cfg) followed immediately by a compute call without awaiting initialize(); concurrent initialize() still in flight; calling after initialize() threw (e.g. bad config caught earlier) without retrying.","commonSituations":"Missing await in async bootstrap; DI containers that construct but do not run async lifecycle hooks; tests constructing directly instead of using createAttentionCoordinator().","solutions":["Prefer the factory: `const coord = await createAttentionCoordinator(config);` — it initializes for you.","Or explicitly `await coordinator.initialize()` before any compute/metrics call.","If initialize() rejected, log and re-initialize or rebuild the coordinator; do not keep calling methods on it.","In DI setups, wire initialization into the container's async start phase."],"exampleFix":"// before\nconst coord = new AttentionCoordinator(cfg);\nconst out = coord.compute(...) // throws before init completes\n\n// after\nconst coord = await createAttentionCoordinator(cfg);\nconst out = coord.compute(...)","handlingStrategy":"validation","validationCode":"const coord = await createAttentionCoordinator(cfg); // factory initializes internally","typeGuard":"function isCoordinatorReady(c: { initialized?: boolean }): boolean {\n  return c.initialized === true;\n}","tryCatchPattern":"try {\n  result = coordinator.compute(input);\n} catch (e) {\n  if (/AttentionCoordinator not initialized/.test((e as Error).message)) {\n    await coordinator.initialize();\n    result = coordinator.compute(input);\n  } else throw e;\n}","preventionTips":["Always construct via createAttentionCoordinator() unless you have a reason not to.","Await initialize() in the async bootstrap before serving compute requests.","Wire async lifecycle into DI containers' start phase."],"tags":["lifecycle","initialization","attention"],"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-14T00:17:10.932Z"}