{"record":{"id":"fdde9e80b4b38bd7","repo":"ruvnet/ruflo","slug":"worker-this-id-not-initialized-call-initialize","errorCode":null,"errorMessage":"Worker ${this.id} not initialized. Call initialize() first.","messagePattern":"Worker (.+?) not initialized\\. Call initialize\\(\\) first\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"v3/@claude-flow/integration/src/worker-base.ts","lineNumber":704,"sourceCode":"    });\n  }\n\n  /**\n   * Initialize coordination\n   */\n  private async initializeCoordination(): Promise<void> {\n    this.emit('coordination-initialized', {\n      workerId: this.id,\n      protocol: this.config.coordination?.protocol || 'direct',\n    });\n  }\n\n  /**\n   * Ensure worker is initialized\n   */\n  protected ensureInitialized(): void {\n    if (!this.initialized) {\n      throw new Error(`Worker ${this.id} not initialized. Call initialize() first.`);\n    }\n  }\n\n  /**\n   * Update metrics for successful task\n   */\n  private updateMetricsSuccess(duration: number, tokensUsed?: number): void {\n    this.metrics.tasksExecuted++;\n    this.metrics.tasksSucceeded++;\n\n    // Update average duration\n    const total = this.metrics.avgDuration * (this.metrics.tasksSucceeded - 1) + duration;\n    this.metrics.avgDuration = total / this.metrics.tasksSucceeded;\n\n    if (tokensUsed) {\n      this.metrics.totalTokensUsed += tokensUsed;\n    }\n  }","sourceCodeStart":686,"sourceCodeEnd":722,"githubUrl":"https://github.com/ruvnet/ruflo/blob/fa13ee4ad60ac2090b1480656eb233521790d640/v3/@claude-flow/integration/src/worker-base.ts#L686-L722","documentation":"WorkerBase.ensureInitialized throws when executeTask (and other init-dependent methods) run before a successful initialize(). this.initialized is set only at the end of the async setup, so any pre-init dispatch is rejected.","triggerScenarios":"Calling worker.executeTask(task) before await worker.initialize() resolves, or after initialization failed. Pools typically initialize workers during spawn, so this mostly bites manually constructed workers.","commonSituations":"Manually new-ing a worker instead of going through the pool; startup scripts dispatching before init completes; a failed initialize() being papered over with a direct dispatch.","solutions":["await worker.initialize() before the first executeTask","Prefer pool.spawn(...), which manages worker lifecycle including initialization","If initialize() itself failed, fix that error — this guard is downstream of it"],"exampleFix":"// before\nconst worker = new MyWorker({ id: 'w1' });\nawait worker.executeTask(task); // throws: initialize() not run\n\n// after\nconst worker = new MyWorker({ id: 'w1' });\nawait worker.initialize();\nawait worker.executeTask(task);","handlingStrategy":"validation","validationCode":"// Initialize once at creation, before any dispatch\nconst worker = new MyWorker({ id: 'w1' });\nawait worker.initialize();\n// or let the pool manage it: const worker = pool.spawn({ id: 'w1', type: 'coder' });","typeGuard":null,"tryCatchPattern":"try {\n  await worker.executeTask(task);\n} catch (e) {\n  if (e instanceof Error && e.message.includes('not initialized. Call initialize() first.')) {\n    await worker.initialize(); // then retry the task once\n    return worker.executeTask(task);\n  }\n  throw e;\n}","preventionTips":["Centralize worker creation so initialize() always precedes first use","Prefer pool.spawn over manual construction","Treat a failed initialize() as fatal for that worker — don't fall through to dispatch"],"tags":["initialization","lifecycle","worker","async"],"backgroundTag":"not-initialized","analyzedSha":"fa13ee4ad60ac2090b1480656eb233521790d640","analyzedAt":"2026-08-18T21:34:22.708Z","schemaVersion":2},"datasetVersion":"2026-08-21T13:17:26.733Z"}