ruvnet/ruflo · error · Error

Swarm already initialized

Error message

Swarm already initialized

What it means

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.

Source

Thrown at v3/@claude-flow/plugins/src/integrations/agentic-flow.ts:157

    super();
    this.config = {
      version: 'alpha',
      timeout: 30000,
      maxConcurrentAgents: 15,
      ...config,
    };
  }

  // =========================================================================
  // Swarm Coordination
  // =========================================================================

  /**
   * Initialize a swarm with the specified topology.
   */
  async initializeSwarm(topology: SwarmTopology): Promise<void> {
    if (this.swarmInitialized) {
      throw new Error('Swarm already initialized');
    }

    this.swarmTopology = topology;
    this.swarmInitialized = true;

    this.emit(AGENTIC_FLOW_EVENTS.SWARM_INITIALIZED, {
      topology,
      timestamp: new Date(),
    });

    this.config.logger?.info(`Swarm initialized with ${topology.type} topology`);
  }

  /**
   * Get current swarm status.
   */
  getSwarmStatus(): {
    initialized: boolean;

View on GitHub (pinned to fa13ee4ad6)

Solutions

  1. Guard initialization with the instance's initialized state or wrap it in once()
  2. Call shutdownSwarm() before re-initializing on the same instance
  3. Create a new AgenticFlowIntegration instance when a fresh swarm is genuinely needed

Example fix

// before
await flow.initializeSwarm(topology);
await flow.initializeSwarm(topology); // Error: Swarm already initialized

// after
const initSwarm = once(() => flow.initializeSwarm(topology));
await initSwarm(); // repeated calls share the first invocation

// or, when re-init is intended:
await flow.shutdownSwarm();
await flow.initializeSwarm(newTopology);
Defensive patterns

Strategy: validation

Validate before calling

const initSwarm = once(() => flow.initializeSwarm(topology));
await initSwarm(); // all boot paths converge here

// intentional re-init goes through shutdown first:
await flow.shutdownSwarm();
await flow.initializeSwarm(newTopology);

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of ruvnet/ruflo@fa13ee4ad6 (2026-08-18). Data as JSON: /api/errors/0c5c83af2d95dba7. Report an issue: GitHub.