Skip to content

fix(opencode): remove shell tool detached flag to prevent zombie processes#29678

Open
JunJieLiu51520 wants to merge 1 commit into
anomalyco:devfrom
JunJieLiu51520:fix/zombie-processes-detached-shell
Open

fix(opencode): remove shell tool detached flag to prevent zombie processes#29678
JunJieLiu51520 wants to merge 1 commit into
anomalyco:devfrom
JunJieLiu51520:fix/zombie-processes-detached-shell

Conversation

@JunJieLiu51520
Copy link
Copy Markdown

Issue for this PR

Closes #29506

Type of change

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

What does this PR do?

tool/shell.ts spawns child processes with detached: true on Linux, which calls setsid() and puts children in their own process group. When these children exit, Node.js cannot reap them because they are in a separate session, resulting in <defunct> zombie processes accumulating across opencode run sessions.

The fix sets detached: false on all platforms. This is safe because:

  1. Child processes stay in the parent's process group so Node.js reaps them normally via handle.exitCode
  2. Explicit cleanup already exists via handle.kill() in abort/timeout paths
  3. Signal-group isolation was never leveraged elsewhere in the codebase

How did you verify your code works?

Confirmed that the cmd() function no longer passes detached: true on any platform. The abort/timeout kill paths remain unchanged and continue to handle process cleanup.

Checklist

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

…esses

On Linux, spawning shell children with `detached: true` calls setsid()
which puts them in their own process group. Without a SIGCHLD handler,
exited children become zombies. Explicit cleanup is already handled via
handle.kill() in abort/timeout paths, making signal-group isolation
unnecessary.

Fixes anomalyco#29506
@github-actions
Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

Potential Duplicate Found

PR #29510 - fix(opencode): remove shell tool detached flag to prevent zombie processes
#29510

This appears to be a duplicate of the current PR #29678. Both PRs have:

Please check PR #29510 to see if it's already merged, closed, or still in progress before proceeding with PR #29678.

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.

fix(opencode): zombie processes from detached shell children on Linux

1 participant