π 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): stop seeding the bridge's ControllerRegistry with the sql.js dbPath
ruvd413297ddef0
diff --git a/v3/@claude-flow/cli/__tests__/memory-init-bridge-dbpath-3155.test.ts b/v3/@claude-flow/cli/__tests__/memory-init-bridge-dbpath-3155.test.tsnew file mode 100644index 0000000000..a289d3d712--- /dev/null+++ b/v3/@claude-flow/cli/__tests__/memory-init-bridge-dbpath-3155.test.ts@@ -0,0 +1,113 @@+/**+ * Regression for ruvnet/ruflo#3155.+ *+ * `initializeMemoryDatabase()` used to pass its just-resolved sql.js-facing+ * `memory.db` path straight through to `activateControllerRegistry()` ->+ * `bridge.getControllerRegistry(dbPath)`. That seeded the process-wide+ * ControllerRegistry singleton with `memory.db` as AgentDB's own native+ * better-sqlite3 database, instead of the dedicated `agentdb-memory.db`+ * sibling `getAgentDbPath()` exists specifically to provide (#2786).+ *+ * Because this activation only runs on a database's FIRST-EVER init (an+ * already-initialized `.swarm/` skips it via the #1791.6 idempotent no-op+ * branch), a bridge started against a brand-new directory would activate+ * against `memory.db` and work fine for that process's lifetime β then a+ * restarted bridge process, whose `.swarm/memory.db` already exists, would+ * skip this call entirely and have its first real bridge operation activate+ * the registry against `agentdb-memory.db` instead (via the `dbPath ||+ * getAgentDbPath()` fallback in memory-bridge.ts). That empty file never+ * received the earlier writes, so every read after a restart silently came+ * back `found:false` / an empty list, with no error anywhere.+ *+ * The fix: `activateControllerRegistry()` no longer forwards the sql.js+ * `dbPath` to the bridge at all β it calls `bridge.getControllerRegistry()`+ * with no argument, so both the init-time warm-up and every later bridge+ * call (bridgeStoreEntry, bridgeGetEntry, ...) resolve the SAME file via+ * `getAgentDbPath()`, regardless of whether this is a fresh directory or a+ * restart against an already-initialized one.+ */+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';+import { existsSync, mkdtempSync, rmSync } from 'node:fs';+import { tmpdir } from 'node:os';+import { join } from 'node:path';++const getControllerRegistry = vi.fn(async (_dbPath?: string) => null);+const shutdownBridge = vi.fn(async () => {});++vi.mock('../src/memory/memory-bridge.js', () => ({+ getControllerRegistry,+ shutdownBridge,+}));++import { initializeMemoryDatabase } from '../src/memory/memory-initializer.js';++let testDir: string;++beforeEach(() => {+ testDir = mkdtempSync(join(tmpdir(), 'memory-init-bridge-dbpath-3155-'));+ getControllerRegistry.mockClear();+});++afterEach(() => {+ rmSync(testDir, { recursive: true, force: true });+});++describe('initializeMemoryDatabase -> ControllerRegistry activation (#3155)', () => {+ it('activates the bridge registry with NO dbPath on a fresh directory (sql.js path)', async () => {+ const dbPath = join(testDir, 'memory.db');++ const result = await initializeMemoryDatabase({+ backend: 'sqlite',+ dbPath,+ force: true,+ migrate: false,+ });++ expect(result.success).toBe(true);+ expect(existsSync(dbPath)).toBe(true);++ // The regression: this used to be called with `dbPath` (the sql.js+ // file just written above) β the bridge's own dedicated file must be+ // resolved independently, so no dbPath is forwarded here at all.+ expect(getControllerRegistry).toHaveBeenCalledTimes(1);+ expect(getControllerRegistry).toHaveBeenCalledWith();+ const [calledArg] = getControllerRegistry.mock.calls[0]!;+ expect(calledArg).toBeUndefined();+ expect(calledArg).not.toBe(dbPath);+ });++ it('activates the bridge registry with NO dbPath on the schema-file fallback path', async () => {+ // Force the sql.js import to fail so initializeMemoryDatabase takes the+ // "fall back to schema file approach" branch (the second call site).+ vi.doMock('sql.js', () => {+ throw new Error('sql.js unavailable in this simulated environment');+ });+ vi.resetModules();+ getControllerRegistry.mockClear();++ vi.doMock('../src/memory/memory-bridge.js', () => ({+ getControllerRegistry,+ shutdownBridge,+ }));++ const { initializeMemoryDatabase: initFallback } = await import('../src/memory/memory-initializer.js');+ const dbPath = join(testDir, 'fallback', 'memory.db');++ const result = await initFallback({+ backend: 'sqlite',+ dbPath,+ force: true,+ migrate: false,+ });++ expect(result.success).toBe(true);+ expect(existsSync(dbPath)).toBe(true);+ expect(getControllerRegistry).toHaveBeenCalledTimes(1);+ const [calledArg] = getControllerRegistry.mock.calls[0]!;+ expect(calledArg).toBeUndefined();+ expect(calledArg).not.toBe(dbPath);++ vi.doUnmock('sql.js');+ vi.resetModules();+ });+});diff --git a/v3/@claude-flow/cli/src/memory/memory-initializer.ts b/v3/@claude-flow/cli/src/memory/memory-initializer.tsindex fc0e2620df..de99a00b4c 100644--- a/v3/@claude-flow/cli/src/memory/memory-initializer.ts+++ b/v3/@claude-flow/cli/src/memory/memory-initializer.ts@@ -1438,14 +1438,33 @@ export async function checkAndMigrateLegacy(options: {* (ReasoningBank, SkillLibrary, ExplainableRecall, etc.) are instantiated.** Uses the memory-bridge's getControllerRegistry() which lazily creates- * a singleton ControllerRegistry and initializes it with the given dbPath.- * After this call, all enabled controllers are ready for immediate use.+ * a singleton ControllerRegistry. Deliberately called with NO dbPath so the+ * bridge resolves its own dedicated file via `getAgentDbPath()` β the same+ * resolution every other bridge call (bridgeStoreEntry, bridgeGetEntry, ...)+ * uses when it omits `dbPath`. After this call, all enabled controllers are+ * ready for immediate use.*- * Failures are isolated: if @claude-flow/memory or agentdb is not installed,- * this returns an empty result without throwing.+ * #3155: this used to be called with the sql.js-facing `memory.db` path+ * (the one just written by the block above, via `resolveDbPath()`), which+ * seeded the process-wide ControllerRegistry singleton with THAT file as+ * AgentDB's native better-sqlite3 database β instead of the dedicated+ * `agentdb-memory.db` sibling `getAgentDbPath()` exists specifically to+ * provide (#2786, so native better-sqlite3 doesn't hit a possibly-encrypted+ * `memory.db`). Because `initializeMemoryDatabase()` only reaches this call+ * on a database's FIRST-EVER init (the `#1791.6` already-exists branch above+ * returns early without activating anything), a bridge started against a+ * brand-new `.swarm/` directory would activate the registry against+ * `memory.db`, store/retrieve correctly for that process's lifetime, and+ * then a SUBSEQUENT process β where `.swarm/memory.db` already exists so+ * this init path is skipped β would have its first bridge call activate the+ * registry against `agentdb-memory.db` instead (via the `dbPath ||+ * getAgentDbPath()` fallback in memory-bridge.ts's `getRegistry()`), an+ * empty file that never received the earlier writes. Restarting the bridge+ * therefore silently lost read access to everything it had written, with no+ * error anywhere. Passing no dbPath here makes both code paths agree on+ * `agentdb-memory.db` every time, regardless of init history.*/async function activateControllerRegistry(- dbPath: string,verbose?: boolean,): Promise<{ activated: string[]; failed: string[]; initTimeMs: number }> {const startTime = performance.now();@@ -1458,7 +1477,7 @@ async function activateControllerRegistry(return { activated, failed, initTimeMs: performance.now() - startTime };}- const registry = await bridge.getControllerRegistry(dbPath);+ const registry = await bridge.getControllerRegistry();if (!registry) {return { activated, failed, initTimeMs: performance.now() - startTime };}@@ -1915,7 +1934,7 @@ export async function initializeMemoryDatabase(options: {// ADR-053: Activate ControllerRegistry so controllers (ReasoningBank,// SkillLibrary, ExplainableRecall, etc.) are instantiated during init- const controllerResult = await activateControllerRegistry(dbPath, verbose);+ const controllerResult = await activateControllerRegistry(verbose);return {success: true,@@ -1978,7 +1997,7 @@ export async function initializeMemoryDatabase(options: {writeFileRestricted(dbPath, sqliteHeader, { encrypt: true });// ADR-053: Activate ControllerRegistry even on fallback path- const controllerResult = await activateControllerRegistry(dbPath, verbose);+ const controllerResult = await activateControllerRegistry(verbose);return {success: true,