Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

fix: classify a failed CLI spawn as a spawn error so it is not escalated as unknown

[._.]/ Adam Eivycda9db4d5fb5
diff --git a/server/lib/aiToolkit/runner.js b/server/lib/aiToolkit/runner.js
index 0cd3949e6b..243c36fe2c 100644
--- a/server/lib/aiToolkit/runner.js
+++ b/server/lib/aiToolkit/runner.js
@@ -529,27 +529,39 @@ export function createRunnerService(config = {}) {
if (settled) return;
settled = true;
releaseRun();
- console.error(`❌ Run ${runId} spawn error: ${err.message}`);
+ const message = err?.message || 'CLI spawn failed';
+ console.error(`❌ Run ${runId} spawn error: ${message}`);
void (async () => {
+ // The 'error' event is the classification: a missing binary's message
+ // matches SPAWN_ERROR, but EACCES/EMFILE do not, and a null category
+ // is read as an unknown provider failure. Keep the raw message — the
+ // pattern's extracted text drops the spawn detail callers match on.
+ const errorAnalysis = analyzeError(message, -1);
+ errorAnalysis.category = ERROR_CATEGORIES.SPAWN_ERROR;
+ errorAnalysis.hasError = true;
+ errorAnalysis.requiresFallback = true;
+ errorAnalysis.message = message;
const failMetadata = {
endTime: new Date().toISOString(),
duration: Date.now() - startTime,
exitCode: -1,
success: false,
- error: err.message,
+ error: message,
+ errorCategory: ERROR_CATEGORIES.SPAWN_ERROR,
+ errorAnalysis,
outputSize: Buffer.byteLength(output),
};
try {
- const metadata = safeJsonParse(await readFile(metadataPath, 'utf-8').catch(() => '{}'));
+ let metadata = safeJsonParse(await readFile(metadataPath, 'utf-8').catch(() => '{}'));
+ if (!metadata || typeof metadata !== 'object' || Array.isArray(metadata)) metadata = {};
Object.assign(metadata, failMetadata);
await atomicWrite(outputPath, output);
await atomicWrite(metadataPath, metadata);
- failMetadata.errorCategory = metadata.errorCategory;
Object.assign(failMetadata, metadata);
} catch (writeErr) {
console.error(`❌ Run ${runId} spawn-error finalization failed: ${writeErr.message}`);
}
- safeSettle(() => hooks.onRunFailed?.(failMetadata, err.message, output), `Run ${runId} onRunFailed hook`);
+ safeSettle(() => hooks.onRunFailed?.(failMetadata, failMetadata.error, output), `Run ${runId} onRunFailed hook`);
safeSettle(() => onComplete?.(failMetadata), `Run ${runId} onComplete`);
})();
});
diff --git a/server/lib/aiToolkit/runner.test.js b/server/lib/aiToolkit/runner.test.js
index a2b02ffe61..63234e6677 100644
--- a/server/lib/aiToolkit/runner.test.js
+++ b/server/lib/aiToolkit/runner.test.js
@@ -1789,9 +1789,15 @@ describe('AI Toolkit runner — built-in executeCliRun spawn (#1865)', () => {
expect(child.stdin.listenerCount('error')).toBeGreaterThan(0);
expect(await runner.isRunActive(runId)).toBe(true);
+ // EPIPE on stdin must not finish the run or throw — the child may still
+ // be exiting, and 'close'/'error' own settlement.
+ child.stdin.emit('error', Object.assign(new Error('write EPIPE'), { code: 'EPIPE' }));
+ expect(completions).toHaveLength(0);
+ expect(onRunFailed).not.toHaveBeenCalled();
+ expect(await runner.isRunActive(runId)).toBe(true);
+
const spawnErr = new Error('spawn missing-cli ENOENT');
spawnErr.code = 'ENOENT';
- child.stdin.emit('error', Object.assign(new Error('write EPIPE'), { code: 'EPIPE' }));
child.emit('error', spawnErr);
child.emit('close', null);
@@ -1800,12 +1806,14 @@ describe('AI Toolkit runner — built-in executeCliRun spawn (#1865)', () => {
expect(metadata.success).toBe(false);
expect(metadata.exitCode).toBe(-1);
expect(metadata.error).toBe('spawn missing-cli ENOENT');
+ expect(metadata.errorCategory).toBe('spawn-error');
expect(onRunFailed).toHaveBeenCalledTimes(1);
expect(await runner.isRunActive(runId)).toBe(false);
const persisted = JSON.parse(await readFile(join(dataDir, 'runs', runId, 'metadata.json'), 'utf8'));
expect(persisted.success).toBe(false);
expect(persisted.exitCode).toBe(-1);
+ expect(persisted.errorCategory).toBe('spawn-error');
await rm(dataDir, { recursive: true, force: true });
});