{"record":{"id":"baa41ab5f23e8d6d","repo":"ruvnet/ruflo","slug":"federationcoordinator-is-not-initialized-call-ini","errorCode":null,"errorMessage":"FederationCoordinator is not initialized. Call initialize() first.","messagePattern":"FederationCoordinator is not initialized\\. Call initialize\\(\\) first\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"v3/@claude-flow/plugin-agent-federation/src/application/federation-coordinator.ts","lineNumber":686,"sourceCode":"      targetNodeId: node.nodeId,\n      trustLevel: session.trustLevel,\n    });\n\n    return session;\n  }\n\n  private findSessionByNodeId(nodeId: string): FederationSession | undefined {\n    for (const session of this.sessions.values()) {\n      if (session.remoteNodeId === nodeId && session.active) {\n        return session;\n      }\n    }\n    return undefined;\n  }\n\n  private ensureInitialized(): void {\n    if (!this.initialized) {\n      throw new Error('FederationCoordinator is not initialized. Call initialize() first.');\n    }\n  }\n}\n","sourceCodeStart":668,"sourceCodeEnd":690,"githubUrl":"https://github.com/ruvnet/ruflo/blob/fa13ee4ad60ac2090b1480656eb233521790d640/v3/@claude-flow/plugin-agent-federation/src/application/federation-coordinator.ts#L668-L690","documentation":"Lifecycle guard on FederationCoordinator: operational methods call ensureInitialized(), which throws this unless initialize() has completed. The guard exists because transport, session tables, and policy state are only usable after initialization, and calling earlier would operate on half-built state.","triggerScenarios":"Calling send/connect/claim operations before awaiting initialize(); initialize() rejected but the caller swallowed the error and continued; using a coordinator after shutdown() with the initialized flag cleared.","commonSituations":"Fire-and-forget startup where a message send races the init promise; DI wiring that lazily constructs but eagerly calls; catch blocks that log init failures without halting the flow.","solutions":["await coordinator.initialize() — and handle its rejection — before any other call","Gate all uses behind the initialization promise (store it and await it at each entry point)","If initialize() failed, stop: log and surface the failure instead of continuing to use the coordinator","After shutdown(), create a new coordinator rather than reusing the instance"],"exampleFix":"// before\nconst c = new FederationCoordinator(cfg);\nc.sendMessage(msg); // throws\n// after\nconst c = new FederationCoordinator(cfg);\nawait c.initialize();\nc.sendMessage(msg);","handlingStrategy":"validation","validationCode":"const coordinator = new FederationCoordinator(cfg);\nconst ready = coordinator.initialize().catch(e => {\n  log.error('federation init failed', e);\n  throw e;\n});\n// gate every subsequent use\nawait ready;\ncoordinator.sendMessage(msg);","typeGuard":null,"tryCatchPattern":"try {\n  coordinator.sendMessage(msg);\n} catch (e) {\n  if (String(e).includes('not initialized')) {\n    await coordinator.initialize();\n    coordinator.sendMessage(msg); // retry once after init\n  } else {\n    throw e;\n  }\n}","preventionTips":["Create a single startup path that awaits initialize() before serving traffic","Store the init promise and await it at every entry point","Treat initialize() rejection as fatal — do not continue using the coordinator","Re-create the coordinator after shutdown instead of reusing it"],"tags":["lifecycle","initialization"],"backgroundTag":"not-initialized","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"}