[PR #5876] fix(pty): use proper process tree cleanup on disposal #11628

Open
opened 2026-02-16 18:16:31 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/5876

State: open
Merged: No


Summary

  • Add killPtyTree() helper for proper PTY process tree cleanup
  • Use Promise.all() for parallel session cleanup on disposal

Problem

PTY disposal was using process.kill() directly which:

  • Only sends SIGTERM without SIGKILL escalation
  • Doesn't kill child processes spawned by the shell
  • Doesn't handle Windows process trees

Solution

Added killPtyTree() helper (based on Shell.killTree pattern) that:

  • Kills the process group (-pid) on Unix
  • Escalates to SIGKILL after 200ms if needed
  • Uses taskkill /t on Windows for tree kill
  • Properly catches errors for already-exited processes

Related: #3057, #5525

**Original Pull Request:** https://github.com/anomalyco/opencode/pull/5876 **State:** open **Merged:** No --- ## Summary - Add `killPtyTree()` helper for proper PTY process tree cleanup - Use `Promise.all()` for parallel session cleanup on disposal ## Problem PTY disposal was using `process.kill()` directly which: - Only sends SIGTERM without SIGKILL escalation - Doesn't kill child processes spawned by the shell - Doesn't handle Windows process trees ## Solution Added `killPtyTree()` helper (based on `Shell.killTree` pattern) that: - Kills the process group (`-pid`) on Unix - Escalates to SIGKILL after 200ms if needed - Uses `taskkill /t` on Windows for tree kill - Properly catches errors for already-exited processes Related: #3057, #5525
yindo added the pull-request label 2026-02-16 18:16:31 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#11628