Skip to content

Conversation

veracioux
Copy link
Contributor

Reproduced using MCP config from: #1717

The easiest way to reproduce (and verify the fix) is to run opencode run hi.

Investigation:

  • The MCP servers from the issue are run via docker run
  • When opencode exits, the ai library sends SIGTERM to all child MCP processes that use stdio transports
  • The problem is that the child processes are the docker run client, and SIGTERM isn't properly delivered, unless docker run --init was used. So the subprocesses stick around, preventing opencode from exiting. I verified this with a minimalistic subprocess-spawning bun program and strace
  • What does work though, is killing the opencode process itself using process.exit, in which case SIGTERM is delivered correctly
  • Fix: I added a process.exit() when the CLI is done with everything.

NOTE: Issue also happens in (some, maybe all) MCP servers wrapped by shell scripts, which this also fixes.

Closes #1717.
Maybe also #1810.
Maybe also #2406.

@veracioux veracioux force-pushed the bugfix/opencode-hangs-after-exit branch from 3ec284c to 90a62c6 Compare October 11, 2025 08:54
@veracioux veracioux force-pushed the bugfix/opencode-hangs-after-exit branch from 90a62c6 to fa73183 Compare October 11, 2025 08:57
@veracioux
Copy link
Contributor Author

Rebased to remove unintended extra commit.

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.

TUI exits but process hangs (no shell return) when opencode.json is present

2 participants