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(memory): stop SmartRetrieval collapsing search results to one

555aaditya2dc15e3cb606
diff --git a/v3/@claude-flow/cli/__tests__/adr-323-memory-provenance.test.ts b/v3/@claude-flow/cli/__tests__/adr-323-memory-provenance.test.ts
index 9af06ec68b..7f993925d9 100644
--- a/v3/@claude-flow/cli/__tests__/adr-323-memory-provenance.test.ts
+++ b/v3/@claude-flow/cli/__tests__/adr-323-memory-provenance.test.ts
@@ -133,6 +133,13 @@ describe.skipIf(!CLI_BUILT)('ADR-323 typed memory provenance', () => {
expect(keys).not.toContain('misc/note');
});
+ it('SmartRetrieval returns every matching entry instead of fusing them into one (#2271)', () => {
+ // The fixture entries were stored seconds apart, so their 12-char search ids collide.
+ const r = searchJson('deploy', workdir, ['--smart']);
+ const keys = r.results.map(x => x.key);
+ expect(keys).toEqual(expect.arrayContaining(['user/goal', 'agent/plan', 'tool/deploy', 'misc/note']));
+ });
+
it('preserves an existing provenance type when an upsert omits the flag', () => {
const updated = run(
['memory', 'store', '-k', 'agent/plan', '-n', 'adr323', '--value', 'updated deploy plan'],
diff --git a/v3/@claude-flow/cli/__tests__/memory-search-scores-3327.test.ts b/v3/@claude-flow/cli/__tests__/memory-search-scores-3327.test.ts
index a28894a49f..43ef1f9ed6 100644
--- a/v3/@claude-flow/cli/__tests__/memory-search-scores-3327.test.ts
+++ b/v3/@claude-flow/cli/__tests__/memory-search-scores-3327.test.ts
@@ -126,6 +126,20 @@ describe('memory_search score contract (#3327 Finding B)', () => {
expect(searchEntries).toHaveBeenCalledTimes(1);
});
+ it('keeps distinct entries whose truncated searchEntries ids collide (#2271)', async () => {
+ // searchEntries() returns ids cut to 12 chars ("entry_" + leading Date.now()
+ // digits), so entries stored within ~2.8h share one; RRF used to fuse them all.
+ const collided = (key: string, score: number, namespace = 'test') =>
+ ({ ...entry(key, score), id: 'entry_177600', namespace });
+ searchEntries.mockResolvedValue({
+ success: true, results: [collided('a', 0.8), collided('b', 0.7), collided('a', 0.6, 'other')],
+ });
+ const result = await search({ query: 'alpha', smart: true, namespace: 'all', limit: 5 });
+ // Baseline fails here: one result. Same key in another namespace is a distinct entry.
+ expect(result.results.map(r => `${r.namespace}/${r.key}`).sort()).toEqual(['other/a', 'test/a', 'test/b']);
+ expect(result.total).toBe(3);
+ });
+
it('supplies rawScore to older SmartRetrieval implementations that preserve candidate fields', async () => {
memoryModuleFactory = () => ({
// The existing return projection is {...candidate, score}. This fake
diff --git a/v3/@claude-flow/cli/src/commands/memory.ts b/v3/@claude-flow/cli/src/commands/memory.ts
index 9b92d8c269..c6e267dc51 100644
--- a/v3/@claude-flow/cli/src/commands/memory.ts
+++ b/v3/@claude-flow/cli/src/commands/memory.ts
@@ -699,7 +699,9 @@ const searchCommand: Command = {
});
return {
results: r.results.map(e => ({
- id: e.id,
+ // #2271: searchEntries() ids are truncated to 12 chars and collide
+ // for entries written within ~2.8h; SmartRetrieval dedupes on id.
+ id: JSON.stringify([e.namespace, e.key]),
key: e.key,
content: e.content,
score: e.score,
diff --git a/v3/@claude-flow/cli/src/mcp-tools/memory-tools.ts b/v3/@claude-flow/cli/src/mcp-tools/memory-tools.ts
index b0bbfbb54d..eb23b6c7dd 100644
--- a/v3/@claude-flow/cli/src/mcp-tools/memory-tools.ts
+++ b/v3/@claude-flow/cli/src/mcp-tools/memory-tools.ts
@@ -707,7 +707,11 @@ export const memoryTools: MCPTool[] = [
});
return {
results: r.results.map(e => ({
- id: e.id,
+ // #2271: searchEntries() truncates ids to 12 chars ("entry_" +
+ // the leading digits of Date.now()), so entries written within
+ // ~2.8h share one id and RRF fused them into a single result.
+ // SmartRetrieval dedupes on id: give it the (namespace, key) tuple.
+ id: JSON.stringify([e.namespace, e.key]),
key: e.key,
content: e.content,
score: e.score,