fix: use process.exitCode instead of process.exit() so runner finally blocks clean up temp files#49
Merged
shreyas-lyzr merged 1 commit intoopen-gitagent:mainfrom Mar 25, 2026
Conversation
… 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.
d0288e1 to
40c19a2
Compare
Contributor
|
Reviewed and merged. Correct fix — process.exit() skips the event loop and bypasses finally blocks, leaving temp directories behind. process.exitCode + return lets the finally cleanup run before Node exits. Applied consistently across 5 runners. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Replace
process.exit(N)withprocess.exitCode = N; returninside try/finally blocks in all five runners:claude,openai,crewai,nanobot,openclaw.Why
process.exit()terminates Node.js immediately without running any pendingfinallyblocks. Every runner in this project follows the same pattern:Because the finally block is skipped, temporary files written to
/tmp— including system prompt content, agent configs, and API credentials passed via environment — are left on disk indefinitely after every invocation.Using
process.exitCode = N; returnlets the finally block execute first, removing all temporary files, and then the process exits naturally with the set exit code.Affected runners:
src/runners/claude.ts— system prompt + hooks settings JSON in /tmpsrc/runners/openai.ts— generated Python script in /tmpsrc/runners/crewai.ts— generated YAML config in /tmpsrc/runners/nanobot.ts— config dir + system prompt file in /tmpsrc/runners/openclaw.ts— full workspace directory in /tmpHow Tested
npm run buildpassesgitagent validatepasses on example agentsManually confirmed that after
gitagent runcompletes, no leftover/tmp/gitagent-*files remain.Checklist