fix(opencode): exit process after a non-interactive run#32404
Closed
ozpool wants to merge 1 commit into
Closed
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
Contributor
|
This PR doesn't fully meet our contributing guidelines and PR template. What needs to be fixed:
Please edit this PR description to address the above within 2 hours, or it will be automatically closed. If you believe this was flagged incorrectly, please let a maintainer know. |
Contributor
|
This pull request has been automatically closed because it was not updated to meet our contributing guidelines within the 2-hour window. Feel free to open a new pull request that follows our guidelines. |
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.
Closes #32335
Problem
A non-interactive
opencode run(the form used by scheduled cron jobs) 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 Node/Bun process stays alive indefinitely on an idle loop instead of exiting.When
opencode runis driven on a schedule, those processes accumulate (re-parented to pid 1) and leak hundreds of MB of RSS each over time.Fix
Exit explicitly once the non-interactive run completes, preserving the resolved exit code.
This already matches the rest of this command: every error branch in
run.tscallsprocess.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.finish()awaits the event loop that prints the response before the exit runs.--attach) drives a separate, already-running server, so it is explicitly left untouched.Test
Added
exits promptly after a successful prompt instead of hanging (regression for #32335)torun-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.