Repository navigation
Description
Zombie process leak: opencode-pty daemon never reaps exited child processes
Summary
The opencode-pty daemon (opencode-pty daemon --runtime-dir ... --name ...) spawns one child process per terminal command but never reaps exited children via waitpid/waitid. Zombies ([defunct]) accumulate for the entire lifetime of the daemon and are never cleaned up. In the observed session, 79 of 81 direct children are zombies, with ages ranging from ~17 seconds up to ~11 hours.
Version
- OpenCode CLI:
opencode v2.3.0 opencode-ptybinary:/root/.cache/opencode/bin/opencode-pty/0.5.2-bc9cb0fa0ebb4e56/opencode-pty(stripped Rust ELF x86-64)opencode-ptybuild hash:0.5.2-bc9cb0fa0ebb4e56- Binary references
nix-0.28.0(from/home/runner/.cargo/registry/src/index.crates.io-.../nix-0.28.0/...path strings)
Reproduction
Run OpenCode normally and execute shell commands through the terminal/pty backend. After commands complete, inspect the daemon's children:
ps -eo pid,ppid,stat,cmd | awk '$2 == <opencode-pty PID>'Exited children remain as [defunct] zombies indefinitely instead of being reaped.
Observed state (live daemon, PID 2674)
Daemon command line:
/root/.cache/opencode/bin/opencode-pty/0.5.2-bc9cb0fa0ebb4e56/opencode-pty daemon --runtime-dir /root/.local/state/opencode/pty --name efba4ea9-dfa3-4986-abf6-1a9f04c5d03a
Parent chain:
PID 518: /root/.opencode/bin/opencode serve --service (PPid 1)
PID 2674: opencode-pty daemon (PPid 518)
PTY service metadata (/root/.local/state/opencode/pty/efba4ea9-dfa3-4986-abf6-1a9f04c5d03a/service.json):
{
"instance_id": "840ee1efacd3a6eedab631848df6cd89",
"pid": 2674,
"protocol": 8,
"socket": "/tmp/opencode-pty-0/90b6a7e4b3cee079823555713e435c10.sock",
"token": "0cf16d25161e9531b2fe1af6e6b595bd",
"features": []
}Daemon /proc/2674/status (key lines):
Name: opencode-pty
State: S (sleeping)
Tgid: 2674
PPid: 518
Threads: 97
VmPeak: 4659672 kB
VmSize: 4659672 kB
RssAnon: 72032 kB
RssFile: 3708 kB
SigPnd: 0000000000000000
SigBlk: 0000000000004002
SigIgn: 0000000000001000
SigCgt: 0000000100000440
Open file descriptors: 118 (mostly pipes and unix sockets; see fd listing below)
Direct children breakdown: 81 total, 79 zombies, 2 alive.
Zombie process census (all children of PID 2674)
| Count | Command | State |
|---|---|---|
| 59 | bash |
<defunct> |
| 8 | tmux: client |
<defunct> |
| 6 | ls |
<defunct> |
| 1 | tail |
<defunct> |
| 1 | ps |
<defunct> |
| 1 | openssl |
<defunct> |
| 1 | go |
<defunct> |
| 1 | git |
<defunct> |
| 1 | curl |
<defunct> |
| 79 | total zombies | |
| 2 | bash -c ... |
S< (alive) |
Zombie ages confirm they are never reaped
ps -eo pid,ppid,stat,etimes,cmd | awk '$2==2674 && $3 ~ /Z/' (elapsed time since exit, seconds):
- Oldest: PID 2841
[curl]— 39,849s (~11.1 hours) - PID 3015
[bash]— 39,541s (~11.0 hours) - PID 3017
[ls]— 39,541s (~11.0 hours) - ...
- Newest: PID 72227
[bash]— 17s
Zombies span the full session lifetime and grow monotonically; none are ever reaped.
Full zombie process list (PID, elapsed seconds, command)
72227 17 bash
72146 43 bash
72148 43 bash
72165 43 bash
72065 115 ps
72016 156 bash
72020 156 bash
71982 162 bash
71985 162 bash
71956 179 bash
71931 182 bash
71936 182 ls
71822 276 bash
71797 290 bash
71774 298 bash
71729 302 bash
71733 302 bash
71741 302 bash
71750 302 bash
71673 317 bash
71676 317 tmux: client
71625 335 bash
71629 335 tmux: client
71553 357 bash
71296 433 ls
71236 443 bash
21263 24385 bash
21188 24398 tail
21167 24403 bash
18956 24957 bash
18927 24961 bash
18878 24964 bash
18847 24971 bash
18772 24978 bash
18701 24984 bash
18711 24984 bash
18690 24987 bash
18664 25004 ls
18642 25025 ls
18650 25025 bash
18629 25028 ls
18578 25059 bash
18539 25073 bash
18515 25079 bash
18484 25085 bash
18459 25093 bash
18443 25099 openssl
18376 25129 bash
18354 25136 bash
18304 25153 bash
18264 25157 go
18225 25159 bash
18148 25233 bash
18048 25325 tmux: client
18037 25328 bash
18015 25337 bash
18004 25348 bash
17988 25354 tmux: client
17971 25359 tmux: client
17962 25361 tmux: client
17952 25365 tmux: client
17933 25369 tmux: client
3417 39432 bash
3368 39481 bash
3330 39486 bash
3323 39491 git
3301 39494 bash
3291 39497 bash
3280 39500 bash
3227 39505 bash
3176 39511 bash
3141 39515 bash
3110 39520 bash
3085 39528 bash
3067 39533 bash
3048 39537 bash
3015 39541 bash
3017 39541 ls
2841 39849 curl
Open file descriptors of daemon (sample, PID 2674)
0 -> /dev/null
1 -> /dev/null
2 -> /dev/null
3 -> socket:[4366100]
10 -> socket:[15003930]
11 -> socket:[15039605]
12 -> socket:[15039605]
13 -> socket:[15003923]
14 -> socket:[15003923]
15 -> pipe:[7318869]
16 -> pipe:[7350328]
17 -> pipe:[7241192]
18 -> pipe:[4597337]
19 -> pipe:[4727032]
...
100 -> pipe:[14827589]
101 -> pipe:[14824547]
...
126 -> /root/.local/share/opencode/shell/472cf5403a55b36889e43c57ade5aa2f62e77267/sh_1daa87cfb003sDdX6Pft0Lxl6V.out
127 -> /root/.local/share/opencode/shell/472cf5403a55b36889e43c57ade5aa2f62e77267/sh_1daa87cfc001gCcaBzJCXnxlYe.out
...
Shell output files are written under /root/.local/share/opencode/shell/<session>/sh_*.out.
Binary symbol strings (relevant)
The opencode-pty binary contains references to waitpid, waitid, wait4, sigwait, posix_spawnp, pidfd_spawnp, and "process has been reaped"/"terminal child waiter", confirming reaping/spawn logic exists in the codebase but is not being applied to direct daemon children:
waitid
signal
waitpid
getpid
sigwait
_exit
pidfd_getpid
pidfd_spawnp
posix_spawnp
...
terminal child waiter
process has been reaped
...
waitid() should only return the above codes
Cargo paths embedded in the binary point to nix-0.28.0, suggesting the nix crate is used for PTY/spawn/wait operations.
Environment
- OS: Debian GNU/Linux 13 (trixie)
- Kernel:
Linux box1 7.3.3-1-cachyos #1 SMP PREEMPT_DYNAMIC Sat, 07 Nov 2026 13:54:44 +0000 x86_64 GNU/Linux
Impact
- Zombies consume a PID each and accumulate indefinitely for the daemon's lifetime.
- On long-running sessions the PID leak grows without bound; on systems with default
pid_maxthis can eventually prevent spawning new processes. - Zombies cannot be killed with
SIGKILL(they are already dead). They only disappear when the parent reaps them or the parent itself exits (reparented to init).
Expected behavior
Exited child processes of the opencode-pty daemon should be reaped promptly (e.g., via SIGCHLD handling/waitid/waitpid in the event loop, or a dedicated reaper thread), so no [defunct] children remain after a command completes.
Suggested fix
Ensure every fork/posix_spawn/pidfd_spawnp performed by the opencode-pty daemon is paired with a corresponding waitpid/waitid call (or a dedicated reaper thread / SIGCHLD signal handler integrated into the async event loop) so exited children are collected promptly and no zombies leak.
Activity
opencodejr commentedon Nov 14, 2026
Thanks for the detailed report, including the full zombie list and the ages.
I think this is a duplicate of #63817, which reports the same problem on 2.3.0 with the
opencode-pty0.5.2 daemon. There, finished shell commands stay<defunct>children of the daemon, theSigCgtvalue is the same, and 2.2.7 left none.From the code I read, keeping some zombies is intentional. The daemon keeps a finished command as a zombie so its PID and process group can't be reused, and the server keeps up to 25 recently finished commands. So a small fixed number is expected. What you show is growth well beyond that under one daemon (79 zombies, the oldest about 11 hours old), which is the bug.
Possible duplicates and related issues, ordered by likelihood:
opencode-pty daemonon 2.3.0. It was closed only because its first author didn't reply. Two other users have since shown the count going past 25 under one daemon PID.I'm closing this issue now as a duplicate of #63817. Please add your details there, especially that it's one daemon PID with zombies about 11 hours old and still growing; that is exactly what was asked for there. If you think this is a different problem, reply here and this issue will reopen.