🌊 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): require durable file and serialize legacy immutable slots
Stuart Kerr9d4eae2c14e2
diff --git a/docs/memory/conditional-append.md b/docs/memory/conditional-append.mdindex ef99915099..4fcf81718f 100644--- a/docs/memory/conditional-append.md+++ b/docs/memory/conditional-append.md@@ -1,4 +1,4 @@-Updated: 2026-10-05 EDT | Version 0.1.0+Updated: 2026-10-05 EDT | Version 0.1.1Created: 2026-10-05 EDT# Native conditional append for structured continuity records@@ -7,8 +7,11 @@ This source candidate adds explicit controls to `memory store`. Existing calls rembedding, upsert and backend fallback behavior. It is not an installed or published capability.- `--no-embedding` avoids embedding structured records.-- `--require-native` refuses WASM and whole-image sql.js fallback before writing a record.-- `--append-only` never replaces active records or resurrects tombstones.+- `--require-native` requires a native disk handle for the exact canonical file, refusing+ in-memory, wrong-file, WASM and whole-image sql.js fallback record writes.+- `--append-only` requires native storage and never replaces active records or resurrects+ tombstones. Its logical-slot check and insert share an immediate transaction, including on+ legacy tables without a UNIQUE constraint.- `--append-conditions '<JSON array>'` requires both native and append-only controls. One to eightpredicates run inside the same native immediate transaction as the record insertion.diff --git a/v3/@claude-flow/cli/__tests__/memory-structured-append.test.ts b/v3/@claude-flow/cli/__tests__/memory-structured-append.test.tsindex 2ad710a4c1..819ca2fb91 100644--- a/v3/@claude-flow/cli/__tests__/memory-structured-append.test.ts+++ b/v3/@claude-flow/cli/__tests__/memory-structured-append.test.ts@@ -131,3 +131,34 @@ describe('withdrawn authority while an older writer is inflight', () => {expect(prepare('SELECT 1 FROM memory_entries WHERE key=?').get('inflight-stale-publication')).toBeUndefined();});});++describe('durable backend and legacy logical-key invariants', () => {+ it('refuses a native in-memory or wrong-file handle before writing a record', async () => {+ const ephemeral = new Database(':memory:');+ __setMemoryBridgeRegistryForTests({ getAgentDB: () => ({ database: ephemeral, embedder: { embed } }), get: () => null });+ expect((await append('ephemeral'))?.success).toBe(false);+ expect(ephemeral.prepare("SELECT 1 FROM memory_entries WHERE key='ephemeral'").get()).toBeUndefined();+ ephemeral.close();+ const otherPath = join(root, 'different-file.db'); const other = new Database(otherPath);+ __setMemoryBridgeRegistryForTests({ getAgentDB: () => ({ database: other, embedder: { embed } }), get: () => null });+ expect((await append('wrong-file'))?.success).toBe(false);+ expect(other.prepare("SELECT 1 FROM memory_entries WHERE key='wrong-file'").get()).toBeUndefined();+ other.close();+ });+ it('rejects duplicate and tombstoned logical slots on a legacy table without a UNIQUE constraint', async () => {+ const legacyPath = join(root, 'legacy.db'); const legacy = new Database(legacyPath);+ // CTAS deliberately drops every UNIQUE/primary-key constraint while preserving the shape.+ legacy.exec(`ATTACH DATABASE '${dbPath.replaceAll("'", "''")}' AS original;+ CREATE TABLE memory_entries AS SELECT * FROM original.memory_entries;+ CREATE TABLE vector_indexes AS SELECT * FROM original.vector_indexes; DETACH DATABASE original;`);+ __setMemoryBridgeRegistryForTests({ getAgentDB: () => ({ database: legacy, embedder: { embed } }), get: () => null });+ const write = (key: string) => bridgeStoreEntry({ key, value: 'changed', namespace: 'fixture', dbPath: legacyPath,+ generateEmbeddingFlag: false, requireNative: true, appendOnly: true });+ expect((await write('new'))?.success).toBe(false);+ expect((await write('historical-vector'))?.success).toBe(false);+ expect(legacy.prepare("SELECT count(*) AS count FROM memory_entries WHERE key='new'").get()).toEqual({ count: 1 });+ expect((await write('new-legacy-slot'))?.success).toBe(true);+ expect((await write('new-legacy-slot'))?.success).toBe(false);+ legacy.close();+ });+});diff --git a/v3/@claude-flow/cli/src/memory/memory-bridge.ts b/v3/@claude-flow/cli/src/memory/memory-bridge.tsindex b9718daf34..a5df70fe0b 100644--- a/v3/@claude-flow/cli/src/memory/memory-bridge.ts+++ b/v3/@claude-flow/cli/src/memory/memory-bridge.ts@@ -1079,10 +1079,15 @@ export async function bridgeStoreEntry(options: {const ctx = getDb(registry);if (!ctx) return null;+ if (options.appendOnly && !options.requireNative) {+ return { success: false, id: '', error: 'Immutable append requires a native writer' };+ }if (options.appendConditions && (!options.requireNative || !options.appendOnly)) {return { success: false, id: "", error: "Conditional append requires native append-only storage" };}- if (options.requireNative && (ctx.agentdb?.isWasm === true || typeof ctx.db.inTransaction !== 'boolean' || typeof ctx.db.transaction !== "function")) {+ if (options.requireNative && (ctx.agentdb?.isWasm === true || typeof ctx.db.inTransaction !== 'boolean'+ || typeof ctx.db.transaction !== 'function' || ctx.db.memory !== false || typeof ctx.db.name !== 'string'+ || !ctx.db.name || canonicalDbPath(ctx.db.name) !== canonicalDbPath(options.dbPath))) {return { success: false, id: '', error: 'Native memory writer required; refusing non-native bridge driver' };}@@ -1209,9 +1214,14 @@ export async function bridgeStoreEntry(options: {let runResult;try {- runResult = options.appendConditions+ runResult = options.appendOnly? ctx.db.transaction(() => {- assertAppendConditions(ctx.db, validateAppendConditions(options.appendConditions));+ // Legacy native tables may predate UNIQUE(namespace,key). Serialize the exact+ // logical-slot check with INSERT, including tombstones, instead of trusting DDL.+ if (ctx.db.prepare('SELECT key FROM memory_entries WHERE namespace = ? AND key = ?').all(namespace, key).length) {+ throw new AppendConditionFailed('immutable append rejected: logical key already exists');+ }+ if (options.appendConditions) assertAppendConditions(ctx.db, validateAppendConditions(options.appendConditions));return insert();}).immediate(): insert();diff --git a/v3/@claude-flow/cli/src/memory/memory-initializer.ts b/v3/@claude-flow/cli/src/memory/memory-initializer.tsindex 00e6547599..5fb0edae6c 100644--- a/v3/@claude-flow/cli/src/memory/memory-initializer.ts+++ b/v3/@claude-flow/cli/src/memory/memory-initializer.ts@@ -2907,6 +2907,10 @@ export async function storeEntry(options: {* be produced — the row is stored without a vector. */embeddingError?: string;}> {+ if (options.appendOnly && !options.requireNative) {+ return { success: false, id: '', error: 'Immutable append requires a native writer' };+ }+// ADR-323: validate before touching either backend so an invalid value// gets one clear error instead of a raw SQLite CHECK-constraint failure// from whichever path (bridge vs sql.js) happens to run.