Skip to content

pty: opencode-pty daemon leaks zombie shell children (never reaped) #64270

Closed as duplicate

Description

@lidaobing

Title

pty: opencode-pty daemon leaks zombie shell children (never reaped)

Body

Summary

The opencode-pty daemon that executes shell-tool commands never reaps its
finished children, so every shell command leaves a zombie process. The daemon
is long-lived and shared across sessions, so the zombies accumulate without
bound (~150 observed after ~3 days of normal use).

Environment

  • opencode version: v2.3.0
  • OS: Ubuntu 24.04, Linux 7.0.0-42-generic x86_64
  • Terminal: VS Code (TERM_PROGRAM=vscode, TERM=xterm-256color, COLORTERM=truecolor)
  • Shell: /bin/bash
  • Install/channel: latest
  • Active plugins: none found in config

Reproduction

  1. Start an opencode session and run a few shell-tool commands (ls,
    git status, a pipeline like make ... | tail, etc.).
  2. After each command finishes, run:
    ps -eo stat,ppid,pid,cmd | awk '$1 ~ /^Z/'
  3. Every finished command is still listed as <defunct> with the
    opencode-pty daemon PID as parent, and stays there.

Expected Behavior

Finished shell commands are reaped by the pty daemon; no zombie processes
accumulate over time.

Actual Behavior

Zombies accumulate indefinitely. After ~3 days of use with a shared daemon:

$ ps -eo stat,ppid,pid,cmd | awk '$1 ~ /^Z/ {print $4}' | sort | uniq -c | sort -rn
    101 [bash]
     26 [sed]
     14 [git]
      5 [tail]
      1 [make]
      1 [grep]

All of them share the same parent:

  PID  PPID     ELAPSED CMD
380876  ...  2-22:25:28 ~/.cache/opencode/bin/opencode-pty/0.5.2-bc9cb0fa0ebb4e56/opencode-pty \
    daemon --runtime-dir ~/.local/state/opencode/pty --name <uuid>

The oldest zombies date back to ~2d20h, i.e. since that daemon started.
Not just the pipeline leader is affected: sed/tail/grep pipeline
children also end up parented to the daemon and are never reaped either.

Additional Context

  • Sending kill -CHLD <daemon pid> does not trigger reaping.
  • Restarting the daemon clears the zombies (they are reparented to init and
    reaped), but that is disruptive to active sessions' terminals.
  • Impact so far is only PID-slot usage, but the growth is unbounded and
    proportional to executed shell commands, so long-lived installs will hit it.
  • Reproducible consistently: each shell command reliably adds one or more
    zombies.

Activity

  1. opencodejr commented on Nov 16, 2026

    @opencodejr
    Contributor

    Thanks for the detailed report. I think this is a duplicate of #63817, which reports this leak and has been reproduced on 2.3.0.

    Possible duplicates and related issues, ordered by likelihood:

    I'm closing this issue now as a duplicate of #63817. Please add your details there; your zombie breakdown across pipeline children (sed, tail, grep) and the note that kill -CHLD doesn't trigger reaping would be useful. If you think this is a different problem, reply here and the issue will reopen.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions