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): preserve namespace and key identity in entry cache

Rudy Celekli106ee2b899fe
diff --git a/v3/@claude-flow/cli/__tests__/memory-cache-tuple-identity.test.ts b/v3/@claude-flow/cli/__tests__/memory-cache-tuple-identity.test.ts
new file mode 100644
index 0000000000..3b0cf8d168
--- /dev/null
+++ b/v3/@claude-flow/cli/__tests__/memory-cache-tuple-identity.test.ts
@@ -0,0 +1,29 @@
+import { afterEach, beforeEach, expect, it, vi } from 'vitest';
+import Database from 'better-sqlite3';
+vi.mock('../src/memory/intelligence.js', () => ({ recordSignalProcessed() {} }));
+import * as bridge from '../src/memory/memory-bridge.js';
+let db: Database.Database;
+beforeEach(() => {
+ db=new Database(':memory:'); const cache=new Map();
+ bridge.__setMemoryBridgeRegistryForTests({getAgentDB:()=>({database:db}),get:(name:string)=>name==='tieredCache'?cache:null});
+});
+afterEach(()=>{bridge._resetRegistryCacheForTest();db.close();});
+const put=(namespace:string,key:string,value:string)=>bridge.bridgeStoreEntry({namespace,key,value,generateEmbeddingFlag:false,upsert:true});
+const get=(namespace:string,key:string)=>bridge.bridgeGetEntry({namespace,key});
+it.each([
+ ['a:b','a_b','key','key'],
+ ['default','default','x:y','x_y'],
+ ['a:b','a','c','b:c'],
+])('keeps cache identities distinct for %s / %s',async(ns1,ns2,key1,key2)=>{
+ expect(await put(ns1,key1,'first')).toMatchObject({success:true});
+ expect(await put(ns2,key2,'second')).toMatchObject({success:true});
+ expect(await get(ns1,key1)).toMatchObject({entry:{content:'first'}});
+ expect(await get(ns2,key2)).toMatchObject({entry:{content:'second'}});
+ expect(await get(ns1,key1)).toMatchObject({entry:{content:'first'}});
+ await put(ns2,key2,'updated');
+ expect(await get(ns1,key1)).toMatchObject({entry:{content:'first'}});
+ expect(await get(ns2,key2)).toMatchObject({entry:{content:'updated'}});
+ await bridge.bridgeDeleteEntry({namespace:ns1,key:key1});
+ expect(await get(ns1,key1)).toMatchObject({found:false});
+ expect(await get(ns2,key2)).toMatchObject({entry:{content:'updated'}});
+});
diff --git a/v3/@claude-flow/cli/src/memory/memory-bridge.ts b/v3/@claude-flow/cli/src/memory/memory-bridge.ts
index 9935b51e35..bf849598af 100644
--- a/v3/@claude-flow/cli/src/memory/memory-bridge.ts
+++ b/v3/@claude-flow/cli/src/memory/memory-bridge.ts
@@ -559,6 +559,12 @@ function computeTermDocFreqs(
// ===== Phase 2: TieredCache helpers =====
+/** Preserve the exact namespace/key tuple; punctuation is valid memory data. */
+function entryCacheKey(namespace: string, key: string): string {
+ return `entry:${JSON.stringify([namespace, key])}`;
+}
+
+
/**
* Try to read from TieredCache before hitting DB.
* Returns cached value or null if cache miss.
@@ -1194,9 +1200,7 @@ export async function bridgeStoreEntry(options: {
// next `bridgeGetEntry` to load the authoritative row (which correctly
// parses tags/metadata from the JSON columns) and repopulate the cache
// from that full shape.
- const safeNs = String(namespace).replace(/:/g, '_');
- const safeKey = String(key).replace(/:/g, '_');
- const cacheKey = `entry:${safeNs}:${safeKey}`;
+ const cacheKey = entryCacheKey(namespace, key);
await cacheInvalidate(registry, cacheKey);
// Phase 4: AttestationLog write audit
@@ -1564,9 +1568,7 @@ export async function bridgeGetEntry(options: {
const { key, namespace = 'default' } = options;
// Phase 2: Check TieredCache first
- const safeNs = String(namespace).replace(/:/g, '_');
- const safeKey = String(key).replace(/:/g, '_');
- const cacheKey = `entry:${safeNs}:${safeKey}`;
+ const cacheKey = entryCacheKey(namespace, key);
dropCacheIfDbChangedElsewhere(registry, ctx);
const cached = await cacheGet(registry, cacheKey);
if (cached && cached.content) {
@@ -1704,9 +1706,7 @@ export async function bridgeDeleteEntry(options: {
} catch { /* non-WAL, busy, or unsupported — non-fatal */ }
// Phase 2: Invalidate cache
- const safeNs = String(namespace).replace(/:/g, '_');
- const safeKey = String(key).replace(/:/g, '_');
- await cacheInvalidate(registry, `entry:${safeNs}:${safeKey}`);
+ await cacheInvalidate(registry, entryCacheKey(namespace, key));
// Phase 4: AttestationLog delete audit
if (changes > 0) {