{"record":{"id":"12b5753a2d81b5fa","repo":"ruvnet/ruflo","slug":"pool-this-config-name-is-at-maximum-capacity","errorCode":null,"errorMessage":"Pool ${this.config.name} is at maximum capacity","messagePattern":"Pool (.+?) is at maximum capacity","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"v3/@claude-flow/swarm/src/agent-pool.ts","lineNumber":154,"sourceCode":"      return;\n    }\n\n    this.busy.delete(agentId);\n    this.available.add(agentId);\n    pooled.acquiredAt = undefined;\n    pooled.lastUsed = new Date();\n    pooled.agent.status = 'idle';\n    pooled.agent.currentTask = undefined;\n\n    this.emit('agent.released', { agentId });\n\n    // Check if we need to scale down\n    await this.checkScaling();\n  }\n\n  async add(agent: AgentState): Promise<void> {\n    if (this.pooledAgents.size >= this.config.maxSize) {\n      throw new Error(`Pool ${this.config.name} is at maximum capacity`);\n    }\n\n    const pooled: PooledAgent = {\n      agent,\n      lastUsed: new Date(),\n      usageCount: 0,\n    };\n\n    this.pooledAgents.set(agent.id.id, pooled);\n    this.available.add(agent.id.id);\n\n    this.emit('agent.added', { agentId: agent.id.id });\n  }\n\n  async remove(agentId: string): Promise<void> {\n    const pooled = this.pooledAgents.get(agentId);\n    if (!pooled) {\n      return;","sourceCodeStart":136,"sourceCodeEnd":172,"githubUrl":"https://github.com/ruvnet/ruflo/blob/fa13ee4ad60ac2090b1480656eb233521790d640/v3/@claude-flow/swarm/src/agent-pool.ts#L136-L172","documentation":"AgentPool caps the number of pooled agents at config.maxSize. add() throws when pooledAgents.size has already reached maxSize — the pool never silently grows past its configured bound. Slots become available again only through release(), which returns an agent to idle and may trigger scale-down via checkScaling().","triggerScenarios":"Calling add() while the pool already holds maxSize agents; agents acquired for work but never release()d (leak); an auto-scaler spawning new agents into a full pool; maxSize configured below the number of concurrently needed agents.","commonSituations":"Missing release() in a finally block after task execution; long-lived idle agents occupying slots; pool sizing never revisited after traffic grew; scale-up loop ignoring pool capacity.","solutions":["Release agents when their work finishes: call pool.release(agentId) in try/finally.","Increase config.maxSize to match the maximum number of concurrent agents.","Before add(), compare current pool occupancy against maxSize and drain idle agents first.","Diagnose leaks: 'agent.added' events should be balanced by 'agent.released'; use lastUsed/usageCount stats to find holders."],"exampleFix":"// before — agents added but never released; pool pins at maxSize\nawait pool.add(agent);\nawait runTask(agent);\n\n// after — release in finally and size the cap for peak concurrency\nconst pool = new AgentPool({ name: 'workers', maxSize: peakConcurrency });\nawait pool.add(agent);\ntry {\n  await runTask(agent);\n} finally {\n  await pool.release(agent.id.id);\n}","handlingStrategy":"try-catch","validationCode":"// track occupancy yourself: every add must pair with a release\nlet inPool = 0;\nawait pool.add(agent); inPool++;\ntry {\n  await runTask(agent);\n} finally {\n  await pool.release(agent.id.id);\n  inPool--;\n}\n// check inPool < config.maxSize before the next add","typeGuard":null,"tryCatchPattern":"try {\n  await pool.add(agent);\n} catch (e) {\n  if (e instanceof Error && e.message.endsWith('is at maximum capacity')) {\n    await drainIdleOrWaitForRelease(); // or rebuild the pool with a larger maxSize\n  } else {\n    throw e;\n  }\n}","preventionTips":["Pair every add/acquire with release() in a finally block.","Set maxSize for worst-case concurrent agents, not average load.","Alert when occupancy pins at maxSize — it indicates a release leak or an undersized cap."],"tags":["pool","capacity","agent","resource-leak"],"backgroundTag":"resource-pool-exhausted","analyzedSha":"fa13ee4ad60ac2090b1480656eb233521790d640","analyzedAt":"2026-08-18T21:34:22.708Z","schemaVersion":2},"datasetVersion":"2026-08-22T04:17:13.399Z"}