(config: ReturnType<Config["loadConfigOrDefault"]>)
| 6828 | } |
| 6829 | |
| 6830 | private countActiveAgentTasks(config: ReturnType<Config["loadConfigOrDefault"]>): number { |
| 6831 | let activeCount = 0; |
| 6832 | for (const task of this.listAgentTaskWorkspaces(config)) { |
| 6833 | const status: AgentTaskStatus = task.taskStatus ?? "running"; |
| 6834 | // If this task workspace is blocked in a foreground wait, do not count it towards parallelism. |
| 6835 | // This prevents deadlocks where a task spawns a nested task in the foreground while |
| 6836 | // maxParallelAgentTasks is low (e.g. 1). |
| 6837 | // Note: StreamManager can still report isStreaming() while a tool call is executing, so |
| 6838 | // isStreaming is not a reliable signal for "actively doing work" here. |
| 6839 | if (status === "running" && task.id && this.isForegroundAwaiting(task.id)) { |
| 6840 | continue; |
| 6841 | } |
| 6842 | if (status !== "queued" && this.isActiveAgentTaskEntry(task)) { |
| 6843 | activeCount += 1; |
| 6844 | continue; |
| 6845 | } |
| 6846 | |
| 6847 | // Defensive: task status and runtime stream state can be briefly out of sync during |
| 6848 | // termination/cleanup boundaries. Count streaming tasks as active so we never exceed |
| 6849 | // the configured parallel limit. |
| 6850 | if (task.id && this.aiService.isStreaming(task.id)) { |
| 6851 | activeCount += 1; |
| 6852 | } |
| 6853 | } |
| 6854 | |
| 6855 | return activeCount; |
| 6856 | } |
| 6857 | |
| 6858 | private hasActiveDescendantAgentTasks( |
| 6859 | config: ReturnType<Config["loadConfigOrDefault"]>, |
no test coverage detected