{"record":{"id":"0c5c83af2d95dba7","repo":"ruvnet/ruflo","slug":"swarm-already-initialized","errorCode":null,"errorMessage":"Swarm already initialized","messagePattern":"Swarm already initialized","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"v3/@claude-flow/plugins/src/integrations/agentic-flow.ts","lineNumber":157,"sourceCode":"    super();\n    this.config = {\n      version: 'alpha',\n      timeout: 30000,\n      maxConcurrentAgents: 15,\n      ...config,\n    };\n  }\n\n  // =========================================================================\n  // Swarm Coordination\n  // =========================================================================\n\n  /**\n   * Initialize a swarm with the specified topology.\n   */\n  async initializeSwarm(topology: SwarmTopology): Promise<void> {\n    if (this.swarmInitialized) {\n      throw new Error('Swarm already initialized');\n    }\n\n    this.swarmTopology = topology;\n    this.swarmInitialized = true;\n\n    this.emit(AGENTIC_FLOW_EVENTS.SWARM_INITIALIZED, {\n      topology,\n      timestamp: new Date(),\n    });\n\n    this.config.logger?.info(`Swarm initialized with ${topology.type} topology`);\n  }\n\n  /**\n   * Get current swarm status.\n   */\n  getSwarmStatus(): {\n    initialized: boolean;","sourceCodeStart":139,"sourceCodeEnd":175,"githubUrl":"https://github.com/ruvnet/ruflo/blob/fa13ee4ad60ac2090b1480656eb233521790d640/v3/@claude-flow/plugins/src/integrations/agentic-flow.ts#L139-L175","documentation":"initializeSwarm() is one-shot per integration instance: the swarmInitialized flag makes a second call throw. shutdownSwarm() is the supported way back to an initializable state. The flag is set before any event is emitted, so the throw happens with no topology changes applied.","triggerScenarios":"Two modules both calling initializeSwarm() on a shared singleton (server bootstrap plus a plugin's onInitialize); retry logic around init; dev-mode double-mount or HMR re-running setup on a surviving instance.","commonSituations":"Splitting boot code into helpers that each 'ensure' the swarm; retry-on-failure wrappers that do not distinguish 'already done' from 'failed'; tests reusing one integration across cases without shutdown.","solutions":["Guard initialization with the instance's initialized state or wrap it in once()","Call shutdownSwarm() before re-initializing on the same instance","Create a new AgenticFlowIntegration instance when a fresh swarm is genuinely needed"],"exampleFix":"// before\nawait flow.initializeSwarm(topology);\nawait flow.initializeSwarm(topology); // Error: Swarm already initialized\n\n// after\nconst initSwarm = once(() => flow.initializeSwarm(topology));\nawait initSwarm(); // repeated calls share the first invocation\n\n// or, when re-init is intended:\nawait flow.shutdownSwarm();\nawait flow.initializeSwarm(newTopology);","handlingStrategy":"validation","validationCode":"const initSwarm = once(() => flow.initializeSwarm(topology));\nawait initSwarm(); // all boot paths converge here\n\n// intentional re-init goes through shutdown first:\nawait flow.shutdownSwarm();\nawait flow.initializeSwarm(newTopology);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Initialize the swarm in exactly one place (bootstrap), not in each plugin","Wrap init in once() so double-mount and retry paths share one call","Call shutdownSwarm() before any deliberate re-initialization"],"tags":["swarm","lifecycle","double-initialization"],"backgroundTag":"already-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"}