ruvnet/ruflo · error

Worker not initialized. Call initialize() first.

Error message

Worker ${this.id} not initialized. Call initialize() first.

What it means

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.

Solutions

  1. await worker.initialize() before the first executeTask
  2. Prefer pool.spawn(...), which manages worker lifecycle including initialization
  3. If initialize() itself failed, fix that error — this guard is downstream of it

Example fix

// before
const worker = new MyWorker({ id: 'w1' });
await worker.executeTask(task); // throws: initialize() not run

// after
const worker = new MyWorker({ id: 'w1' });
await worker.initialize();
await worker.executeTask(task);
Defensive patterns

Strategy: validation

Validate before calling

// Initialize once at creation, before any dispatch
const worker = new MyWorker({ id: 'w1' });
await worker.initialize();
// or let the pool manage it: const worker = pool.spawn({ id: 'w1', type: 'coder' });

Try / catch

try {
  await worker.executeTask(task);
} catch (e) {
  if (e instanceof Error && e.message.includes('not initialized. Call initialize() first.')) {
    await worker.initialize(); // then retry the task once
    return worker.executeTask(task);
  }
  throw e;
}

Prevention

When it happens

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

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

Related errors


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

Appendix: source

Thrown at v3/@claude-flow/integration/src/worker-base.ts:704

    });
  }

  /**
   * Initialize coordination
   */
  private async initializeCoordination(): Promise<void> {
    this.emit('coordination-initialized', {
      workerId: this.id,
      protocol: this.config.coordination?.protocol || 'direct',
    });
  }

  /**
   * Ensure worker is initialized
   */
  protected ensureInitialized(): void {
    if (!this.initialized) {
      throw new Error(`Worker ${this.id} not initialized. Call initialize() first.`);
    }
  }

  /**
   * Update metrics for successful task
   */
  private updateMetricsSuccess(duration: number, tokensUsed?: number): void {
    this.metrics.tasksExecuted++;
    this.metrics.tasksSucceeded++;

    // Update average duration
    const total = this.metrics.avgDuration * (this.metrics.tasksSucceeded - 1) + duration;
    this.metrics.avgDuration = total / this.metrics.tasksSucceeded;

    if (tokensUsed) {
      this.metrics.totalTokensUsed += tokensUsed;
    }
  }

View on GitHub (pinned to fa13ee4ad6)