🌊 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
TypeScript agentic-aiagentic-frameworkagentic-workflowagentsai-agentsai-assistantai-skillsautonomous-agentsclaudecodexdsh-pluginharnessmcp-servermulti-agentmulti-agent-systemsnpmskillsswarmswarm-intelligencetypescript
fix(reasoningbank): count each duplicate removal once (#4415)
ordinary being1baacb6856b9
diff --git a/v3/@claude-flow/hooks/src/__tests__/reasoningbank.test.ts b/v3/@claude-flow/hooks/src/__tests__/reasoningbank.test.tsindex 30faccb35e..56b6631de7 100644--- a/v3/@claude-flow/hooks/src/__tests__/reasoningbank.test.ts+++ b/v3/@claude-flow/hooks/src/__tests__/reasoningbank.test.ts@@ -304,6 +304,40 @@ describe('ReasoningBank', () => {expect(result).toHaveProperty('patternsPromoted');});+ it.each([+ ['high-first', [0.9, 0.6, 0.3]],+ ['low-first', [0.3, 0.6, 0.9]],+ ['mid-first', [0.6, 0.3, 0.9]],+ ])('counts each removed duplicate once in a 3-way cluster (%s)', async (_label, qualities) => {+ const bank = new ReasoningBank({ useMockEmbeddings: true, dimensions: 384 });+ await bank.initialize();++ const embedding = new Float32Array(384);+ embedding[0] = 1;+ await bank.importPatterns({+ shortTerm: qualities.map((quality, i) => ({+ id: `cluster_${i}`,+ strategy: `Cluster ${i}`,+ domain: 'general',+ embedding,+ quality,+ usageCount: 1,+ successCount: 0,+ createdAt: Date.now(),+ updatedAt: Date.now(),+ metadata: {},+ })),+ longTerm: [],+ });++ const result = await bank.consolidate();++ // The high-quality survivor removes both siblings exactly once. The old+ // loop then re-compared the two tombstones and reported a third removal.+ expect(result.duplicatesRemoved).toBe(2);+ expect(bank.getStats().shortTermCount).toBe(1);+ });+it('should free HNSW index capacity when pruning, not just the in-memory map', async () => {// Small maxElements (maxShortTerm + maxLongTerm) so the bug surfaces// without inserting thousands of patterns.diff --git a/v3/@claude-flow/hooks/src/reasoningbank/index.ts b/v3/@claude-flow/hooks/src/reasoningbank/index.tsindex 166a6ae84e..816b9f7b69 100644--- a/v3/@claude-flow/hooks/src/reasoningbank/index.ts+++ b/v3/@claude-flow/hooks/src/reasoningbank/index.ts@@ -597,7 +597,12 @@ export class ReasoningBank extends EventEmitter {// Deduplicate similar patternsconst patterns = Array.from(this.shortTermPatterns.values());for (let i = 0; i < patterns.length; i++) {+ // A prior comparison may have removed this pattern already. Re-entering+ // its inner loop would compare a tombstone, double-count+ // duplicatesRemoved, and issue redundant storage/HNSW deletes (#4410).+ if (!this.shortTermPatterns.has(patterns[i].id)) continue;for (let j = i + 1; j < patterns.length; j++) {+ if (!this.shortTermPatterns.has(patterns[j].id)) continue;const similarity = this.cosineSimilarity(patterns[i].embedding, patterns[j].embedding);if (similarity > this.config.dedupThreshold) {// Keep the one with higher quality@@ -608,6 +613,9 @@ export class ReasoningBank extends EventEmitter {await this.hnswIndex.removePoint(toRemove.id);}duplicatesRemoved++;+ // If `i` lost, every later comparison would be against a removed+ // pattern. Stop this inner loop entirely (#4415 review).+ if (toRemove === patterns[i]) break;}}}