🌊 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(reasoningbank): stop blocking the event loop on fallback embeddings (#4422)
ordinary beingb45b035e4968
diff --git a/v3/@claude-flow/hooks/src/__tests__/fallback-embedding-async-4410.test.ts b/v3/@claude-flow/hooks/src/__tests__/fallback-embedding-async-4410.test.tsnew file mode 100644index 0000000000..ad58bdc75b--- /dev/null+++ b/v3/@claude-flow/hooks/src/__tests__/fallback-embedding-async-4410.test.ts@@ -0,0 +1,38 @@+/**+ * #4410 memory scan: FallbackEmbeddingService used execFileSync, blocking the+ * event loop for up to 10 s per embedding whenever the primary embedder was+ * unavailable. Use the async execFile instead.+ */+import { afterEach, describe, expect, it, vi } from 'vitest';++vi.mock('child_process', () => ({+ execFile: (_file: string, _args: string[], _opts: unknown, cb: (err: Error | null, stdout: string, stderr: string) => void) => {+ setTimeout(() => cb(null, '[0.5,0.25]', ''), 60);+ },+ // The pre-fix implementation uses this; keep the baseline comparable.+ execFileSync: () => {+ const end = Date.now() + 60;+ while (Date.now() < end) { /* simulate the blocking child */ }+ return '[0.5,0.25]';+ },+}));++import { FallbackEmbeddingService } from '../reasoningbank/index.js';++afterEach(() => {+ vi.clearAllTimers();+});++describe('FallbackEmbeddingService embed is non-blocking (#4410)', () => {+ it('lets a timer run while the fallback embedding process is pending', async () => {+ const service = new FallbackEmbeddingService(2);+ let timerFired = false;+ const timer = setTimeout(() => { timerFired = true; }, 10);++ const embedding = await service.embed('probe');++ clearTimeout(timer);+ expect(timerFired).toBe(true);+ expect(Array.from(embedding)).toEqual([0.5, 0.25]);+ });+});diff --git a/v3/@claude-flow/hooks/src/reasoningbank/index.ts b/v3/@claude-flow/hooks/src/reasoningbank/index.tsindex 816b9f7b69..64a2b2b725 100644--- a/v3/@claude-flow/hooks/src/reasoningbank/index.ts+++ b/v3/@claude-flow/hooks/src/reasoningbank/index.ts@@ -970,9 +970,10 @@ class RealEmbeddingService implements IEmbeddingService {}/**- * Fallback embedding service (hash-based)+ * Fallback embedding service (agentic-flow ONNX, then hash-based)+ * @internal Exported for the event-loop blocking regression test.*/-class FallbackEmbeddingService implements IEmbeddingService {+export class FallbackEmbeddingService implements IEmbeddingService {private dimensions: number;private cache: Map<string, Float32Array> = new Map();@@ -986,17 +987,25 @@ class FallbackEmbeddingService implements IEmbeddingService {return this.cache.get(cacheKey)!;}- // Try agentic-flow ONNX embeddings first+ // Try agentic-flow ONNX embeddings first. Use the async execFile, not+ // execFileSync: the latter blocked the event loop for up to 10 s per+ // embedding whenever the primary path was unavailable (#4410).try {- const { execFileSync } = await import('child_process');- // Use execFileSync with shell: false to prevent command injection- // Pass text as argument array to avoid shell interpolation+ const { execFile } = await import('child_process');+ // Pass text as an argument array (shell:false), so a prompt cannot+ // become a shell command.const safeText = text.slice(0, 500).replace(/[\x00-\x1f]/g, ''); // Remove control chars- const result = execFileSync(- 'npx',- ['agentic-flow@alpha', 'embeddings', 'generate', safeText, '--format', 'json'],- { encoding: 'utf-8', timeout: 10000, shell: false, stdio: ['pipe', 'pipe', 'pipe'] }- );+ const result = await new Promise<string>((resolve, reject) => {+ execFile(+ process.platform === 'win32' ? 'npx.cmd' : 'npx',+ ['agentic-flow@alpha', 'embeddings', 'generate', safeText, '--format', 'json'],+ { encoding: 'utf-8', timeout: 10000, shell: false },+ (error, stdout) => {+ if (error) reject(error);+ else resolve(String(stdout));+ },+ );+ });const parsed = JSON.parse(result);const embedding = new Float32Array(parsed.embedding || parsed);this.cache.set(cacheKey, embedding);