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
Linux: terminal-agent shutdown leaves active PTY children orphaned #3147
On Linux, a browse terminal-agent restart can leave its active PTY child running after the agent exits. Repeated watchdog restarts can therefore accumulate orphaned processes and exhaust host memory.
This is a process leak, not an in-process heap leak.
Root cause
browse/src/terminal-agent.ts handled SIGTERM and SIGINT by removing state files and immediately calling process.exit(0).
That shutdown path did not enumerate or dispose active PtySession instances. The primary session index is a WeakMap, which cannot be enumerated, while sessionsById intentionally excludes legacy grants. Even if a PTY received SIGINT, the immediate process exit prevented the existing delayed SIGKILL fallback from running.
Reproduction
I reproduced this with Bun 1.4.3 using an integration test that:
starts the real terminal-agent on loopback;
grants and opens a real WebSocket PTY session;
launches a child that ignores SIGINT and SIGTERM;
sends SIGTERM to the terminal-agent;
checks whether the recorded child PID is still alive.
Before the fix, the assertion fails because the child survives. After the fix, the child is reaped before the agent exits.
Proposed fix
Maintain a strong set of active sessions solely for shutdown ownership, dispose every active session during agent cleanup, and keep the signal handler alive long enough for the existing PTY shutdown grace period and SIGKILL fallback.
Validation on Bun 1.4.3:
136 focused terminal-agent and PTY lifecycle tests pass
production TypeScript check passes
test TypeScript ratchet passes with no new diagnostics
Fixed in v1.91.106.0 (main 3e8b34d, wave PR #3209). Terminal-agent shutdown now reaps every proven member of the PTY's process group after a 3 s grace, including children that ignore SIGHUP (Linux). Adopted from #3148 by @Y4NN777.
Activity
fix(browse): reap a terminal-agent PTY's whole process group at shutd…
test(browse): scope the SIGTERM PTY-reap case to POSIX signals (#3147)
fix(browse): reap a terminal-agent PTY's whole process group at shutd…
test(browse): scope the SIGTERM PTY-reap case to POSIX signals (#3147)
fix(browse): reap a terminal-agent PTY's whole process group at shutd…
test(browse): scope the SIGTERM PTY-reap case to POSIX signals (#3147)
fix(browse): reap a terminal-agent PTY's whole process group at shutd…
test(browse): scope the SIGTERM PTY-reap case to POSIX signals (#3147)
fix(browse): reap a terminal-agent PTY's whole process group at shutd…
test(browse): scope the SIGTERM PTY-reap case to POSIX signals (#3147)
v1.91.106.0 fix: the 2026-10-15 issue wave (#3209)
capy-ai commentedon Oct 16, 2026
Fixed in v1.91.106.0 (main 3e8b34d, wave PR #3209). Terminal-agent shutdown now reaps every proven member of the PTY's process group after a 3 s grace, including children that ignore SIGHUP (Linux). Adopted from #3148 by @Y4NN777.