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): reroute the stale-lock retry AgentDB too; memory 3.0.4

Dragan Spiridonovc536e77fdaad
diff --git a/v3/@claude-flow/cli/__tests__/graph-writer-shared-sqlite-3693.test.ts b/v3/@claude-flow/cli/__tests__/graph-writer-shared-sqlite-3693.test.ts
index 77a082d4b4..c17783bc9f 100644
--- a/v3/@claude-flow/cli/__tests__/graph-writer-shared-sqlite-3693.test.ts
+++ b/v3/@claude-flow/cli/__tests__/graph-writer-shared-sqlite-3693.test.ts
@@ -141,10 +141,10 @@ describe('#3693 graph writer idle close vs live AgentDB handle', () => {
expect(resolveAgentdbBetterSqlite3(agentdbEntry)).toBe(HolderCtor);
});
- // @claude-flow/memory >= 3.0.3 opens AgentDB's handle with ITS better-sqlite3
+ // @claude-flow/memory >= 3.0.4 opens AgentDB's handle with ITS better-sqlite3
// (agentdb-native-driver.js), so that copy is the holder the CLI must share.
- it('owner is @claude-flow/memory when it routes AgentDB through its own driver', async () => {
- if (!native) return;
+ it('owner is @claude-flow/memory when it routes AgentDB through its own driver', async (ctx) => {
+ if (!native) ctx.skip(); // reported as skipped, never a silent pass
const memDist = join(root, 'node_modules', '@claude-flow', 'memory', 'dist');
const memNm = join(root, 'node_modules', '@claude-flow', 'memory', 'node_modules');
mkdirSync(memDist, { recursive: true });
@@ -164,7 +164,7 @@ describe('#3693 graph writer idle close vs live AgentDB handle', () => {
expect(MemoryCtor).not.toBe(HolderCtor);
});
- it('owner falls back to agentdb when @claude-flow/memory has no driver (memory <= 3.0.2)', async () => {
+ it('owner falls back to agentdb when @claude-flow/memory has no driver (memory <= 3.0.3)', async () => {
const oldMemDist = join(root, 'old-memory', 'dist');
mkdirSync(oldMemDist, { recursive: true });
writeFileSync(join(oldMemDist, 'index.js'), '');
diff --git a/v3/@claude-flow/cli/__tests__/shared-sqlite-host-driver.test.ts b/v3/@claude-flow/cli/__tests__/shared-sqlite-host-driver.test.ts
index 16c8e7815e..d90a53b659 100644
--- a/v3/@claude-flow/cli/__tests__/shared-sqlite-host-driver.test.ts
+++ b/v3/@claude-flow/cli/__tests__/shared-sqlite-host-driver.test.ts
@@ -3,9 +3,9 @@
* AgentDB with its own better-sqlite3 (Node 24 Statement-GC abort): the CLI's
* shared loader must hand out the exact constructor AgentDB's handle uses.
*
- * The installed @claude-flow/memory may be the workspace source (>= 3.0.3,
+ * The installed @claude-flow/memory may be the workspace source (>= 3.0.4,
* routes AgentDB through getHostSqliteDriver) or a published copy that does
- * not (<= 3.0.2, AgentDB loads its own); both must keep one copy.
+ * not (<= 3.0.3, AgentDB loads its own); both must keep one copy.
*/
import { describe, expect, it } from 'vitest';
import { existsSync } from 'node:fs';
diff --git a/v3/@claude-flow/cli/package.json b/v3/@claude-flow/cli/package.json
index b28d5ba0e3..78814decdd 100644
--- a/v3/@claude-flow/cli/package.json
+++ b/v3/@claude-flow/cli/package.json
@@ -125,11 +125,11 @@
"ws": "^8.21.0",
"yaml": "^2.8.0",
"zod": "^3.22.0",
- "@claude-flow/memory": "3.0.3"
+ "@claude-flow/memory": "3.0.4"
},
"optionalDependencies": {
"@agntcy/slim-bindings": "2.0.0-alpha.5",
- "@claude-flow/memory": "3.0.3",
+ "@claude-flow/memory": "3.0.4",
"@metaharness/darwin": "~0.10.2",
"@metaharness/flywheel": "~0.1.10",
"@metaharness/radio": "~0.1.0",
diff --git a/v3/@claude-flow/cli/src/memory/shared-sqlite.ts b/v3/@claude-flow/cli/src/memory/shared-sqlite.ts
index 9a56bee649..62c81327c9 100644
--- a/v3/@claude-flow/cli/src/memory/shared-sqlite.ts
+++ b/v3/@claude-flow/cli/src/memory/shared-sqlite.ts
@@ -12,7 +12,7 @@
*
* Resolve the constructor from the same place AgentDB's handle is opened with,
* so both share one SQLite instance (and its connection bookkeeping):
- * - @claude-flow/memory >= 3.0.3 opens AgentDB with its own better-sqlite3
+ * - @claude-flow/memory >= 3.0.4 opens AgentDB with its own better-sqlite3
* (agentdb-native-driver.js, getHostSqliteDriver) to keep agentdb's nested
* 11.x — compiled from source on Node 24, which aborts in Statement GC —
* out of the process. Resolve from memory's location then.
diff --git a/v3/@claude-flow/memory/package.json b/v3/@claude-flow/memory/package.json
index 5bb7513977..24bfd41674 100644
--- a/v3/@claude-flow/memory/package.json
+++ b/v3/@claude-flow/memory/package.json
@@ -1,6 +1,6 @@
{
"name": "@claude-flow/memory",
- "version": "3.0.3",
+ "version": "3.0.4",
"type": "module",
"description": "Memory module - AgentDB unification, HNSW indexing, vector search, hybrid SQLite+AgentDB backend (ADR-009)",
"main": "dist/index.js",
diff --git a/v3/@claude-flow/memory/src/agentdb-native-driver.test.ts b/v3/@claude-flow/memory/src/agentdb-native-driver.test.ts
index 845975d316..4726a87328 100644
--- a/v3/@claude-flow/memory/src/agentdb-native-driver.test.ts
+++ b/v3/@claude-flow/memory/src/agentdb-native-driver.test.ts
@@ -7,12 +7,13 @@
*/
import { afterAll, afterEach, describe, it, expect, vi } from 'vitest';
-import { cpSync, mkdirSync, mkdtempSync, readFileSync, rmSync, symlinkSync, writeFileSync } from 'node:fs';
+import { cpSync, mkdirSync, mkdtempSync, readFileSync, rmSync, symlinkSync, utimesSync, writeFileSync } from 'node:fs';
import { createRequire } from 'node:module';
import { tmpdir } from 'node:os';
import { dirname, join } from 'node:path';
import Database from 'better-sqlite3';
import { getHostSqliteDriver, useHostSqliteDriver } from './agentdb-native-driver.js';
+import { AGENTDB_CONCURRENT_MODIFICATION_CODE } from './agentdb-lock-guard.js';
function fakeAgentDB(config: { forceWasm?: boolean } = {}) {
const calls: string[] = [];
@@ -154,21 +155,40 @@ describe('useHostSqliteDriver with a nested agentdb copy', () => {
});
});
-/** Fake agentdb module whose AgentDB records the handle its initialize() opened. */
-function agentdbModuleRecordingHandle() {
+/**
+ * Fake agentdb module whose AgentDB records the handle its initialize() opened.
+ * With `failFirstInit`, the first instance fails like agentdb alpha.20 does on a
+ * stale `<db>.agentdb.lock`, so withAgentdbLockRecovery retries with a new instance.
+ */
+function agentdbModuleRecordingHandle(failFirstInit = false) {
const opened: unknown[] = [];
+ let instances = 0;
class AgentDB {
config: Record<string, unknown>;
usingWasm = true;
database: unknown = null;
+ readonly instance = ++instances;
constructor(config: Record<string, unknown> = {}) { this.config = config; }
async initializeDatabase(_dbPath: string): Promise<unknown> { return { agentdbOwnLoader: true }; }
async initialize() {
+ if (failFirstInit && this.instance === 1) {
+ throw Object.assign(new Error('concurrent modification'), { code: AGENTDB_CONCURRENT_MODIFICATION_CODE });
+ }
this.database = await this.initializeDatabase((this.config.dbPath as string) || ':memory:');
opened.push(this.database);
}
}
- return { opened, module: { AgentDB, default: AgentDB } };
+ return { opened, instances: () => instances, module: { AgentDB, default: AgentDB } };
+}
+
+/** A db path whose `<db>.agentdb.lock` belongs to a dead writer (provably stale). */
+function dbWithStaleLock(dir: string): string {
+ const dbPath = join(dir, 'agentdb-memory.db');
+ const lock = `${dbPath}.agentdb.lock`;
+ writeFileSync(lock, '2147483000\n');
+ const old = new Date(Date.now() - 3600_000);
+ utimesSync(lock, old, old);
+ return dbPath;
}
describe('AgentDB construction sites apply useHostSqliteDriver', () => {
@@ -207,6 +227,53 @@ describe('AgentDB construction sites apply useHostSqliteDriver', () => {
});
});
+describe('AgentDB construction sites reroute the stale-lock retry instance too', () => {
+ afterEach(() => {
+ vi.doUnmock('agentdb');
+ vi.resetModules();
+ });
+
+ it('ControllerRegistry.initAgentDB retry', async () => {
+ const dir = mkdtempSync(join(tmpdir(), 'cf-agentdb-retry-'));
+ try {
+ const fake = agentdbModuleRecordingHandle(true);
+ vi.resetModules();
+ vi.doMock('agentdb', () => fake.module);
+ const { ControllerRegistry } = await import('./controller-registry.js');
+
+ await (new ControllerRegistry() as any).initAgentDB({ dbPath: dbWithStaleLock(dir) });
+
+ expect(fake.instances()).toBe(2);
+ expect(fake.opened).toHaveLength(1);
+ expect(fake.opened[0]).toBeInstanceOf(Database);
+ (fake.opened[0] as Database.Database).close();
+ } finally {
+ rmSync(dir, { recursive: true, force: true });
+ }
+ });
+
+ it('AgentDBBackend.initialize retry', async () => {
+ const dir = mkdtempSync(join(tmpdir(), 'cf-agentdb-retry-'));
+ const errors = vi.spyOn(console, 'error').mockImplementation(() => {});
+ try {
+ const fake = agentdbModuleRecordingHandle(true);
+ vi.resetModules();
+ vi.doMock('agentdb', () => fake.module);
+ const { AgentDBBackend } = await import('./agentdb-backend.js');
+
+ await new AgentDBBackend({ dbPath: dbWithStaleLock(dir) } as any).initialize();
+
+ expect(fake.instances()).toBe(2);
+ expect(fake.opened).toHaveLength(1);
+ expect(fake.opened[0]).toBeInstanceOf(Database);
+ (fake.opened[0] as Database.Database).close();
+ } finally {
+ errors.mockRestore();
+ rmSync(dir, { recursive: true, force: true });
+ }
+ });
+});
+
/**
* Drift guard: useHostSqliteDriver replaces AgentDB.initializeDatabase(). If
* agentdb renames it or stops routing initialize() through it, the helper would
diff --git a/v3/pnpm-lock.yaml b/v3/pnpm-lock.yaml
index 1e731ddb3d..77e82e45b8 100644
--- a/v3/pnpm-lock.yaml
+++ b/v3/pnpm-lock.yaml
@@ -211,7 +211,7 @@ importers:
specifier: 2.0.0-alpha.5
version: 2.0.0-alpha.5
'@claude-flow/memory':
- specifier: 3.0.3
+ specifier: 3.0.4
version: link:../memory
'@metaharness/darwin':
specifier: ~0.10.2