fix(opencode): exit process after a non-interactive run#32516
Open
ozpool wants to merge 1 commit into
Open
Conversation
A non-interactive `opencode run` finished its prompt and returned, but the running server keeps handles open (db connections, sockets, timers), so the event loop never drained and the process stayed alive with an idle loop. Scheduled runs therefore leaked, accumulating orphaned processes over time. Exit explicitly once the run completes, preserving the resolved exit code and matching the error branches in this command that already call process.exit. Attach mode drives a separate server, so it is left running. Closes anomalyco#32335
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.
Issue for this PR
Closes #32335
Type of change
What does this PR do?
A non-interactive
opencode run(the form scheduled cron jobs use) finishes its prompt and returns from the command handler, but the in-process server keeps handles open — db connections, unix sockets, timers. With nothing draining the event loop, the process stays alive on an idle loop instead of exiting, so scheduled runs pile up (re-parented to pid 1) and leak hundreds of MB of RSS each.This exits explicitly once the non-interactive run completes, preserving the resolved exit code. It matches the rest of the command: every error branch in
run.tsalready callsprocess.exit(1), and the success path was the only one that just setprocess.exitCodeand returned. The block now converges on a singleprocess.exit(process.exitCode ?? 0)after the work finishes.Output is not truncated —
finish()awaits the event loop that prints the response before the exit runs. Attach mode (--attach) drives a separate, already-running server, so it is left untouched.How did you verify your code works?
Added a regression test
exits promptly after a successful prompt instead of hangingtorun-process.test.ts, mirroring the existing #27371 hang regression: it runs a successful prompt through the real CLI subprocess and asserts a clean exit 0 well under the harness timeout.Screenshots / recordings
Not a UI change.
Checklist