fix(tui/pty): reap leaked slash_worker subprocesses on PTY chat disconnect#42132
Merged
Conversation
…tchdog Daemon thread polls _is_orphaned (original ppid check + psutil create_time PID-reuse guard, no PR_SET_PDEATHSIG). On orphan, drains an in-flight command up to a grace window then os._exit(0). Started before the HermesCLI build to cover the spawn window. Task: swl-qrf.8
Contributor
🔎 Lint report:
|
| Rule | Count |
|---|---|
unresolved-import |
2 |
First entries
tui_gateway/slash_worker.py:15: [unresolved-import] unresolved-import: Cannot resolve imported module `psutil`
tests/test_slash_worker_watchdog.py:1: [unresolved-import] unresolved-import: Cannot resolve imported module `psutil`
✅ Fixed issues: none
Unchanged: 5430 pre-existing issues carried over.
Diagnostics are surfaced as warnings — this check never fails the build.
This was referenced Jun 8, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Dashboard
/chatPTY disconnects no longer leaktui_gateway.slash_workersubprocesses. Two independent, cheap guards close the leak for both Linux and macOS.Root cause:
/api/ptyspawnshermes --tui, which spawns its owntui_gateway, which spawns_SlashWorkergrandchildren.ptyprocessmakes the PTY child a session leader (setsid()), butPtyBridge.close()only signalled the single leader PID — so the grandchild slash workers never received SIGHUP/TERM/KILL and orphaned on every refresh / proxy drop. The in-process orphan reaper (#38591) only covers the dashboard's own gateway sessions, not this subprocess tree.Changes
hermes_cli/pty_bridge.py:close()nowos.killpg(os.getpgid(pid), sig)over the whole PTY process group (falls back to single-PID kill when the group is unknown). Reaps grandchild helpers. (@paulb26, fix(pty-bridge): terminate PTY process groups on teardown #24135)tui_gateway/slash_worker.py: daemon watchdog self-terminates the worker on parent death —getppid()change +psutilcreate_timePID-reuse guard, started before the HermesCLI build to cover the spawn window, drains an in-flight command up to a grace window beforeos._exit(0). Cross-platform (noPR_SET_PDEATHSIG, so it works on macOS too). (@firefly, fix(tui-gateway): reap leaked slash_worker processes/fds on disconnect, create-race, and parent-death #35626)scripts/release.py: AUTHOR_MAP entry for @paulb26.Validation
close()tests/hermes_cli/test_pty_bridge.py+tests/test_slash_worker_watchdog.py→ 23 passed.bridge.close(); real orphaned watchdog process self-terminated after parent exit.Closes #32377. Salvaged from #24135 (@paulb26) and #35626 (@banditburai/firefly); supersedes the slash-worker-leak PR cluster.
Infographic