Skip to content

armgit / ruflo

Public Imported from GitHub
0

🌊 The original agent harness. Deploy intelligent multi-player swarms, coordinate autonomous workflows, and build conversational AI systems. Features adaptive memory, self-learning intelligence, federation, vector RAG integration, and native Claude Code / Codex / Hermes and many more Integrated

fix(swarm): release a recovered agent from its domain pool (#4486)

ordinary being84638632fe85
diff --git a/v3/@claude-flow/swarm/__tests__/recover-agent-domain-release-4458.test.ts b/v3/@claude-flow/swarm/__tests__/recover-agent-domain-release-4458.test.ts
new file mode 100644
index 0000000000..29f2c47f15
--- /dev/null
+++ b/v3/@claude-flow/swarm/__tests__/recover-agent-domain-release-4458.test.ts
@@ -0,0 +1,76 @@
+/**
+ * #4458 swarm scan: UnifiedSwarmCoordinator.recoverAgent() reset the shared
+ * AgentState to idle but never released the agent's domain-pool reservation.
+ * AgentPool.busy is separate from AgentState.status, so the slot stayed busy
+ * forever and queued domain tasks could not drain after heartbeat recovery.
+ */
+
+import { describe, expect, it } from 'vitest';
+import {
+ UnifiedSwarmCoordinator,
+ createUnifiedSwarmCoordinator,
+} from '../src/unified-coordinator.ts';
+
+function createCoordinator(): UnifiedSwarmCoordinator {
+ return createUnifiedSwarmCoordinator({
+ maxAgents: 20,
+ maxTasks: 100,
+ heartbeatIntervalMs: 1000,
+ healthCheckIntervalMs: 2000,
+ taskTimeoutMs: 10000,
+ topology: { type: 'hierarchical', maxAgents: 20 },
+ consensus: {
+ algorithm: 'raft',
+ threshold: 0.66,
+ timeoutMs: 5000,
+ maxRounds: 5,
+ requireQuorum: true,
+ },
+ });
+}
+
+function taskData(name: string) {
+ return {
+ type: 'coding' as const,
+ name,
+ description: name,
+ priority: 'normal' as const,
+ dependencies: [],
+ input: {},
+ timeoutMs: 5000,
+ retries: 0,
+ maxRetries: 3,
+ metadata: {},
+ };
+}
+
+describe('UnifiedSwarmCoordinator recovered-agent domain release (#4458)', () => {
+ it('returns the recovered agent to its domain pool and drains a queued task', async () => {
+ const coordinator = createCoordinator();
+ await coordinator.initialize();
+
+ try {
+ const activeTaskId = await coordinator.submitTask(taskData('active'));
+ const { agentId } = await coordinator.spawnAgent({ type: 'coder', domain: 'core' });
+ expect(await coordinator.assignTaskToDomain(activeTaskId, 'core')).toBe(agentId);
+
+ // The only pool agent is busy, so this is queued in the domain queue.
+ const queuedTaskId = await coordinator.submitTask(taskData('queued'));
+ expect(await coordinator.assignTaskToDomain(queuedTaskId, 'core')).toBeUndefined();
+ expect(coordinator.getTask(queuedTaskId)?.status).toBe('queued');
+ expect(coordinator.getDomainPool('core')!.getState().busyAgents).toContain(agentId);
+
+ await (coordinator as unknown as {
+ recoverAgent(agentId: string): Promise<void>;
+ }).recoverAgent(agentId);
+
+ // Releasing the reservation lets the queued domain task take the slot.
+ expect(coordinator.getTask(queuedTaskId)?.status).toBe('assigned');
+ expect(coordinator.getTask(queuedTaskId)?.assignedTo?.id).toBe(agentId);
+ expect(coordinator.getAgent(agentId)?.currentTask?.id).toBe(queuedTaskId);
+ expect(coordinator.getDomainPool('core')!.getState().busyAgents).toContain(agentId);
+ } finally {
+ await coordinator.shutdown();
+ }
+ });
+});
diff --git a/v3/@claude-flow/swarm/src/unified-coordinator.ts b/v3/@claude-flow/swarm/src/unified-coordinator.ts
index fba841afa2..a3d8ab3fce 100644
--- a/v3/@claude-flow/swarm/src/unified-coordinator.ts
+++ b/v3/@claude-flow/swarm/src/unified-coordinator.ts
@@ -1087,6 +1087,11 @@ export class UnifiedSwarmCoordinator extends EventEmitter implements IUnifiedSwa
agent.currentTask = undefined;
agent.health = 1.0;
agent.lastHeartbeat = new Date();
+
+ // Domain-pool ownership is separate from AgentState.status. Without this
+ // release the recovered agent stays in AgentPool.busy forever and queued
+ // domain tasks never drain, even though the shared state says idle.
+ await this.releaseDomainAgent(agentId);
}
private performHealthChecks(): void {