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

test(hive-mind): retry the real-CLI child on transient spawn failures (ENOMEM/EAGAIN) with back-off

RuFlo7106a4c1661f
diff --git a/v3/@claude-flow/cli/__tests__/hive-mind-spawn-broadcast-shutdown-auth.test.ts b/v3/@claude-flow/cli/__tests__/hive-mind-spawn-broadcast-shutdown-auth.test.ts
index 08f7d1da04..2d9754229b 100644
--- a/v3/@claude-flow/cli/__tests__/hive-mind-spawn-broadcast-shutdown-auth.test.ts
+++ b/v3/@claude-flow/cli/__tests__/hive-mind-spawn-broadcast-shutdown-auth.test.ts
@@ -51,10 +51,17 @@ import { hiveMindTools, getHiveTokenForCli } from '../src/mcp-tools/hive-mind-to
const CLI = join(__dirname, '..', 'bin', 'cli.js');
-// A child with no exit status either died from a signal or never started (spawn
-// error: EAGAIN/ENOMEM/EMFILE under the full parallel suite). A real defect
-// repeats, so that case is retried once, and the signal / error code and message
-// are always reported instead of an opaque -1.
+// A child with no exit status either died from a signal or never started. Under
+// the full parallel suite (hundreds of forked test files) the runner can be out of
+// memory for a moment: run 38290339354 failed this test with
+// "spawnSync node ENOMEM". That is resource pressure, not a defect, and it clears
+// as sibling forks exit, so such a spawn is retried a few times with a short
+// back-off. A real defect repeats on every attempt and still fails; the signal /
+// error code and message are always reported instead of an opaque -1.
+const TRANSIENT_SPAWN = new Set(['ENOMEM', 'EAGAIN', 'EMFILE', 'ENFILE']);
+function pause(ms: number): void {
+ Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms);
+}
function runCli(args: string[], cwd: string, attempt = 1): { stdout: string; exit: number } {
try {
const stdout = execFileSync('node', [CLI, ...args], {
@@ -66,8 +73,11 @@ function runCli(args: string[], cwd: string, attempt = 1): { stdout: string; exi
return { stdout, exit: 0 };
} catch (err) {
const e = err as { status?: number | null; signal?: string | null; code?: string; message?: string; stdout?: Buffer; stderr?: Buffer };
- if (e.status == null && attempt < 2) return runCli(args, cwd, attempt + 1);
- const killed = e.status == null ? `\n[no exit status: signal=${e.signal ?? 'none'} code=${e.code ?? 'none'} message=${String(e.message ?? '').split('\n')[0]}]` : '';
+ if (e.status == null && attempt < 5 && (e.signal || TRANSIENT_SPAWN.has(String(e.code)))) {
+ pause(500 * attempt);
+ return runCli(args, cwd, attempt + 1);
+ }
+ const killed = e.status == null ? `\n[no exit status after ${attempt} attempt(s): signal=${e.signal ?? 'none'} code=${e.code ?? 'none'} message=${String(e.message ?? '').split('\n')[0]}]` : '';
return { stdout: (e.stdout?.toString() ?? '') + (e.stderr?.toString() ?? '') + killed, exit: e.status ?? -1 };
}
}