🌊 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(memory): keep same-key entries from other namespaces in memory_search_unified (#4470)
kevin6ed591a45ae5
diff --git a/v3/@claude-flow/cli/__tests__/memory-search-unified-same-key.test.ts b/v3/@claude-flow/cli/__tests__/memory-search-unified-same-key.test.tsnew file mode 100644index 0000000000..25b1aeff45--- /dev/null+++ b/v3/@claude-flow/cli/__tests__/memory-search-unified-same-key.test.ts@@ -0,0 +1,58 @@+// memory_search_unified fans out one search per namespace and merges the+// results. Entries are identified by (namespace, key) (see #2271), so two+// entries that share a key in different namespaces must both survive the+// merge instead of the lower-scored one being dropped as a duplicate.++import { beforeEach, describe, expect, it, vi } from 'vitest';++vi.mock('fs', () => ({+ existsSync: vi.fn(() => false), mkdirSync: vi.fn(), readdirSync: vi.fn(() => []),+ readFileSync: vi.fn(() => '{}'), statSync: vi.fn(), unlinkSync: vi.fn(), writeFileSync: vi.fn(),+}));++const { searchEntries } = vi.hoisted(() => ({ searchEntries: vi.fn() }));+vi.mock('../src/memory/memory-initializer.js', () => ({+ searchEntries,+ storeEntry: vi.fn(), listEntries: vi.fn(), getEntry: vi.fn(), deleteEntry: vi.fn(),+ initializeMemoryDatabase: vi.fn(),+ checkMemoryInitialization: vi.fn(async () => ({ initialized: true })),+}));++import { memoryTools } from '../src/mcp-tools/memory-tools.js';++const tool = memoryTools.find((t) => t.name === 'memory_search_unified')!;++interface UnifiedResult {+ results: Array<{ key: string; namespace: string; score: number }>;+ total: number;+}++describe('memory_search_unified merge', () => {+ beforeEach(() => {+ searchEntries.mockReset();+ searchEntries.mockImplementation(async ({ namespace }: { namespace: string }) => ({+ success: true,+ results: namespace === 'project-a'+ ? [{ key: 'config', content: 'a config', score: 0.9, namespace }]+ : [{ key: 'config', content: 'b config', score: 0.7, namespace }],+ }));+ });++ it('keeps entries that share a key in different namespaces', async () => {+ const r = await tool.handler({+ query: 'config',+ namespaces: ['project-a', 'project-b'],+ }) as UnifiedResult;++ expect(r.results.map((e) => [e.namespace, e.key])).toEqual([+ ['project-a', 'config'],+ ['project-b', 'config'],+ ]);+ expect(r.total).toBe(2);+ });++ it('still returns a key once when it appears once per namespace', async () => {+ const r = await tool.handler({ query: 'config', namespace: 'project-a' }) as UnifiedResult;+ expect(r.results.map((e) => [e.namespace, e.key])).toEqual([['project-a', 'config']]);+ });+});diff --git a/v3/@claude-flow/cli/src/mcp-tools/memory-tools.ts b/v3/@claude-flow/cli/src/mcp-tools/memory-tools.tsindex 8605652ccb..8b2d09ef59 100644--- a/v3/@claude-flow/cli/src/mcp-tools/memory-tools.ts+++ b/v3/@claude-flow/cli/src/mcp-tools/memory-tools.ts@@ -1542,12 +1542,15 @@ export const memoryTools: MCPTool[] = [} catch { /* namespace may not exist */ }}- // Sort by score, deduplicate by key, take top N+ // Sort by score, deduplicate by (namespace, key), take top N. An entry is+ // identified by both (see #2271), so the same key in another namespace is+ // a different entry and must not be dropped as a duplicate.allResults.sort((a, b) => b.score - a.score);const seen = new Set<string>();const deduplicated = allResults.filter(r => {- if (seen.has(r.key)) return false;- seen.add(r.key);+ const id = JSON.stringify([r.namespace, r.key]);+ if (seen.has(id)) return false;+ seen.add(id);return true;}).slice(0, limit);