{"record":{"id":"517e78a79ae2c949","repo":"ruvnet/ruflo","slug":"cannot-initialize-from-status-this-state-status","errorCode":null,"errorMessage":"Cannot initialize from status: ${this.state.status}","messagePattern":"Cannot initialize from status: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"v3/@claude-flow/swarm/src/unified-coordinator.ts","lineNumber":197,"sourceCode":"    this.initializeDomainConfigs();\n\n    this.setupEventForwarding();\n  }\n\n  // =============================================================================\n  // Domain Configuration Initialization\n  // =============================================================================\n\n  private initializeDomainConfigs(): void {\n    for (const config of DOMAIN_CONFIGS) {\n      this.domainConfigs.set(config.name, config);\n      this.domainTaskQueues.set(config.name, []);\n    }\n  }\n\n  async initialize(): Promise<void> {\n    if (this.state.status !== 'initializing' && this.state.status !== 'stopped') {\n      throw new Error(`Cannot initialize from status: ${this.state.status}`);\n    }\n\n    const startTime = performance.now();\n\n    try {\n      // Initialize all components in parallel\n      await Promise.all([\n        this.topologyManager.initialize(this.config.topology),\n        this.messageBus.initialize(this.config.messageBus),\n        this.consensusEngine.initialize(this.config.consensus),\n      ]);\n\n      // Initialize default agent pools\n      await this.initializeAgentPools();\n\n      // Start background processes\n      this.startBackgroundProcesses();\n","sourceCodeStart":179,"sourceCodeEnd":215,"githubUrl":"https://github.com/ruvnet/ruflo/blob/fa13ee4ad60ac2090b1480656eb233521790d640/v3/@claude-flow/swarm/src/unified-coordinator.ts#L179-L215","documentation":"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.","triggerScenarios":"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().","commonSituations":"Dev servers with hot reload re-running module bootstrap; retry decorators around startup; singleton coordinators shared across tests without reset.","solutions":["Call stop() first, then initialize() again; stop transitions the status back to an initializable state","Or construct a fresh UnifiedSwarmCoordinator instead of reusing the instance","Guard bootstrap code against double execution (an idempotent started promise or flag) in hot-reload environments"],"exampleFix":"// before\nawait coordinator.initialize();\nawait coordinator.initialize(); // throws: status is running\n\n// after\nawait coordinator.initialize();\nawait coordinator.stop();\nawait coordinator.initialize(); // ok: status is stopped","handlingStrategy":"try-catch","validationCode":"// Only initialize from an initializable lifecycle state\nconst status = (coordinator as any).state?.status;\nif (status && status !== 'initializing' && status !== 'stopped') {\n  await coordinator.stop();\n}\nawait coordinator.initialize();","typeGuard":"function isInitializable(status: 'initializing' | 'running' | 'paused' | 'stopped' | 'degraded'): boolean {\n  return status === 'initializing' || status === 'stopped';\n}","tryCatchPattern":"try {\n  await coordinator.initialize();\n} catch (err) {\n  if (err instanceof Error && err.message.startsWith('Cannot initialize from status')) {\n    await coordinator.stop();\n    return coordinator.initialize();\n  }\n  throw err;\n}","preventionTips":["Make bootstrap idempotent with a module-level started promise that guards double init","Create a fresh coordinator per test instead of re-initializing a shared one","Never wrap initialize() in a naive retry loop without stop() in between"],"tags":["lifecycle","state-machine","initialization","unified-coordinator"],"backgroundTag":"invalid-state-transition","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"}