Skip to content

fix(opencode): exit process after a non-interactive run#32404

Closed
ozpool wants to merge 1 commit into
anomalyco:devfrom
ozpool:run-exit-cleanly
Closed

fix(opencode): exit process after a non-interactive run#32404
ozpool wants to merge 1 commit into
anomalyco:devfrom
ozpool:run-exit-cleanly

Conversation

@ozpool

@ozpool ozpool commented Jun 15, 2026

Copy link
Copy Markdown

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 run is 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.ts calls process.exit(1), and the success path was the only one that just set process.exitCode and returned. The block now converges on a single process.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 explicitly left untouched.

Test

Added exits promptly after a successful prompt instead of hanging (regression for #32335) to run-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.

bun test test/cli/run/run-process.test.ts   # 5 pass
tsgo --noEmit                                # clean

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
@github-actions github-actions Bot added the needs:compliance This means the issue will auto-close after 2 hours. label Jun 15, 2026
@github-actions

Copy link
Copy Markdown
Contributor

This PR doesn't fully meet our contributing guidelines and PR template.

What needs to be fixed:

  • PR description is missing required template sections. Please use the PR template.

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.

@github-actions

Copy link
Copy Markdown
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.

@github-actions github-actions Bot removed the needs:compliance This means the issue will auto-close after 2 hours. label Jun 15, 2026
@github-actions github-actions Bot closed this Jun 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: opencode run processes don't exit after completing scheduled work, causing memory leak

1 participant