ruvnet/ruflo · error
Swarm not initialized
Error message
Swarm not initialized
What it means
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.
Source
Thrown at v3/@claude-flow/plugins/src/integrations/agentic-flow.ts:217
for (const agentId of this.agents.keys()) {
await this.terminateAgent(agentId);
}
this.swarmInitialized = false;
this.swarmTopology = undefined;
this.config.logger?.info('Swarm shutdown complete');
}
// =========================================================================
// Agent Management
// =========================================================================
/**
* Spawn a new agent.
*/
async spawnAgent(options: AgentSpawnOptions): Promise<SpawnedAgent> {
if (!this.swarmInitialized) {
throw new Error('Swarm not initialized');
}
if (this.agents.size >= (this.config.maxConcurrentAgents ?? 15)) {
throw new Error(`Maximum agent limit (${this.config.maxConcurrentAgents}) reached`);
}
const id = options.id ?? `agent-${this.nextAgentId++}`;
if (this.agents.has(id)) {
throw new Error(`Agent ${id} already exists`);
}
const agent: SpawnedAgent = {
id,
type: options.type,
status: 'active',
capabilities: options.capabilities ?? [],
parentId: options.parentId,View on GitHub (pinned to fa13ee4ad6)
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
Example fix
// before
flow.initializeSwarm(topology); // missing await
await flow.spawnAgent({ type: 'coder' }); // Error: Swarm not initialized
// after
await flow.initializeSwarm(topology);
await flow.spawnAgent({ type: 'coder' }); Defensive patterns
Strategy: validation
Validate before calling
await flow.initializeSwarm({ type: 'mesh' }); // 1. always first, always awaited
const agent = await flow.spawnAgent({ type: 'coder' }); // 2. then spawn Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- SwarmAdapter not initialized. Call initialize() first.
- Maximum agent limit (${this.config.maxConcurrentAgents}) rea
- Agent ${id} already exists
- Agent ${agentId} not found
- No available agents
AI-assisted analysis of ruvnet/ruflo@fa13ee4ad6 (2026-08-18).
Data as JSON: /api/errors/2e53792eeaa1b242.
Report an issue: GitHub.