Skip to content

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

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

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

Conversation

@z1243161996

@z1243161996 z1243161996 commented May 27, 2026

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?

On Linux, tool/shell.ts spawns child shell processes with detached: true, which calls setsid() to put them in their own process group/session. When these child processes exit before the parent calls waitpid(), and with no SIGCHLD handler anywhere in the codebase, they become <defunct> zombie processes. Observed 11 zombies from 8 opencode run sessions.

This PR changes detached: process.platform !== "win32" to detached: false. Without setsid(), child processes remain in the parent's process group and are properly reaped by Node.js when handle.exitCode resolves. Explicit process cleanup is already handled via handle.kill() in abort/timeout paths -- signal isolation via detached is unnecessary.

Related: #29294 (detached: true causes parent to retain write-end FDs of child stdout pipes), #28654 (timeout detection)

How did you verify your code works?

Verified on Linux (Ubuntu 24.04): ran multiple opencode run sessions with shell tool invocations, confirmed zero zombie processes accumulate (previously 11 zombies from 8 sessions). Confirmed abort/timeout kill paths still work via handle.kill().

Checklist

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

On Linux, spawning shell processes with `detached: true` puts them in
their own session via setsid(). When these processes exit before the
parent calls waitpid(), and with no SIGCHLD handler in the codebase,
they become zombie processes.

Change `detached: process.platform !== "win32"` to `detached: false`.
Child processes remain in the parent's process group and are properly
reaped by Node.js when handle.exitCode resolves.

Also helps with anomalyco#29294 — detached: true causes the parent to retain
write-end copies of child stdout pipes, preventing EOF delivery.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@github-actions github-actions Bot added the needs:compliance This means the issue will auto-close after 2 hours. label May 27, 2026
@z1243161996 z1243161996 changed the title fix(opencode): remove detached flag to prevent zombie processes on Linux fix(opencode): remove shell tool detached flag to prevent zombie processes May 27, 2026
@github-actions github-actions Bot removed the needs:compliance This means the issue will auto-close after 2 hours. label May 27, 2026
@github-actions

Copy link
Copy Markdown
Contributor

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

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