{"record":{"id":"96b58c21dfb7d7ec","repo":"ruvnet/ruflo","slug":"max-sessions-this-config-maxsessions-reached","errorCode":null,"errorMessage":"Max sessions (${this.config.maxSessions}) reached","messagePattern":"Max sessions \\((.+?)\\) reached","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"v3/@claude-flow/browser/src/application/browser-service.ts","lineNumber":488,"sourceCode":"// ============================================================================\n// Browser Swarm Coordinator\n// ============================================================================\n\nexport class BrowserSwarmCoordinator {\n  private config: BrowserSwarmConfig;\n  private services: Map<string, BrowserService> = new Map();\n  private sharedData: Map<string, unknown> = new Map();\n\n  constructor(config: BrowserSwarmConfig) {\n    this.config = config;\n  }\n\n  /**\n   * Spawn a new browser agent in the swarm\n   */\n  async spawnAgent(role: 'navigator' | 'scraper' | 'validator' | 'tester' | 'monitor'): Promise<BrowserService> {\n    if (this.services.size >= this.config.maxSessions) {\n      throw new Error(`Max sessions (${this.config.maxSessions}) reached`);\n    }\n\n    const sessionId = `${this.config.sessionPrefix}-${role}-${Date.now()}`;\n    const service = new BrowserService({\n      sessionId,\n      role,\n      capabilities: this.getCapabilitiesForRole(role),\n      defaultTimeout: 30000,\n      headless: true,\n    });\n\n    this.services.set(sessionId, service);\n    return service;\n  }\n\n  /**\n   * Get capabilities for a role\n   */","sourceCodeStart":470,"sourceCodeEnd":506,"githubUrl":"https://github.com/ruvnet/ruflo/blob/fa13ee4ad60ac2090b1480656eb233521790d640/v3/@claude-flow/browser/src/application/browser-service.ts#L470-L506","documentation":"Thrown by BrowserSwarmCoordinator.spawnAgent in @claude-flow/browser when the number of live browser services (this.services) has reached the configured maxSessions ceiling. Each spawned navigator/scraper/validator/tester/monitor role creates a real BrowserService session, and the coordinator enforces a hard cap before creating a new one. The default cap is 5 (createBrowserSwarm defaults maxSessions to 5).","triggerScenarios":"Calling swarm.spawnAgent(role) when services.size >= config.maxSessions, e.g. spawning a 6th agent with the default config, or repeatedly spawning testers/monitors without terminating prior sessions. Sessions removed only via shutdown/termination of individual services.","commonSituations":"Loops that spawn one browser per task/page without closing finished ones; raising parallelism (e.g. shard count) without scaling maxSessions; long-running swarms where crashed branches are never reaped so stale entries keep services.size at the cap.","solutions":["Terminate or shut down idle/finished sessions before spawning new ones so services.size drops below the cap","Pass a higher maxSessions in the BrowserSwarmConfig given to createBrowserSwarm (e.g. createBrowserSwarm({ maxSessions: 20 })) sized to the host's browser capacity","Call swarm.getStats() first and gate spawning on activeSessions < maxSessions instead of blind-spawning","Wrap spawnAgent in a retry-with-backoff that waits for other agents to finish when the workload is bursty"],"exampleFix":"// before\nconst swarm = createBrowserSwarm(); // maxSessions defaults to 5\nfor (const url of urls) {\n  const agent = await swarm.spawnAgent('scraper'); // throws on 6th\n}\n\n// after\nconst swarm = createBrowserSwarm({ maxSessions: urls.length });\nfor (const url of urls) {\n  const agent = await swarm.spawnAgent('scraper');\n  // ...await agent work...\n  await agent.shutdown(); // free the slot before next spawn\n}","handlingStrategy":"validation","validationCode":"const stats = swarm.getStats(); // { activeSessions, maxSessions, topology }\nif (stats.activeSessions >= stats.maxSessions) {\n  throw new Error(`spawn would exceed cap; terminate a session or raise maxSessions (currently ${stats.maxSessions})`);\n}\nconst agent = await swarm.spawnAgent('scraper');","typeGuard":null,"tryCatchPattern":"try { await swarm.spawnAgent(role); } catch (e) { if (e instanceof Error && e.message.startsWith('Max sessions')) { /* terminate idle sessions or backoff */ } throw e; }","preventionTips":["Track spawned BrowserService instances and shutdown() each one in a finally block","Size maxSessions to match available browser/host capacity when configuring the swarm","Gate batch spawns on getStats().activeSessions < maxSessions"],"tags":["browser","session-limit","capacity","swarm"],"backgroundTag":"resource-limit-reached","analyzedSha":"fa13ee4ad60ac2090b1480656eb233521790d640","analyzedAt":"2026-08-18T21:34:22.708Z","contentChangedAt":"2026-08-18T21:34:22.708Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}