{"record":{"id":"58e8aa066450c636","repo":"ruvnet/ruflo","slug":"maximum-tasks-this-config-maxtasks-reached","errorCode":null,"errorMessage":"Maximum tasks (${this.config.maxTasks}) reached","messagePattern":"Maximum tasks \\((.+?)\\) reached","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"v3/@claude-flow/swarm/src/unified-coordinator.ts","lineNumber":396,"sourceCode":"  }\n\n  getAgentsByType(type: AgentType): AgentState[] {\n    return this.getAllAgents().filter(a => a.type === type);\n  }\n\n  getAvailableAgents(): AgentState[] {\n    return this.getAllAgents().filter(a => a.status === 'idle');\n  }\n\n  // ===== TASK MANAGEMENT =====\n\n  async submitTask(\n    taskData: Omit<TaskDefinition, 'id' | 'status' | 'createdAt'>\n  ): Promise<string> {\n    const startTime = performance.now();\n\n    if (this.state.tasks.size >= this.config.maxTasks) {\n      throw new Error(`Maximum tasks (${this.config.maxTasks}) reached`);\n    }\n\n    this.taskCounter++;\n    const taskId: TaskId = {\n      id: `task_${this.state.id.id}_${this.taskCounter}`,\n      swarmId: this.state.id.id,\n      sequence: this.taskCounter,\n      priority: taskData.priority,\n    };\n\n    const task: TaskDefinition = {\n      ...taskData,\n      id: taskId,\n      status: 'created',\n      createdAt: new Date(),\n    };\n\n    this.state.tasks.set(taskId.id, task);","sourceCodeStart":378,"sourceCodeEnd":414,"githubUrl":"https://github.com/ruvnet/ruflo/blob/fa13ee4ad60ac2090b1480656eb233521790d640/v3/@claude-flow/swarm/src/unified-coordinator.ts#L378-L414","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Raise maxTasks in the coordinator config for batch workloads","Prune or archive completed and failed tasks from state.tasks so the map does not stay full","Throttle submissions and retry with backoff at capacity instead of letting the producer crash"],"exampleFix":"// before\nconst coordinator = new UnifiedSwarmCoordinator({ ...baseConfig, maxTasks: 100 });\nawait Promise.all(items.map(i => coordinator.submitTask(toTask(i)))); // throws at #101\n\n// after\nconst coordinator = new UnifiedSwarmCoordinator({ ...baseConfig, maxTasks: items.length });\nawait Promise.all(items.map(i => coordinator.submitTask(toTask(i))));","handlingStrategy":"retry","validationCode":"// Submit with backoff: treat the capacity error as backpressure\nasync function submitWithBackoff(coordinator: UnifiedSwarmCoordinator, task: TaskInput, attempts = 5): Promise<string> {\n  for (let i = 0; i < attempts; i++) {\n    try {\n      return await coordinator.submitTask(task);\n    } catch (err) {\n      if (!(err instanceof Error && err.message.includes('Maximum tasks'))) throw err;\n      await new Promise(r => setTimeout(r, 2 ** i * 100)); // tasks complete, slots free\n    }\n  }\n  throw new Error('Task table stayed at maxTasks after retries');\n}","typeGuard":null,"tryCatchPattern":"try {\n  taskId = await coordinator.submitTask(taskData);\n} catch (err) {\n  if (err instanceof Error && err.message.includes('Maximum tasks')) {\n    await drainCompletedTasks(coordinator); // prune finished tasks, then retry once\n    taskId = await coordinator.submitTask(taskData);\n  } else {\n    throw err;\n  }\n}","preventionTips":["Size maxTasks above peak concurrent plus queued work","Archive finished tasks out of state.tasks on a schedule","Producers should treat this error as backpressure rather than a crash"],"tags":["unified-coordinator","capacity","task-queue","backpressure"],"backgroundTag":"queue-full","analyzedSha":"fa13ee4ad60ac2090b1480656eb233521790d640","analyzedAt":"2026-08-18T21:34:22.708Z","schemaVersion":2},"datasetVersion":"2026-08-22T04:17:13.399Z"}