🌊 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): disclose the sibling AgentDB store on partial hits too (#3566)
ruv91ea1b524e1b
diff --git a/v3/@claude-flow/cli/__tests__/memory-sibling-disclosure-partial-3566.test.ts b/v3/@claude-flow/cli/__tests__/memory-sibling-disclosure-partial-3566.test.tsnew file mode 100644index 0000000000..0b9bf18200--- /dev/null+++ b/v3/@claude-flow/cli/__tests__/memory-sibling-disclosure-partial-3566.test.ts@@ -0,0 +1,120 @@+/**+ * #3566 — `memory search` and `memory retrieve` disclosed the sibling AgentDB+ * store only when they found nothing. A partial hit ("Found 1 results") read as+ * complete while the rows the MCP path wrote sat unread next door.+ *+ * Also covers the import counter: `memory import` reported "Vectors: 0" while+ * every imported value was re-embedded.+ */+import { afterAll, beforeEach, describe, expect, it, vi } from 'vitest';+import { mkdtempSync, rmSync, writeFileSync } from 'node:fs';+import { tmpdir } from 'node:os';+import { join } from 'node:path';++const mocks = vi.hoisted(() => ({+ search: vi.fn(), list: vi.fn(), get: vi.fn(), store: vi.fn(), sibling: vi.fn(),+ warning: vi.fn(), json: vi.fn(), error: vi.fn(),+}));+vi.mock('../src/memory/memory-initializer.js', async importOriginal => ({+ ...await importOriginal<typeof import('../src/memory/memory-initializer.js')>(),+ resolveDbPath: (p?: string) => p || '/project/.swarm/memory.db',+ searchEntries: mocks.search,+ listEntries: mocks.list,+ getEntry: mocks.get,+ storeEntry: mocks.store,+ checkMemoryInitialization: async () => ({ initialized: true }),+ initializeMemoryDatabase: async () => ({ success: true }),+}));+vi.mock('../src/memory/sibling-store.js', () => ({ countSiblingStoreRows: mocks.sibling }));+vi.mock('../src/output.js', () => ({ output: {+ printJson: mocks.json, printWarning: mocks.warning, printError: mocks.error,+ writeln: vi.fn(), printTable: vi.fn(), printInfo: vi.fn(), printSuccess: vi.fn(), printBox: vi.fn(), printList: vi.fn(),+ bold: (s: string) => s, dim: (s: string) => s, warning: (s: string) => s,+} }));+vi.mock('../src/prompt.js', () => ({ select: vi.fn(), input: vi.fn(), confirm: vi.fn() }));++const { memoryCommand } = await import('../src/commands/memory.js');+const { memoryTools } = await import('../src/mcp-tools/memory-tools.js');+const search = memoryCommand.subcommands!.find(c => c.name === 'search')!;+const retrieve = memoryCommand.subcommands!.find(c => c.name === 'retrieve')!;+const importTool = memoryTools.find(t => t.name === 'memory_import')!;++const SIBLING = { path: '/project/.swarm/agentdb-memory.db', rows: 2 };+const hit = { id: 'e1', key: 'edge-gateway', content: 'edge gateway tokens', score: 0.81, namespace: 'default' };+const run = (cmd: typeof search, flags: Record<string, unknown>) =>+ cmd.action!({ cwd: '/project', args: [], flags: { _: [], ...flags }, interactive: false } as never);+const siblingWarnings = () => mocks.warning.mock.calls.map(c => String(c[0])).filter(m => m.includes(SIBLING.path));++const dir = mkdtempSync(join(tmpdir(), 'mem-3566-'));+afterAll(() => rmSync(dir, { recursive: true, force: true }));++beforeEach(() => {+ vi.clearAllMocks();+ mocks.sibling.mockResolvedValue(SIBLING);+ mocks.search.mockResolvedValue({ success: true, results: [hit], searchTime: 1 });+ mocks.list.mockResolvedValue({ success: true, entries: [], total: 0 });+ mocks.get.mockResolvedValue({ success: true, found: true, entry: { ...hit, accessCount: 0, createdAt: '', updatedAt: '', hasEmbedding: true, tags: [] } });+});++describe('#3566 search and retrieve disclose the sibling store on partial hits', () => {+ it('search with one hit discloses the 2 unread sibling entries as a partial result', async () => {+ const result = await run(search, { query: 'edge gateway tokens' }) as { success: boolean; data: unknown[] };+ expect(result.success).toBe(true);+ expect(result.data).toHaveLength(1);+ const w = siblingWarnings();+ expect(w).toHaveLength(1);+ expect(w[0]).toMatch(/Partial result: 1 match/);+ expect(w[0]).toContain('2 entries');+ });++ it('search --format json keeps stdout JSON-only and still warns on stderr', async () => {+ await run(search, { query: 'edge gateway tokens', format: 'json' });+ expect(mocks.json).toHaveBeenCalledTimes(1);+ expect(siblingWarnings()).toHaveLength(1);+ });++ it('keyword search with a hit discloses the sibling too', async () => {+ mocks.list.mockResolvedValue({ success: true, total: 1, entries: [{ key: 'edge-gateway', namespace: 'default', content: 'edge gateway tokens' }] });+ await run(search, { query: 'edge', type: 'keyword' });+ expect(siblingWarnings()).toHaveLength(1);+ });++ it('retrieve of a found key discloses the sibling store', async () => {+ const result = await run(retrieve, { key: 'edge-gateway' }) as { success: boolean };+ expect(result.success).toBe(true);+ expect(siblingWarnings()).toHaveLength(1);+ });++ it('the empty branch is unchanged: no results still discloses the sibling', async () => {+ mocks.search.mockResolvedValue({ success: true, results: [], searchTime: 1 });+ await run(search, { query: 'purple aardvark telemetry protocol' });+ const w = siblingWarnings();+ expect(w).toHaveLength(1);+ expect(w[0]).toMatch(/^This read covered one store\./);+ });++ it('no sibling rows means no disclosure on a hit', async () => {+ mocks.sibling.mockResolvedValue(null);+ await run(search, { query: 'edge gateway tokens' });+ await run(retrieve, { key: 'edge-gateway' });+ expect(mocks.warning.mock.calls.some(c => /entries are in/.test(String(c[0])))).toBe(false);+ });+});++describe('memory import reports the vectors it actually wrote', () => {+ it('counts re-embedded entries instead of a constant 0', async () => {+ const inputPath = join(dir, 'export.json');+ writeFileSync(inputPath, JSON.stringify({ entries: [+ { key: 'a', namespace: 'p', value: 'one' },+ { key: 'b', namespace: 'p', value: 'two' },+ { key: 'c', namespace: 'p', value: 'three' },+ ] }));+ mocks.store+ .mockResolvedValueOnce({ success: true, id: '1', embedding: { dimensions: 384, model: 'm' } })+ .mockResolvedValueOnce({ success: true, id: '2', embedding: { dimensions: 384, model: 'm' } })+ .mockResolvedValueOnce({ success: true, id: '3' });+ const result = await importTool.handler({ inputPath }) as { imported: { entries: number; vectors: number } };+ expect(result.imported.entries).toBe(3);+ expect(result.imported.vectors).toBe(2);+ });+});diff --git a/v3/@claude-flow/cli/src/commands/memory.ts b/v3/@claude-flow/cli/src/commands/memory.tsindex 2590045192..4eb2cfeaef 100644--- a/v3/@claude-flow/cli/src/commands/memory.ts+++ b/v3/@claude-flow/cli/src/commands/memory.ts@@ -24,11 +24,16 @@ import { siblingAgentDbPath } from '../memory/memory-bridge.js';* `found:false`. A confident negative is worse than an error, because nothing* prompts anyone to look further.*/-async function warnIfSiblingHasRows(pathFlag: unknown): Promise<void> {+async function warnIfSiblingHasRows(pathFlag: unknown, hits?: number): Promise<void> {const unread = await countSiblingStoreRows(resolveDbPath(pathFlag as string | undefined));if (unread && unread.rows > 0) {+ // #3566: disclose on hits too. A partial positive ("Found 1 results") invites+ // no second look, so it is the more dangerous case, not the safer one.+ const lead = hits === undefined+ ? 'This read covered one store.'+ : `Partial result: ${hits} ${hits === 1 ? 'match' : 'matches'} came from the store read here.`;output.printWarning(- `This read covered one store. ${unread.rows} entries are in ${unread.path} and were not searched. ` ++ `${lead} ${unread.rows} entries are in ${unread.path} and were not searched. ` +`That store is written by the MCP/AgentDB path; read it with --path ${unread.path}.`,);}@@ -354,6 +359,9 @@ const retrieveCommand: Command = {}const entry = result.entry;+ // #3566: the same key may also live in the sibling store. Goes to stderr,+ // so --value-only / --format json stdout stays parseable.+ await warnIfSiblingHasRows(ctx.flags.path, 1);// #2073: --value-only emits just the raw value (no decoration) for// piping into JSON.parse / jq / other downstream parsers without@@ -611,6 +619,7 @@ const searchCommand: Command = {// Pure-keyword mode returns directly; skip the semantic path entirely.if (ctx.flags.format === 'json') {output.printJson({ query, searchType, results: keywordResults, searchTime: '0ms' });+ await warnIfSiblingHasRows(ctx.flags.path, keywordResults.length);return { success: true, data: keywordResults };}output.writeln();@@ -618,6 +627,7 @@ const searchCommand: Command = {for (const r of keywordResults) {output.writeln(` ${r.key} (${r.namespace}, score=${r.score.toFixed(2)}) — ${r.preview.slice(0, 80)}${r.preview.length > 80 ? '…' : ''}`);}+ await warnIfSiblingHasRows(ctx.flags.path, keywordResults.length);return { success: true, data: keywordResults };}// Hybrid mode: keyword hits will be MERGED after semantic runs below.@@ -738,6 +748,7 @@ const searchCommand: Command = {if (ctx.flags.format === 'json') {output.printJson({ query, searchType, results, searchTime: `${searchTimeMs}ms`, ...(smartStats ? { stats: smartStats } : {}) });+ await warnIfSiblingHasRows(ctx.flags.path, results.length);return { success: true, data: results };}@@ -768,6 +779,7 @@ const searchCommand: Command = {output.writeln();output.printInfo(`Found ${results.length} results`);+ await warnIfSiblingHasRows(ctx.flags.path, results.length);return { success: true, data: results };} catch (error) {diff --git a/v3/@claude-flow/cli/src/mcp-tools/memory-tools.ts b/v3/@claude-flow/cli/src/mcp-tools/memory-tools.tsindex 5e4e34bffd..5700d7e20f 100644--- a/v3/@claude-flow/cli/src/mcp-tools/memory-tools.ts+++ b/v3/@claude-flow/cli/src/mcp-tools/memory-tools.ts@@ -1603,6 +1603,9 @@ export const memoryTools: MCPTool[] = [await ensureInitialized(dbPath);const { storeEntry } = await getMemoryFunctions();const t0 = Date.now();+ // Values are re-embedded on import; count the vectors actually written+ // rather than reporting a constant 0 next to entries that show a vector.+ let vectors = 0;const inputPath = String(input.inputPath ?? '');if (!inputPath || !existsSync(inputPath)) return { error: `File not found: ${inputPath || '(empty)'}` };let doc: { entries?: Array<{ key: string; namespace?: string; value?: unknown }> };@@ -1617,13 +1620,13 @@ export const memoryTools: MCPTool[] = [const value = typeof e.value === 'string' ? e.value : JSON.stringify(e.value ?? null);try {const result = await storeEntry({ key: e.key, value, namespace: nsOverride ?? e.namespace ?? 'default', upsert: input.merge !== false, dbPath });- if (result.success) imported++;+ if (result.success) { imported++; if (result.embedding) vectors++; }else skipped++;} catch { skipped++; }}return {inputPath,- imported: { entries: imported, vectors: 0, patterns: 0 },+ imported: { entries: imported, vectors, patterns: 0 },skipped,duration: Date.now() - t0,};