fix(pty-bridge): terminate PTY process groups on teardown#24135
Closed
paulb26 wants to merge 1 commit into
Closed
Conversation
7b0af0d to
235895e
Compare
banditburai
added a commit
to banditburai/hermes-agent
that referenced
this pull request
Jun 1, 2026
…ousResearch#24135) close() escalated SIGHUP->SIGTERM->SIGKILL against the leader only, leaking any grandchildren it spawned (NousResearch#32377). Capture the child's pgid at construction (never the dashboard's own group) and signal the whole group via os.killpg, with a single-leader fallback when no pgid is available. Keeps the trailing proc.close(force=True) that closes the PTY master fd (the NousResearch#24775 fd-leak fix). Task: swl-qrf.10
teknium1
added a commit
that referenced
this pull request
Jun 8, 2026
Contributor
jhjaggars-hermes
pushed a commit
to jhjaggars/hermes-agent
that referenced
this pull request
Jun 8, 2026
changman
pushed a commit
to changman/hermes-agent
that referenced
this pull request
Jun 10, 2026
alt-glitch
pushed a commit
that referenced
this pull request
Jun 14, 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.
Problem statement
The dashboard chat runs the real TUI through
PtyBridge. After extended dashboard use, child helper processes such astui_gateway.slash_workercan survive chat teardown. Those orphaned helpers accumulate and eventually exhaust available PTY devices, causing new dashboard chats to fail with:Chat failed to start: out of pty devicesThis primarily affects long-running local dashboard users who open/close or reconnect chat sessions over time.
Root cause
PtyBridge.close()only sent teardown signals to the PTY leader process viaself._proc.kill(sig). The TUI can spawn helper children under the same process group, and killing only the leader does not reliably terminate those descendants. The process tree outlives the dashboard chat session, leaking PTY-backed resources.Fix approach
os.getpgid(self._proc.pid).SIGHUP, thenSIGTERM, thenSIGKILLto the full process group withos.killpg(pgid, sig).Test coverage
Added tests in
tests/hermes_cli/test_pty_bridge.py:test_close_signals_child_process_groupclose()usesos.killpg()when a process group is available and does not fall back to single-processkill().test_close_falls_back_to_single_process_signal_when_group_unknownself._proc.kill()path is still used ifos.getpgid()fails.Targeted test command:
Risk assessment
Low-to-moderate risk. The PTY bridge is already POSIX-only, and process-group teardown is the correct lifecycle boundary for an embedded terminal session. The main compatibility risk is that any child process intentionally meant to survive the dashboard TUI will now be terminated; for dashboard chat teardown, that is the desired behavior because helper descendants are session-owned. Fallback preserves the previous behavior if process-group lookup is unavailable.