{"record":{"id":"e078dc012e7cab5e","repo":"ruvnet/ruflo","slug":"registry-already-initialized","errorCode":null,"errorMessage":"Registry already initialized","messagePattern":"Registry already initialized","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"v3/@claude-flow/plugins/src/registry/enhanced-plugin-registry.ts","lineNumber":390,"sourceCode":"    }\n\n    // Shutdown and remove\n    await this.shutdownPlugin(name);\n    this.removePluginFromGraph(name);\n\n    this.logger.info(`Plugin unregistered: ${name}`);\n  }\n\n  // =========================================================================\n  // Initialization\n  // =========================================================================\n\n  /**\n   * Initialize all registered plugins.\n   */\n  async initialize(): Promise<void> {\n    if (this.initialized) {\n      throw new Error('Registry already initialized');\n    }\n\n    // Validate dependencies\n    const errors = this.dependencyGraph.validate();\n    const criticalErrors = errors.filter(e => e.type !== 'missing' || !this.isOptionalDependency(e));\n\n    if (criticalErrors.length > 0) {\n      const errorMessages = criticalErrors.map(e => e.message).join('\\n');\n      throw new Error(`Dependency validation failed:\\n${errorMessages}`);\n    }\n\n    // Initialize based on strategy\n    const strategy = this.config.initializationStrategy ?? 'sequential';\n\n    switch (strategy) {\n      case 'sequential':\n        await this.initializeSequential();\n        break;","sourceCodeStart":372,"sourceCodeEnd":408,"githubUrl":"https://github.com/ruvnet/ruflo/blob/fa13ee4ad60ac2090b1480656eb233521790d640/v3/@claude-flow/plugins/src/registry/enhanced-plugin-registry.ts#L372-L408","documentation":"Thrown by EnhancedPluginRegistry.initialize() when called on a registry whose initialized flag is already true. The flag is set at the end of a successful initialize(), so this error fires on any second initialize() call - including well-meant retries after a first call that succeeded.","triggerScenarios":"Calling initialize() in both an init hook and main() so it runs twice; a re-initialize-on-failure loop calling initialize() again after the first call already set initialized=true; sharing a module-level registry across tests that each call initialize().","commonSituations":"Framework lifecycle calling setup more than once (e.g. dev server restart in-process); tests reusing a singleton registry; orchestrator code that retries the whole boot step including initialize().","solutions":["Call initialize() exactly once per registry instance; guard boot code with a check of the registry's initialized state if exposed","For re-init after a bad state, create a new registry and re-register plugins rather than re-initializing the spent one","Move initialize() out of helper/retry functions into a single bootstrap point"],"exampleFix":"// before\nasync function boot() {\n  await registry.initialize();\n}\nawait boot();\nawait boot(); // second call -> Registry already initialized\n\n// after\nlet booted = false;\nasync function boot() {\n  if (booted) return;\n  await registry.initialize();\n  booted = true;\n}","handlingStrategy":"validation","validationCode":"if (!isRegistryInitialized(registry)) {\n  await registry.initialize();\n} else {\n  logger.debug('registry already initialized; skipping');\n}","typeGuard":"function isRegistryInitialized(\n  registry: object\n): boolean {\n  const r = registry as Record<string, unknown>;\n  if (typeof r['isInitialized'] === 'function') {\n    return (r['isInitialized'] as () => boolean)();\n  }\n  return r['initialized'] === true;\n}","tryCatchPattern":"try {\n  await registry.initialize();\n} catch (err) {\n  if (err instanceof Error && err.message === 'Registry already initialized') {\n    return; // idempotent bootstrap\n  }\n  throw err;\n}","preventionTips":["Initialize the registry in exactly one bootstrap location, guarded by a booted flag","In tests, create a new registry per test rather than re-initializing a shared one","Never put initialize() inside generic retry logic; retry the failed init step, not the whole lifecycle"],"tags":["double-initialization","lifecycle","plugin-registry","typescript"],"backgroundTag":"double-initialization","analyzedSha":"fa13ee4ad60ac2090b1480656eb233521790d640","analyzedAt":"2026-08-18T21:34:22.708Z","contentChangedAt":"2026-08-18T21:34:22.708Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}