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
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
address review (codex): settle onComplete when close-handler finalization fails (#1825)
[._.]/ Adam Eivy561f196a1377
diff --git a/server/lib/aiToolkit/runner.js b/server/lib/aiToolkit/runner.jsindex bb0804d09a..ac00753e50 100644--- a/server/lib/aiToolkit/runner.js+++ b/server/lib/aiToolkit/runner.js@@ -481,6 +481,21 @@ export function createRunnerService(config = {}) {onComplete?.(metadata);} catch (handlerErr) {console.error(`❌ Run ${runId} failure handler error: ${handlerErr.message}`);+ // Still settle callers waiting on onComplete so a persistence/hook+ // failure surfaces as a failed run instead of hanging forever.+ try {+ const failMetadata = {+ endTime: new Date().toISOString(),+ duration: Date.now() - startTime,+ success: false,+ error: `Run finalization failed: ${handlerErr.message}`,+ outputSize: Buffer.byteLength(output),+ };+ hooks.onRunFailed?.(failMetadata, failMetadata.error, output);+ onComplete?.(failMetadata);+ } catch (settleErr) {+ console.error(`❌ Run ${runId} failed to settle after failure handler error: ${settleErr.message}`);+ }}});diff --git a/server/services/runner.js b/server/services/runner.jsindex 3ab7ea4659..2c0e9886a3 100644--- a/server/services/runner.js+++ b/server/services/runner.js@@ -279,6 +279,24 @@ export async function executeCliRun({ runId, provider, prompt, workspacePath, ononComplete?.(metadata);} catch (err) {console.error(`❌ Run ${runId} close handler error: ${err.message}`);+ // The timeout was already cleared and the child has closed, so callers+ // waiting on onComplete would hang forever if we only logged. Settle them+ // with failure metadata so a disk/hook failure surfaces as a failed run.+ try {+ const failMetadata = {+ endTime: new Date().toISOString(),+ duration: Date.now() - startTime,+ exitCode: code,+ success: false,+ error: `Run finalization failed: ${err.message}`,+ errorCategory: 'finalization_error',+ outputSize: Buffer.byteLength(output),+ };+ runnerConfig.hooks?.onRunFailed?.(failMetadata, failMetadata.error, output);+ onComplete?.(failMetadata);+ } catch (settleErr) {+ console.error(`❌ Run ${runId} failed to settle after close handler error: ${settleErr.message}`);+ }}});diff --git a/server/services/runner.test.js b/server/services/runner.test.jsindex 93cdac43e0..fcbdcb919a 100644--- a/server/services/runner.test.js+++ b/server/services/runner.test.js@@ -164,7 +164,7 @@ describe('executeCliRun — Codex sentinel suppression', () => {});describe('executeCliRun — close handler crash guard', () => {- it('does not throw an unhandled rejection when a metadata write fails on close', async () => {+ it('does not crash and still settles the caller when a metadata write fails on close', async () => {const child = makeChild();spawn.mockReturnValue(child);const errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});@@ -180,7 +180,8 @@ describe('executeCliRun — close handler crash guard', () => {defaultModel: 'codex-configured-default', timeout: 5000,};- await executeCliRun({ runId: 'run-write-fail', provider, prompt: 'test prompt', workspacePath: '/workspace' });+ const onComplete = vi.fn();+ await executeCliRun({ runId: 'run-write-fail', provider, prompt: 'test prompt', workspacePath: '/workspace', onComplete });child.stdout.emit('data', Buffer.from('output'));child.emit('close', 0);@@ -188,6 +189,9 @@ describe('executeCliRun — close handler crash guard', () => {await new Promise((resolve) => setImmediate(resolve));expect(errorSpy).toHaveBeenCalledWith(expect.stringContaining('run-write-fail close handler error'));+ // The caller must still be settled with failure metadata, not left hanging.+ expect(onComplete).toHaveBeenCalledTimes(1);+ expect(onComplete.mock.calls[0][0]).toMatchObject({ success: false, errorCategory: 'finalization_error' });errorSpy.mockRestore();});});