π 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): #2312 β break embedder-rescue recursion that OOM'd CI at 4GB (#2348)
rUv7c6362633edb
diff --git a/.github/workflows/v3-ci.yml b/.github/workflows/v3-ci.ymlindex 89c113cd5d..052669086c 100644--- a/.github/workflows/v3-ci.yml+++ b/.github/workflows/v3-ci.yml@@ -2322,13 +2322,14 @@ jobs:pnpm install --frozen-lockfilepnpm -r build- name: Run trajectory graph edges smoke- # #2312 β TEST 2 (post-task β reinforced-by edge) OOMs at 6 GB+ inside- # the SONA endTrajectory + distillLearning chain (EWCConsolidator init- # is the likely allocator). The graph-edge contract being asserted is- # orthogonal to that path. Gate the step non-blocking until the real- # allocation profile is fixed; TEST 1 (trajectory-step β trajectory-- # caused edge) still runs and gates the same contract.- continue-on-error: true+ # #2312 root cause (fixed): memory-bridge's rescueAgentdbEmbedder+ # patched agentdb.embedder.embed to delegate to generateEmbedding β+ # which is bridge-first, so the patched embed re-entered itself via+ # bridgeGenerateEmbedding in an unbounded async cycle (heap OOM at+ # the V8 limit, SIGABRT 134; SONA/EWC were innocent). The rescue now+ # delegates to generateLocalEmbedding (a bridge-free leaf), so this+ # smoke gates again at default heap β verified green in a node:22+ # Linux container at 512 MB with a cold model cache.run: node scripts/smoke-trajectory-graph-edges.mjsgraph-plugin-adapter-smoke:diff --git a/scripts/smoke-trajectory-graph-edges.mjs b/scripts/smoke-trajectory-graph-edges.mjsindex e513583437..8835ce5a42 100644--- a/scripts/smoke-trajectory-graph-edges.mjs+++ b/scripts/smoke-trajectory-graph-edges.mjs@@ -9,7 +9,7 @@* Usage: node scripts/smoke-trajectory-graph-edges.mjs*/-import { fileURLToPath } from 'url';+import { fileURLToPath, pathToFileURL } from 'url';import * as path from 'path';import * as fs from 'fs';import * as os from 'os';@@ -17,6 +17,10 @@ import * as os from 'os';const __dirname = path.dirname(fileURLToPath(import.meta.url));const projectRoot = path.resolve(__dirname, '..');const distBase = path.join(projectRoot, 'v3/@claude-flow/cli/dist/src');+// Windows: absolute paths must be file:// URLs for dynamic import() β a bare+// C:\... path fails with ERR_UNSUPPORTED_ESM_URL_SCHEME (hit while debugging+// #2312 locally). No-op on POSIX.+const distImport = (rel) => import(pathToFileURL(path.join(distBase, rel)).href);// sql.js is available in root node_modules (installed by the CI setup step via// `npm install --legacy-peer-deps --ignore-scripts` at the repo root).@@ -72,10 +76,10 @@ console.log('\n[ADR-130 smoke] Phase 3 β SONA trajectory-to-graph hooks\n');async function testTrajectoryStep() {console.log('TEST 1: trajectory-step writes trajectory-caused edge');try {- const { initializeMemoryDatabase } = await import(path.join(distBase, 'memory/memory-initializer.js'));+ const { initializeMemoryDatabase } = await distImport('memory/memory-initializer.js');await initializeMemoryDatabase({ dbPath, force: true });- const mod = await import(path.join(distBase, 'mcp-tools/hooks-tools.js'));+ const mod = await distImport('mcp-tools/hooks-tools.js');const traj = mod.hooksTrajectoryStep ?? mod.allHooksTools?.find(t => t.name === 'hooks_intelligence_trajectory-step');if (!traj) { fail('1a', 'hooks_intelligence_trajectory-step not found'); return; }@@ -107,7 +111,7 @@ async function testTrajectoryStep() {async function testPostTask() {console.log('\nTEST 2: post-task writes reinforced-by edge');try {- const mod = await import(path.join(distBase, 'mcp-tools/hooks-tools.js'));+ const mod = await distImport('mcp-tools/hooks-tools.js');const postTask = mod.hooksPostTask ?? mod.allHooksTools?.find(t => t.name === 'hooks_post-task');if (!postTask) { fail('2a', 'hooks_post-task not found'); return; }@@ -139,7 +143,7 @@ async function testPostTask() {async function testPostTaskFailure() {console.log('\nTEST 3: post-task with success=false does not write reinforced-by edge');try {- const mod = await import(path.join(distBase, 'mcp-tools/hooks-tools.js'));+ const mod = await distImport('mcp-tools/hooks-tools.js');const postTask = mod.hooksPostTask ?? mod.allHooksTools?.find(t => t.name === 'hooks_post-task');const beforeCount = await countEdgesByRelation('reinforced-by');@@ -165,7 +169,7 @@ async function testPostTaskFailure() {async function testNonBlocking() {console.log('\nTEST 4: async writes are non-blocking (<200ms tool response)');try {- const mod = await import(path.join(distBase, 'mcp-tools/hooks-tools.js'));+ const mod = await distImport('mcp-tools/hooks-tools.js');const traj = mod.hooksTrajectoryStep ?? mod.allHooksTools?.find(t => t.name === 'hooks_intelligence_trajectory-step');const times = [];diff --git a/v3/@claude-flow/cli/src/memory/memory-bridge.ts b/v3/@claude-flow/cli/src/memory/memory-bridge.tsindex 1f71422dc8..3fce82ba11 100644--- a/v3/@claude-flow/cli/src/memory/memory-bridge.ts+++ b/v3/@claude-flow/cli/src/memory/memory-bridge.ts@@ -568,25 +568,41 @@ async function rescueAgentdbEmbedder(agentdb: { embedder?: { pipeline?: unknown;// own embed() does the right thing and we should not interpose.if (emb.pipeline) return;- type EmbedFn = (text: string) => Promise<{ embedding: number[] | Float32Array; dimensions: number; model: string }>;- let generateEmbedding: EmbedFn | null = null;+ // #2312: delegate to generateLOCALEmbedding, NOT generateEmbedding.+ // generateEmbedding is bridge-first β routing the rescued embed through it+ // closes a cycle (generateEmbedding β bridgeGenerateEmbedding β+ // embedder.embed [patched] β generateEmbedding β β¦) that allocated+ // unboundedly via microtasks until V8 hit the heap limit (~4 GB on the CI+ // runner, SIGABRT 134). The local chain never consults the bridge, so the+ // rescued embedder is a leaf. If the running memory-initializer build+ // predates generateLocalEmbedding, decline the rescue entirely β a stale+ // pairing must fail safe, not recurse.+ type EmbedFn = (text: string) => Promise<{ embedding: number[] | Float32Array; dimensions: number; model: string; backend?: 'onnx' | 'mock' }>;+ let localEmbed: EmbedFn | null = null;try {- const mod = (await import('./memory-initializer.js')) as unknown as { generateEmbedding?: EmbedFn };- generateEmbedding = mod.generateEmbedding ?? null;+ const mod = (await import('./memory-initializer.js')) as unknown as { generateLocalEmbedding?: EmbedFn };+ localEmbed = mod.generateLocalEmbedding ?? null;} catch {return; // can't import the rescuer β leave the mock fallback alone}- if (!generateEmbedding) return;- const embed: EmbedFn = generateEmbedding;+ if (!localEmbed) return;+ const embed: EmbedFn = localEmbed;- // Probe once to confirm the rescuer actually returns real (non-zero) vectors.- // If our own fallback chain also dead-ends in mock embeddings, leave- // agentdb as-is rather than swapping one mock for another.+ // Probe once to confirm the rescuer actually returns REAL ONNX vectors+ // (#2312: the old probe only checked non-zero, which the deterministic+ // hash fallback also satisfies β so it "rescued" agentdb's mock with our+ // own mock and reported it as real). Require backend === 'onnx'.try {const probe = await embed('rescue-probe');const arr = probe?.embedding ? Array.from(probe.embedding as ArrayLike<number>) : [];const hasSignal = arr.length > 0 && arr.some((v: number) => Math.abs(v) > 1e-9);- if (!hasSignal) return;+ if (!hasSignal || probe.backend !== 'onnx') {+ // Local chain is also degraded β leave agentdb's embedder alone, but+ // tag it so bridgeGenerateEmbedding's AUDIT-#3 isMock check reports+ // backend='mock' truthfully instead of labeling mock vectors 'onnx'.+ try { (emb as { backend?: string }).backend = 'mock'; } catch { /* frozen */ }+ return;+ }} catch {return;}diff --git a/v3/@claude-flow/cli/src/memory/memory-initializer.ts b/v3/@claude-flow/cli/src/memory/memory-initializer.tsindex 8ad5547b23..e6505f0c7c 100644--- a/v3/@claude-flow/cli/src/memory/memory-initializer.ts+++ b/v3/@claude-flow/cli/src/memory/memory-initializer.ts@@ -1894,6 +1894,30 @@ export async function generateEmbedding(text: string): Promise<{}}+ return generateLocalEmbedding(text);+}++/**+ * Generate an embedding using ONLY the local model chain (transformers.js /+ * ruvector ONNX / hash fallback) β never the AgentDB bridge.+ *+ * #2312: this MUST stay bridge-free. `memory-bridge.ts` rescues a degraded+ * agentdb embedder by delegating to this module; if that delegation went+ * through `generateEmbedding` (bridge-first), the call would re-enter the+ * patched `agentdb.embedder.embed` and recurse unboundedly:+ *+ * generateEmbedding β bridgeGenerateEmbedding β embedder.embed (patched)+ * β generateEmbedding β β¦ (heap OOM at ~4 GB on CI, no stack overflow+ * because the cycle is async/microtask-driven)+ *+ * Keeping the local chain as its own export breaks that cycle structurally.+ */+export async function generateLocalEmbedding(text: string): Promise<{+ embedding: number[];+ dimensions: number;+ model: string;+ backend: 'onnx' | 'mock';+}> {// Ensure model is loadedif (!embeddingModelState?.loaded) {await loadEmbeddingModel();