{"record":{"id":"2e53792eeaa1b242","repo":"ruvnet/ruflo","slug":"swarm-not-initialized","errorCode":null,"errorMessage":"Swarm not initialized","messagePattern":"Swarm not initialized","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"v3/@claude-flow/plugins/src/integrations/agentic-flow.ts","lineNumber":217,"sourceCode":"    for (const agentId of this.agents.keys()) {\n      await this.terminateAgent(agentId);\n    }\n\n    this.swarmInitialized = false;\n    this.swarmTopology = undefined;\n    this.config.logger?.info('Swarm shutdown complete');\n  }\n\n  // =========================================================================\n  // Agent Management\n  // =========================================================================\n\n  /**\n   * Spawn a new agent.\n   */\n  async spawnAgent(options: AgentSpawnOptions): Promise<SpawnedAgent> {\n    if (!this.swarmInitialized) {\n      throw new Error('Swarm not initialized');\n    }\n\n    if (this.agents.size >= (this.config.maxConcurrentAgents ?? 15)) {\n      throw new Error(`Maximum agent limit (${this.config.maxConcurrentAgents}) reached`);\n    }\n\n    const id = options.id ?? `agent-${this.nextAgentId++}`;\n\n    if (this.agents.has(id)) {\n      throw new Error(`Agent ${id} already exists`);\n    }\n\n    const agent: SpawnedAgent = {\n      id,\n      type: options.type,\n      status: 'active',\n      capabilities: options.capabilities ?? [],\n      parentId: options.parentId,","sourceCodeStart":199,"sourceCodeEnd":235,"githubUrl":"https://github.com/ruvnet/ruflo/blob/fa13ee4ad60ac2090b1480656eb233521790d640/v3/@claude-flow/plugins/src/integrations/agentic-flow.ts#L199-L235","documentation":"spawnAgent() requires a prior successful initializeSwarm(); the swarmInitialized flag guards it and the throw happens before any agent bookkeeping. Note that shutdownSwarm() resets the flag, so spawning after a shutdown hits this until the swarm is re-initialized.","triggerScenarios":"Calling spawnAgent() before await initializeSwarm(...) resolves (missing await or a race); initializeSwarm() having failed earlier so the flag was never set; spawning after shutdownSwarm() without re-init.","commonSituations":"Async boot races where a queue consumer starts spawning before the init promise settles; init errors swallowed upstream so callers proceed anyway; tests skipping the init step.","solutions":["await integration.initializeSwarm(topology) before any spawnAgent call","Chain boot strictly: init swarm, then spawn agents, then orchestrate; store the init promise and await it everywhere it matters","If init can fail, catch it and abort boot before attempting to spawn"],"exampleFix":"// before\nflow.initializeSwarm(topology); // missing await\nawait flow.spawnAgent({ type: 'coder' }); // Error: Swarm not initialized\n\n// after\nawait flow.initializeSwarm(topology);\nawait flow.spawnAgent({ type: 'coder' });","handlingStrategy":"validation","validationCode":"await flow.initializeSwarm({ type: 'mesh' }); // 1. always first, always awaited\nconst agent = await flow.spawnAgent({ type: 'coder' }); // 2. then spawn","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Chain boot with awaits: initializeSwarm → spawnAgent → orchestrateTask","Capture the init promise and await it in any code that can race startup","Abort boot on init failure instead of letting spawn calls hit the guard"],"tags":["swarm","agents","initialization-order","async"],"backgroundTag":"not-initialized","analyzedSha":"fa13ee4ad60ac2090b1480656eb233521790d640","analyzedAt":"2026-08-18T21:34:22.708Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}