{"record":{"id":"d2814cd3d505ffd9","repo":"ruvnet/ruflo","slug":"no-available-agents","errorCode":null,"errorMessage":"No available agents","messagePattern":"No available agents","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"v3/@claude-flow/plugins/src/integrations/agentic-flow.ts","lineNumber":316,"sourceCode":"\n  /**\n   * Orchestrate a task.\n   */\n  async orchestrateTask(options: TaskOrchestrationOptions): Promise<OrchestrationResult> {\n    if (!this.swarmInitialized) {\n      throw new Error('Swarm not initialized');\n    }\n\n    const taskId = `task-${this.nextTaskId++}`;\n\n    // Find or assign agent\n    let agentId = options.agentId;\n    if (!agentId) {\n      const availableAgent = Array.from(this.agents.values()).find(\n        a => a.status === 'active' || a.status === 'idle'\n      );\n      if (!availableAgent) {\n        throw new Error('No available agents');\n      }\n      agentId = availableAgent.id;\n    }\n\n    const result: OrchestrationResult = {\n      taskId,\n      status: 'running',\n      agentId,\n      startedAt: new Date(),\n    };\n\n    this.tasks.set(taskId, result);\n\n    this.emit(AGENTIC_FLOW_EVENTS.TASK_STARTED, {\n      taskId,\n      agentId,\n      taskType: options.taskType,\n      timestamp: new Date(),","sourceCodeStart":298,"sourceCodeEnd":334,"githubUrl":"https://github.com/ruvnet/ruflo/blob/fa13ee4ad60ac2090b1480656eb233521790d640/v3/@claude-flow/plugins/src/integrations/agentic-flow.ts#L298-L334","documentation":"When orchestrateTask() is called without options.agentId, it scans the agents map for the first entry with status 'active' or 'idle' and throws 'No available agents' when none qualifies. Since spawnAgent() creates agents as 'active' and terminateAgent() marks them 'terminated' (without removing them), this error means: no agents spawned yet, or every spawned agent has been terminated.","triggerScenarios":"Orchestrating without agentId before spawning any agents; terminate-everything then submitting a task; agents all left in non-eligible statuses from earlier runs on the same instance.","commonSituations":"Boot scripts that submit seed tasks before spawning the worker pool; cleanup-all followed by continued task submission; tests that skip the spawn step.","solutions":["Spawn at least one agent before orchestrating, or pass options.agentId pointing at an existing active/idle agent","Re-spawn replacement agents after terminating a pool before submitting more tasks","Guard submission: check your own record of eligible agents before calling orchestrateTask without agentId"],"exampleFix":"// before\nconst result = await flow.orchestrateTask({ type: 'research' }); // Error: No available agents\n\n// after\nawait flow.initializeSwarm({ type: 'mesh' });\nawait flow.spawnAgent({ type: 'researcher' });\nconst result = await flow.orchestrateTask({ type: 'research' });","handlingStrategy":"validation","validationCode":"const live = new Map<string, SpawnedAgent>();\nasync function ensureWorker(): Promise<string> {\n  const eligible = [...live.values()].filter(a => a.status === 'active' || a.status === 'idle');\n  if (eligible.length === 0) {\n    const agent = await flow.spawnAgent({ type: 'coder' });\n    live.set(agent.id, agent);\n    return agent.id;\n  }\n  return eligible[0].id;\n}\nconst result = await flow.orchestrateTask({ ...opts, agentId: await ensureWorker() });","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Spawn the worker pool before submitting tasks","Pass options.agentId when you track eligibility yourself","Re-spawn replacements after terminating agents — terminated entries are never auto-selected"],"tags":["swarm","tasks","agents","scheduling"],"backgroundTag":"resource-exhausted","analyzedSha":"fa13ee4ad60ac2090b1480656eb233521790d640","analyzedAt":"2026-08-18T21:34:22.708Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}