Skip to content

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

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

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

Conversation

@ozpool

@ozpool ozpool commented Jun 16, 2026

Copy link
Copy Markdown

Issue for this PR

Closes #32335

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

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.ts already 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 left untouched.

How did you verify your code works?

Added a regression test exits promptly after a successful prompt instead of hanging 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

Screenshots / recordings

Not a UI change.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

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
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