ruvnet/ruflo · error

Cannot initialize from status: ${this.state.status}

Error message

Cannot initialize from status: ${this.state.status}

What it means

UnifiedSwarmCoordinator.initialize() is lifecycle-guarded: it only runs from status initializing (fresh instance) or stopped. Calling it on a running, paused, or degraded swarm throws to prevent re-initializing live components (topology manager, message bus, consensus engine) under active agents. The throw happens before the parallel component initialization starts.

Source

Thrown at v3/@claude-flow/swarm/src/unified-coordinator.ts:197

    this.initializeDomainConfigs();

    this.setupEventForwarding();
  }

  // =============================================================================
  // Domain Configuration Initialization
  // =============================================================================

  private initializeDomainConfigs(): void {
    for (const config of DOMAIN_CONFIGS) {
      this.domainConfigs.set(config.name, config);
      this.domainTaskQueues.set(config.name, []);
    }
  }

  async initialize(): Promise<void> {
    if (this.state.status !== 'initializing' && this.state.status !== 'stopped') {
      throw new Error(`Cannot initialize from status: ${this.state.status}`);
    }

    const startTime = performance.now();

    try {
      // Initialize all components in parallel
      await Promise.all([
        this.topologyManager.initialize(this.config.topology),
        this.messageBus.initialize(this.config.messageBus),
        this.consensusEngine.initialize(this.config.consensus),
      ]);

      // Initialize default agent pools
      await this.initializeAgentPools();

      // Start background processes
      this.startBackgroundProcesses();

View on GitHub (pinned to fa13ee4ad6)

Solutions

  1. Call stop() first, then initialize() again; stop transitions the status back to an initializable state
  2. Or construct a fresh UnifiedSwarmCoordinator instead of reusing the instance
  3. Guard bootstrap code against double execution (an idempotent started promise or flag) in hot-reload environments

Example fix

// before
await coordinator.initialize();
await coordinator.initialize(); // throws: status is running

// after
await coordinator.initialize();
await coordinator.stop();
await coordinator.initialize(); // ok: status is stopped
Defensive patterns

Strategy: try-catch

Validate before calling

// Only initialize from an initializable lifecycle state
const status = (coordinator as any).state?.status;
if (status && status !== 'initializing' && status !== 'stopped') {
  await coordinator.stop();
}
await coordinator.initialize();

Type guard

function isInitializable(status: 'initializing' | 'running' | 'paused' | 'stopped' | 'degraded'): boolean {
  return status === 'initializing' || status === 'stopped';
}

Try / catch

try {
  await coordinator.initialize();
} catch (err) {
  if (err instanceof Error && err.message.startsWith('Cannot initialize from status')) {
    await coordinator.stop();
    return coordinator.initialize();
  }
  throw err;
}

Prevention

When it happens

Trigger: Double-invoking initialize() (for example an init wrapper with retry); hot-reload re-running bootstrap code on the same instance; calling initialize() on a paused swarm instead of resume().

Common situations: Dev servers with hot reload re-running module bootstrap; retry decorators around startup; singleton coordinators shared across tests without reset.

Understand the failure class

Background: "Invalid state transition" errors: "status must be X, actually Y", "already rejected/charging/uninstalled", "cannot ... while running" — what they mean when a library rejects your call — this error's family across 31 libraries.

Related errors


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