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): rescue each store's embedder, not just the first (#4421)

ordinary beingaca151dfe12e
diff --git a/v3/@claude-flow/cli/__tests__/memory-embedder-rescue-multistore-4410.test.ts b/v3/@claude-flow/cli/__tests__/memory-embedder-rescue-multistore-4410.test.ts
new file mode 100644
index 0000000000..37091da0bc
--- /dev/null
+++ b/v3/@claude-flow/cli/__tests__/memory-embedder-rescue-multistore-4410.test.ts
@@ -0,0 +1,41 @@
+/**
+ * #4410 memory scan: the AgentDB embedder rescue was guarded by one
+ * process-wide boolean. Each dbPath registry owns a different embedder, so
+ * after the first store succeeded, every later store kept AgentDB's mock
+ * embedder. The rescue must be idempotent per embedder, not per process.
+ */
+import { describe, expect, it, vi } from 'vitest';
+
+vi.mock('../src/memory/memory-initializer.js', () => ({
+ generateLocalEmbedding: vi.fn(async () => ({
+ embedding: [0.5, 0.25],
+ dimensions: 2,
+ model: 'test',
+ backend: 'onnx',
+ })),
+}));
+
+import { rescueAgentdbEmbedder } from '../src/memory/memory-bridge.js';
+
+function mockEmbedder() {
+ return {
+ pipeline: null,
+ embed: async () => new Float32Array([0, 0]),
+ embedBatch: async () => [],
+ __ruvectorRescued: false as boolean | undefined,
+ };
+}
+
+describe('AgentDB embedder rescue is per store (#4410)', () => {
+ it('rescues both distinct embedders, not just the first in the process', async () => {
+ const first = mockEmbedder();
+ const second = mockEmbedder();
+
+ await rescueAgentdbEmbedder({ embedder: first });
+ await rescueAgentdbEmbedder({ embedder: second });
+
+ expect(first.__ruvectorRescued).toBe(true);
+ expect(second.__ruvectorRescued).toBe(true);
+ expect(Array.from(await second.embed('probe'))).toEqual([0.5, 0.25]);
+ });
+});
diff --git a/v3/@claude-flow/cli/src/memory/memory-bridge.ts b/v3/@claude-flow/cli/src/memory/memory-bridge.ts
index f372a64483..79bae6fdd5 100644
--- a/v3/@claude-flow/cli/src/memory/memory-bridge.ts
+++ b/v3/@claude-flow/cli/src/memory/memory-bridge.ts
@@ -902,12 +902,10 @@ function getDb(registry: any): any | null {
return { db, agentdb };
}
-// One-shot guard so we only patch once per process — the embedder is shared
-// by ReflexionMemory/SkillLibrary/CausalRecall and they all see the same
-// object reference.
-let _embedderPatched = false;
-async function rescueAgentdbEmbedder(agentdb: { embedder?: { pipeline?: unknown; embed?: (t: string) => Promise<Float32Array>; embedBatch?: (ts: string[]) => Promise<Float32Array[]>; __ruvectorRescued?: boolean } }): Promise<void> {
- if (_embedderPatched) return;
+// The rescue is idempotent per embedder via __ruvectorRescued. A process-wide
+// flag would skip later dbPath registries and leave their embedder on mock (#4410).
+/** @internal Exported for the multi-store rescue regression test. */
+export async function rescueAgentdbEmbedder(agentdb: { embedder?: { pipeline?: unknown; embed?: (t: string) => Promise<Float32Array>; embedBatch?: (ts: string[]) => Promise<Float32Array[]>; __ruvectorRescued?: boolean } }): Promise<void> {
const emb = agentdb?.embedder;
if (!emb || emb.__ruvectorRescued) return;
@@ -965,7 +963,6 @@ async function rescueAgentdbEmbedder(agentdb: { embedder?: { pipeline?: unknown;
emb.embedBatch = async (texts: string[]): Promise<Float32Array[]> =>
Promise.all(texts.map(t => newEmbed(t)));
emb.__ruvectorRescued = true;
- _embedderPatched = true;
}
/** AgentDB uses a null pipeline while its transformer failed and it serves mock vectors. */