You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
opencode-pty daemon leaks zombie child processes (unbounded growth under single daemon PID) #63976
opencode-pty daemon leaks zombie child processes (unbounded growth under a single daemon PID)
Since upgrading to OpenCode 2.3.0, every finished shell command stays a <defunct> zombie child of opencode-pty daemon and is never reaped. Zombies grow monotonically for the daemon's entire lifetime, holding PIDs and counting against TasksMax.
Because both duplicates are closed, please do not close this issue as a duplicate. The unbounded growth (past 25, under one daemon PID) is confirmed here and by iehgit (100 zombies, 2h11m) and jotenakis2 (aarch64, monotonic past 25).
Related bot-behavior complaint
#63975 — opencodejr closed #63948 without checking #63817 was open, and does not respond to reopen pings.
Expected
Exited children should be reaped promptly (e.g. SIGCHLD/waitid/waitpid in the event loop) so no [defunct] children remain after a command completes.
Thanks for the details. I reproduced the growth past 25 on 2.3.0, and it also happens on the latest dev (9f1639c).
Single directory: With one TUI session running 40 shell tool calls in one directory, the daemon stayed at exactly 25 zombies. That matches the earlier result in #63817.
Several directories: With one opencode serve, and so one opencode-pty daemon, I ran 30 commands in each of 4 project directories through the HTTP API. The daemon's zombie children went 25 → 50 → 75 → 100, one step of 25 per directory. That fits the 100 that iehgit saw.
Why it grows (from the code): the limit of 25 recently finished commands is kept per directory, not per daemon. Each directory used keeps up to 25 finished commands as zombies, and those of a directory that receives no more commands are not reaped until a cleanup sweep, which only forgets commands that ended more than 7 days ago or whose output file is gone. So the total grows with the number of directories and worktrees a long-lived server has used.
The script below reproduces it. I'm leaving this issue open as the place to track the bug, since #63817 and #63948 are closed. Restarting the server or daemon clears the zombies in the meantime, as you noted.
Reproduction script (multi-location.sh)
#!/usr/bin/env bash# Runs shell commands through one `opencode serve` (one opencode-pty daemon) in several project# directories and counts the daemon's <defunct> children after each directory.# Usage: OPENCODE="opencode" ./multi-location.sh (DIRS=4 PER_DIR=30 by default)set -u
OPENCODE=${OPENCODE:-opencode}
DIRS=${DIRS:-4}; PER_DIR=${PER_DIR:-30}; PORT=${PORT:-4199}
ROOT=$(mktemp -d /tmp/opencode/zombies.XXXX)export HOME=$ROOT/home XDG_DATA_HOME=$ROOT/home/.local/share XDG_STATE_HOME=$ROOT/home/.local/state XDG_CACHE_HOME=$ROOT/home/.cache XDG_CONFIG_HOME=$ROOT/home/.config
mkdir -p "$HOME"export OPENCODE_SERVER_PASSWORD=repro-pass
AUTH="opencode:repro-pass"$OPENCODE --version
cd"$ROOT";$OPENCODE serve --hostname 127.0.0.1 --port $PORT>"$ROOT/serve.log"2>&1&
SERVER=$!cd - >/dev/null
foriin$(seq 60);do curl -sf -u $AUTH -o /dev/null "http://127.0.0.1:$PORT/api/shell"&&break; sleep 1;donecensus() {
fordin$(pgrep -f 'opencode-pty daemon');doif grep -q "$ROOT" /proc/$d/cmdline 2>/dev/null;thenecho"$1: daemon $d has $(ps -eo ppid,stat | awk -v p=$d'$1==p && $2 ~ /^Z/'| wc -l) zombie children"fidone
}
fornin$(seq $DIRS);do
dir=$ROOT/project$n; mkdir -p "$dir"; (cd "$dir"&& git init -q)
enc=$(python3 -c 'import urllib.parse,sys;print(urllib.parse.quote(sys.argv[1]))'"$dir")forcin$(seq $PER_DIR);do
curl -sf -u $AUTH -o /dev/null -X POST -H 'content-type: application/json' \
"http://127.0.0.1:$PORT/api/shell?location%5Bdirectory%5D=$enc" -d "{\"command\":\"echo $n-$c; ls | head -1\"}"||echo"create failed"done
sleep 3
census "after project$n ($((n*PER_DIR)) commands)"done
ps -eo pid,ppid,stat,etimes,comm | awk '$3 ~ /^Z/'| head -3
kill$SERVER;wait$SERVER2>/dev/null
The unreaped roots also enforce an ownership contract: the SPEC and pipe test deliberately retain them until terminate, reserving PID/PGID so later group signals cannot hit a reused ID. A global SIGCHLD/waitpid reaper would break that contract.
Would a daemon-wide bound on retained finished commands be acceptable? It would reduce this growth but shorten completed-command recovery across Locations/handoffs. Otherwise, finished metadata needs to be separated from ownership of a signalable process group.
Source analysis only; I haven't run this on Linux.
Chain: electron → opencode-cli serve --service → opencode-pty daemon 0.5.2-bc9cb0fa0ebb4e56
Single daemon PID, single project directory
Census under the daemon PID:
Metric
Value
Zombie children
25
opencode-pty-ac actor threads
26 (plus 4 opencode-pty, 1 each -wa, -si, -re)
SigIgn / SigCgt SIGCHLD
absent in both
Total zombie RSS
0 KB
Two samples 60 s apart, with shell commands in between: 25 → 25 zombies, oldest zombie ~24 min old, newest replaced. So on this setup it is steady-state at the 25-per-directory cap you identified, not unbounded — matching the single-directory result.
Two small additions:
The zombie names are ordinary tool-call commands (zsh, sed, grep, find, cat, ls, ps, pacman), so every shell tool call leaves exactly one, and each also pins one opencode-pty-ac actor thread that stays blocked in futex_do_wait. The thread leak is the more expensive half: ~26 threads per directory held forever.
kill -9 on a zombie does nothing, and quitting the desktop app is the only thing that clears the set (init reaps them on daemon exit) — consistent with the retain-until-terminate contract described above.
Not arguing against the PID/PGID-reservation contract; just noting that a 25-entry cap per directory still means ~26 threads and 25 PIDs per directory for the life of the daemon.
Stepping back for a moment, because both this thread and #64037 end up debating how much to retain... BUT I think the prior question is why retain at all.
The only legitimate reason for the daemon to outlive a server is keeping running commands alive across restarts. An exited command has nothing to hand off: its output is already persisted, and the child carries no data. Yet, the design retains exited children for days per Location, and, per the SPEC L184 analysis above, that retention is deliberate : the corpse is kept so its PID/PGID can't be recycled into a later group signal.
Those are two separable needs. "Don't signal a recycled PID" doesn't require holding the corpse: reap immediately and validate the signal target (starttime/pidfd), or don't keep signal targets for processes that no longer exist. What we have instead is a daemon whose lifetime is bound to nothing — it outlives sessions, server generations, and on the desktop path only dies when the whole app quits. On my box it routinely survives every session that used it; killing it is the only cleanup that exists, and opencode serve just silently respawns a fresh one (same name, zero zombies) — which neatly demonstrates the daemon belongs to the server's lifetime, not to any session.
There's also a control angle that's worse than the resource angle. Quitting a session is supposed to be the kill switch: when an agent goes sideways — spawning runaway builds or command loops — closing the session is the one recourse a user has that always works. Under the daemon model it silently doesn't. The session ends, the agent is gone, and its in-flight children keep running detached, with no client attached to watch or stop them.
So the ask, in increasing order of what I'd consider acceptable:
Correct default: session-bound teardown. No session, no opencode-pty — the daemon and everything it retains lives exactly as long as the clients using it. Exited children reaped immediately; running children adopted by a live session or terminated like any unowned process.
Bare minimum: persistence as an explicit opt-in. If a user wants their processes to survive session/server restarts, that's tmux/abduco/systemd --user semantics and should be requested per session — an explicit "detach this," not the invisible default for every shell command every user runs. Breaking the normal process/reap contract should be the exception a user chooses, never the ambient behavior everyone gets.
#64037 is reasonable containment and I'm not arguing against merging it. But a daemon-wide LRU still bakes in "retention is the default, only the bound is negotiable" — and even at 100, the kill-switch problem above remains. If the daemon model is kept long-term, the lifetime contract deserves its own look, ideally before quota-tuning hardens into the accepted shape of the fix.
Two reports, same bar: reap promptly, retain nothing. So whichever issue is retained, the expected behavior is on record twice. And a merged LRU cap of any size doesn't meet either statement.
Activity
opencodejr commentedon Nov 14, 2026
Thanks for the details. I reproduced the growth past 25 on 2.3.0, and it also happens on the latest
dev(9f1639c).Single directory: With one TUI session running 40 shell tool calls in one directory, the daemon stayed at exactly 25 zombies. That matches the earlier result in #63817.
Several directories: With one
opencode serve, and so oneopencode-pty daemon, I ran 30 commands in each of 4 project directories through the HTTP API. The daemon's zombie children went 25 → 50 → 75 → 100, one step of 25 per directory. That fits the 100 that iehgit saw.Why it grows (from the code): the limit of 25 recently finished commands is kept per directory, not per daemon. Each directory used keeps up to 25 finished commands as zombies, and those of a directory that receives no more commands are not reaped until a cleanup sweep, which only forgets commands that ended more than 7 days ago or whose output file is gone. So the total grows with the number of directories and worktrees a long-lived server has used.
The script below reproduces it. I'm leaving this issue open as the place to track the bug, since #63817 and #63948 are closed. Restarting the server or daemon clears the zombies in the meantime, as you noted.
Reproduction script (multi-location.sh)
Run it:
bash multi-location.shr266-tech commentedon Nov 15, 2026
The unreaped roots also enforce an ownership contract: the SPEC and pipe test deliberately retain them until
terminate, reserving PID/PGID so later group signals cannot hit a reused ID. A global SIGCHLD/waitpidreaper would break that contract.The 25-entry eviction is Location-scoped; global cleanup only forgets old/missing outputs. #62342 targets different, non-persistent PTYs.
Would a daemon-wide bound on retained finished commands be acceptable? It would reduce this growth but shorten completed-command recovery across Locations/handoffs. Otherwise, finished metadata needs to be separated from ownership of a signalable process group.
Source analysis only; I haven't run this on Linux.
vamps-goes-coding commentedon Nov 15, 2026
Confirming from the desktop app path, which I don't see covered yet.
opencode-desktop-bin 2.3.0-1(Electron 44), XFCE/X11, Arch Linux, kernel6.18.63-3-lts, zshelectron→opencode-cli serve --service→opencode-ptydaemon0.5.2-bc9cb0fa0ebb4e56Census under the daemon PID:
opencode-pty-acactor threadsopencode-pty, 1 each-wa,-si,-re)SigIgn/SigCgtSIGCHLDTwo samples 60 s apart, with shell commands in between: 25 → 25 zombies, oldest zombie ~24 min old, newest replaced. So on this setup it is steady-state at the 25-per-directory cap you identified, not unbounded — matching the single-directory result.
Two small additions:
zsh,sed,grep,find,cat,ls,ps,pacman), so every shell tool call leaves exactly one, and each also pins oneopencode-pty-acactor thread that stays blocked infutex_do_wait. The thread leak is the more expensive half: ~26 threads per directory held forever.kill -9on a zombie does nothing, and quitting the desktop app is the only thing that clears the set (init reaps them on daemon exit) — consistent with the retain-until-terminatecontract described above.Not arguing against the PID/PGID-reservation contract; just noting that a 25-entry cap per directory still means ~26 threads and 25 PIDs per directory for the life of the daemon.
jwitmann commentedon Nov 16, 2026
Stepping back for a moment, because both this thread and #64037 end up debating how much to retain... BUT I think the prior question is why retain at all.
The only legitimate reason for the daemon to outlive a server is keeping running commands alive across restarts. An exited command has nothing to hand off: its output is already persisted, and the child carries no data. Yet, the design retains exited children for days per Location, and, per the SPEC L184 analysis above, that retention is deliberate : the corpse is kept so its PID/PGID can't be recycled into a later group signal.
Those are two separable needs. "Don't signal a recycled PID" doesn't require holding the corpse: reap immediately and validate the signal target (starttime/pidfd), or don't keep signal targets for processes that no longer exist. What we have instead is a daemon whose lifetime is bound to nothing — it outlives sessions, server generations, and on the desktop path only dies when the whole app quits. On my box it routinely survives every session that used it; killing it is the only cleanup that exists, and opencode serve just silently respawns a fresh one (same name, zero zombies) — which neatly demonstrates the daemon belongs to the server's lifetime, not to any session.
There's also a control angle that's worse than the resource angle. Quitting a session is supposed to be the kill switch: when an agent goes sideways — spawning runaway builds or command loops — closing the session is the one recourse a user has that always works. Under the daemon model it silently doesn't. The session ends, the agent is gone, and its in-flight children keep running detached, with no client attached to watch or stop them.
So the ask, in increasing order of what I'd consider acceptable:
Correct default: session-bound teardown. No session, no opencode-pty — the daemon and everything it retains lives exactly as long as the clients using it. Exited children reaped immediately; running children adopted by a live session or terminated like any unowned process.
Bare minimum: persistence as an explicit opt-in. If a user wants their processes to survive session/server restarts, that's tmux/abduco/systemd --user semantics and should be requested per session — an explicit "detach this," not the invisible default for every shell command every user runs. Breaking the normal process/reap contract should be the exception a user chooses, never the ambient behavior everyone gets.
#64037 is reasonable containment and I'm not arguing against merging it. But a daemon-wide LRU still bakes in "retention is the default, only the bound is negotiable" — and even at 100, the kill-switch problem above remains. If the daemon model is kept long-term, the lifetime contract deserves its own look, ideally before quota-tuning hardens into the accepted shape of the fix.
jwitmann commentedon Nov 16, 2026
#63817 was reopened on Nov 15, so this is now one of two open issues on the same bug.
Worth noting both "Expected" sections ask for the same thing:
Two reports, same bar: reap promptly, retain nothing. So whichever issue is retained, the expected behavior is on record twice. And a merged LRU cap of any size doesn't meet either statement.