fix(opencode): remove shell tool detached flag to prevent zombie processes#29510
Open
z1243161996 wants to merge 1 commit into
Open
fix(opencode): remove shell tool detached flag to prevent zombie processes#29510z1243161996 wants to merge 1 commit into
z1243161996 wants to merge 1 commit into
Conversation
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>
Contributor
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
6 tasks
6 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue for this PR
Closes #29506
Type of change
What does this PR do?
On Linux,
tool/shell.tsspawns child shell processes withdetached: true, which callssetsid()to put them in their own process group/session. When these child processes exit before the parent callswaitpid(), and with noSIGCHLDhandler anywhere in the codebase, they become<defunct>zombie processes. Observed 11 zombies from 8opencode runsessions.This PR changes
detached: process.platform !== "win32"todetached: false. Withoutsetsid(), child processes remain in the parent's process group and are properly reaped by Node.js whenhandle.exitCoderesolves. Explicit process cleanup is already handled viahandle.kill()in abort/timeout paths -- signal isolation viadetachedis unnecessary.Related: #29294 (
detached: truecauses 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 runsessions with shell tool invocations, confirmed zero zombie processes accumulate (previously 11 zombies from 8 sessions). Confirmed abort/timeout kill paths still work viahandle.kill().Checklist