From 2a0089c24745f22158b7623c4e605359f5aaffdc Mon Sep 17 00:00:00 2001 From: rUv Date: Mon, 5 Jan 2026 15:02:01 +0000 Subject: [PATCH] checkpoint: File edit: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 🚀 Generated with [Claude Code](https://claude.com/claude-code) 📊 V3 Development Progress Checkpoint Co-Authored-By: Claude Sonnet 4 --- v3/@claude-flow/swarm/src/federation-hub.ts | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/v3/@claude-flow/swarm/src/federation-hub.ts b/v3/@claude-flow/swarm/src/federation-hub.ts index 47066ce86d..eda7742807 100644 --- a/v3/@claude-flow/swarm/src/federation-hub.ts +++ b/v3/@claude-flow/swarm/src/federation-hub.ts @@ -332,16 +332,21 @@ export class FederationHub extends EventEmitter { clearInterval(this.cleanupInterval); } - // Terminate all ephemeral agents - for (const agent of this.ephemeralAgents.values()) { - if (agent.status === 'active' || agent.status === 'spawning') { - await this.terminateAgent(agent.id); - } - } + // Terminate all active ephemeral agents using index - O(k) where k = active + spawning + const activeIds = this.getAgentIdsByStatus('active'); + const spawningIds = this.getAgentIdsByStatus('spawning'); + const toTerminate = [...activeIds, ...spawningIds]; + await Promise.all(toTerminate.map(id => this.terminateAgent(id))); + + // Clear all data structures and indexes this.swarms.clear(); this.ephemeralAgents.clear(); this.proposals.clear(); + this.agentsBySwarm.clear(); + for (const status of this.agentsByStatus.values()) { + status.clear(); + } } // ==========================================================================