Skip to content

fix: add --no-orphans to compiled binary execArgv#30875

Open
jwcrystal wants to merge 1 commit into
anomalyco:devfrom
jwcrystal:fix/mcp-orphan-cleanup
Open

fix: add --no-orphans to compiled binary execArgv#30875
jwcrystal wants to merge 1 commit into
anomalyco:devfrom
jwcrystal:fix/mcp-orphan-cleanup

Conversation

@jwcrystal
Copy link
Copy Markdown

@jwcrystal jwcrystal commented Jun 5, 2026

Issue for this PR

Closes #30123

For context: existing issues #30073, #30123, and #26714 all discuss the same MCP orphan problem. This PR takes the simplest approach — enabling Bun's built-in --no-orphans mode in the compiled binary — rather than adding a process.on('exit') handler or modifying MCP lifecycle logic.

Type of change

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

What does this PR do?

Adds --no-orphans to the compiled binary's execArgv in the build script. When opencode exits, Bun now automatically kills all descendant processes (including MCP stdio servers spawned via StdioClientTransport).

Before this change, MCP child processes became orphans reparented to init/launchd on abnormal exit (SIGKILL/crash) or the process.exit() fallback. Bun's --no-orphans handles both clean and unclean exits (Linux prctl / macOS kqueue descendant reaper).

How did you verify your code works?

The change is a single flag addition to the Bun build config (execArgv). The flag is documented and maintained by Bun — verified its behavior matches the implementation described in Bun's ParentDeathWatchdog (Linux prctl, macOS kqueue, clean-exit tree walk with SIGSTOP+verify SIGKILL). No runtime test was added because the behavior depends on Bun's runtime internals, not opencode logic.

Screenshots / recordings

N/A

Checklist

  • I have tested my changes locally (verified build script syntax, confirmed flag is accepted)
  • I have not included unrelated changes in this PR

@jwcrystal jwcrystal requested a review from adamdotdevin as a code owner June 5, 2026 06:38
@github-actions github-actions Bot added needs:compliance This means the issue will auto-close after 2 hours. needs:title labels Jun 5, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jun 5, 2026

Hey! Your PR title build: add --no-orphans to compiled binary execArgv doesn't follow conventional commit format.

Please update it to start with one of:

  • feat: or feat(scope): new feature
  • fix: or fix(scope): bug fix
  • docs: or docs(scope): documentation changes
  • chore: or chore(scope): maintenance tasks
  • refactor: or refactor(scope): code refactoring
  • test: or test(scope): adding or updating tests

Where scope is the package name (e.g., app, desktop, opencode).

See CONTRIBUTING.md for details.

@jwcrystal jwcrystal changed the title build: add --no-orphans to compiled binary execArgv fix: add --no-orphans to compiled binary execArgv Jun 5, 2026
@github-actions github-actions Bot removed needs:title needs:compliance This means the issue will auto-close after 2 hours. labels Jun 5, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jun 5, 2026

Thanks for updating your PR! It now meets our contributing guidelines. 👍

Enable Bun's --no-orphans flag so MCP stdio server child processes
cannot outlive the opencode parent process on Linux and macOS.

Bun's no-orphans mode uses PR_SET_PDEATHSIG (Linux) and kqueue
EVFILT_PROC (macOS) to ensure all descendant processes are killed
when the parent exits, even on SIGKILL or crash.
@jwcrystal jwcrystal force-pushed the fix/mcp-orphan-cleanup branch from 7f322f1 to f9c01fe Compare June 5, 2026 06:43
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.

MCP server processes not cleaned up on exit (orphan processes) + eagerly starts all servers

1 participant