Skip to content

Commit 40c19a2

Browse files
fix: use process.exitCode instead of process.exit() so runner finally blocks clean up temp files
process.exit() terminates the Node.js process immediately without executing pending finally blocks. All five runners (claude, openai, crewai, nanobot, openclaw) write temporary files or directories then call process.exit() inside a try block, so the finally cleanup is always skipped. Replace process.exit(N) with process.exitCode = N; return so the finally block executes and removes temporary files before the process exits naturally. This prevents system prompt content, agent configs, and API key material written to /tmp from persisting on disk indefinitely.
1 parent 01f72c7 commit 40c19a2

File tree

5 files changed

+15
-10
lines changed

5 files changed

+15
-10
lines changed

src/runners/claude.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,11 @@ export function runWithClaude(agentDir: string, manifest: AgentManifest, options
9696
if (result.error) {
9797
error(`Failed to launch Claude Code: ${result.error.message}`);
9898
info('Make sure Claude Code CLI is installed: npm install -g @anthropic-ai/claude-code');
99-
process.exit(1);
99+
process.exitCode = 1;
100+
return;
100101
}
101102

102-
process.exit(result.status ?? 0);
103+
process.exitCode = result.status ?? 0;
103104
} finally {
104105
for (const f of tmpFiles) {
105106
try { unlinkSync(f); } catch { /* ignore */ }

src/runners/crewai.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,11 @@ export function runWithCrewAI(agentDir: string, _manifest: AgentManifest): void
2525
if (result.error) {
2626
error(`Failed to run CrewAI: ${result.error.message}`);
2727
info('Make sure the crewai CLI is installed: pip install crewai');
28-
process.exit(1);
28+
process.exitCode = 1;
29+
return;
2930
}
3031

31-
process.exit(result.status ?? 0);
32+
process.exitCode = result.status ?? 0;
3233
} finally {
3334
try { unlinkSync(tmpFile); } catch { /* ignore */ }
3435
}

src/runners/nanobot.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,11 @@ export function runWithNanobot(agentDir: string, manifest: AgentManifest, option
5858
error(`Failed to launch Nanobot: ${result.error.message}`);
5959
info('Install Nanobot with: pip install nanobot-ai');
6060
info('Or: uv tool install nanobot-ai');
61-
process.exit(1);
61+
process.exitCode = 1;
62+
return;
6263
}
6364

64-
process.exit(result.status ?? 0);
65+
process.exitCode = result.status ?? 0;
6566
} finally {
6667
try { rmSync(tmpConfigDir, { recursive: true, force: true }); } catch { /* ignore */ }
6768
}

src/runners/openai.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,11 @@ export function runWithOpenAI(agentDir: string, _manifest: AgentManifest): void
3232
if (result.error) {
3333
error(`Failed to run Python: ${result.error.message}`);
3434
info('Make sure python3 is installed and the openai-agents package is available');
35-
process.exit(1);
35+
process.exitCode = 1;
36+
return;
3637
}
3738

38-
process.exit(result.status ?? 0);
39+
process.exitCode = result.status ?? 0;
3940
} finally {
4041
try { unlinkSync(tmpFile); } catch { /* ignore */ }
4142
}

src/runners/openclaw.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,11 @@ export function runWithOpenClaw(agentDir: string, manifest: AgentManifest, optio
118118
if (result.error) {
119119
error(`Failed to launch OpenClaw: ${result.error.message}`);
120120
info('Make sure OpenClaw is installed: npm install -g openclaw@latest');
121-
process.exit(1);
121+
process.exitCode = 1;
122+
return;
122123
}
123124

124-
process.exit(result.status ?? 0);
125+
process.exitCode = result.status ?? 0;
125126
} finally {
126127
// Cleanup temp workspace
127128
try { rmSync(workspaceDir, { recursive: true, force: true }); } catch { /* ignore */ }

0 commit comments

Comments
 (0)