ruvnet/ruflo · error

Maximum tasks (${this.config.maxTasks}) reached

Error message

Maximum tasks (${this.config.maxTasks}) reached

What it means

submitTask() enforces the maxTasks ceiling: once state.tasks.size reaches config.maxTasks, new submissions throw before a task id is created. The guard acts as backpressure; long-running swarms accumulate completed tasks in the map until something prunes them, which is the usual root cause.

Source

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

  }

  getAgentsByType(type: AgentType): AgentState[] {
    return this.getAllAgents().filter(a => a.type === type);
  }

  getAvailableAgents(): AgentState[] {
    return this.getAllAgents().filter(a => a.status === 'idle');
  }

  // ===== TASK MANAGEMENT =====

  async submitTask(
    taskData: Omit<TaskDefinition, 'id' | 'status' | 'createdAt'>
  ): Promise<string> {
    const startTime = performance.now();

    if (this.state.tasks.size >= this.config.maxTasks) {
      throw new Error(`Maximum tasks (${this.config.maxTasks}) reached`);
    }

    this.taskCounter++;
    const taskId: TaskId = {
      id: `task_${this.state.id.id}_${this.taskCounter}`,
      swarmId: this.state.id.id,
      sequence: this.taskCounter,
      priority: taskData.priority,
    };

    const task: TaskDefinition = {
      ...taskData,
      id: taskId,
      status: 'created',
      createdAt: new Date(),
    };

    this.state.tasks.set(taskId.id, task);

View on GitHub (pinned to fa13ee4ad6)

Solutions

  1. Raise maxTasks in the coordinator config for batch workloads
  2. Prune or archive completed and failed tasks from state.tasks so the map does not stay full
  3. Throttle submissions and retry with backoff at capacity instead of letting the producer crash

Example fix

// before
const coordinator = new UnifiedSwarmCoordinator({ ...baseConfig, maxTasks: 100 });
await Promise.all(items.map(i => coordinator.submitTask(toTask(i)))); // throws at #101

// after
const coordinator = new UnifiedSwarmCoordinator({ ...baseConfig, maxTasks: items.length });
await Promise.all(items.map(i => coordinator.submitTask(toTask(i))));
Defensive patterns

Strategy: retry

Validate before calling

// Submit with backoff: treat the capacity error as backpressure
async function submitWithBackoff(coordinator: UnifiedSwarmCoordinator, task: TaskInput, attempts = 5): Promise<string> {
  for (let i = 0; i < attempts; i++) {
    try {
      return await coordinator.submitTask(task);
    } catch (err) {
      if (!(err instanceof Error && err.message.includes('Maximum tasks'))) throw err;
      await new Promise(r => setTimeout(r, 2 ** i * 100)); // tasks complete, slots free
    }
  }
  throw new Error('Task table stayed at maxTasks after retries');
}

Try / catch

try {
  taskId = await coordinator.submitTask(taskData);
} catch (err) {
  if (err instanceof Error && err.message.includes('Maximum tasks')) {
    await drainCompletedTasks(coordinator); // prune finished tasks, then retry once
    taskId = await coordinator.submitTask(taskData);
  } else {
    throw err;
  }
}

Prevention

When it happens

Trigger: Sustained task submission beyond config.maxTasks without pruning earlier tasks; batch jobs submitting thousands of tasks against a small limit; completed tasks never removed from state.tasks.

Common situations: Demo-sized defaults used for production batches; tasks retained for audit keeping the map full; fan-out workloads (one task per item) exceeding the limit.

Related errors


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