fix: block agent from self-destructing gateway via terminal (#6666) - #9895
Merged
Conversation
Add dangerous command patterns that require approval when the agent tries to run gateway lifecycle commands via the terminal tool: - hermes gateway stop/restart — kills all running agents mid-work - hermes update — pulls code and restarts the gateway - systemctl restart/stop (with optional flags like --user) These patterns fire the approval prompt so the user must explicitly approve before the agent can kill its own gateway process. In YOLO mode, the commands run without approval (by design — YOLO means the user accepts all risks). Also fixes the existing systemctl pattern to handle flags between the command and action (e.g. 'systemctl --user restart' was previously undetected because the regex expected the action immediately after 'systemctl'). Root cause: issue #6666 reported agents running 'hermes gateway restart' via terminal, killing the gateway process mid-agent-loop. The user sees the agent suddenly stop responding with no explanation. Combined with the SIGTERM auto-recovery from PR #9875, the gateway now both prevents accidental self-destruction AND recovers if it happens anyway. Test plan: - Updated test_systemctl_restart_not_flagged → test_systemctl_restart_flagged - All 119 approval tests pass - E2E verified: hermes gateway restart, hermes update, systemctl --user restart all detected; hermes gateway status, systemctl status remain safe
5 tasks
kshitijk4poor
added a commit
to kshitijk4poor/hermes-agent
that referenced
this pull request
Aug 20, 2026
…herKeys only Ghostty's Kitty disambiguate-mode implementation strips the Alt modifier from the Backspace key — Option+Backspace arrives as bare \x7f instead of the expected \x1b[27;3;127~, breaking backward-kill-word. This was a regression introduced when PR NousResearch#87630 re-added the CSI >1u Kitty protocol push for all allowlisted terminals including Ghostty. Under modifyOtherKeys mode (CSI >4;2m), Ghostty correctly sends \x1b[27;3;127~ for Option+Backspace, which the alias table in pt_input_extras already maps to (Escape, ControlH) = backward-kill-word. Fix: for Ghostty only, push just modifyOtherKeys and skip the Kitty protocol push. All other terminals (iTerm2, WezTerm, kitty, tmux, VS Code) still get the full dual-protocol push. Ghostty upstream tracking: discussion NousResearch#9560, issue NousResearch#9895 (cmd+backspace variant of the same root cause).
kshitijk4poor
added a commit
that referenced
this pull request
Aug 20, 2026
…herKeys only Ghostty's Kitty disambiguate-mode implementation strips the Alt modifier from the Backspace key — Option+Backspace arrives as bare \x7f instead of the expected \x1b[27;3;127~, breaking backward-kill-word. This was a regression introduced when PR #87630 re-added the CSI >1u Kitty protocol push for all allowlisted terminals including Ghostty. Under modifyOtherKeys mode (CSI >4;2m), Ghostty correctly sends \x1b[27;3;127~ for Option+Backspace, which the alias table in pt_input_extras already maps to (Escape, ControlH) = backward-kill-word. Fix: for Ghostty only, push just modifyOtherKeys and skip the Kitty protocol push. All other terminals (iTerm2, WezTerm, kitty, tmux, VS Code) still get the full dual-protocol push. Ghostty upstream tracking: discussion #9560, issue #9895 (cmd+backspace variant of the same root cause).
lisajlau
pushed a commit
to lisajlau/hermes-agent
that referenced
this pull request
Aug 20, 2026
…herKeys only Ghostty's Kitty disambiguate-mode implementation strips the Alt modifier from the Backspace key — Option+Backspace arrives as bare \x7f instead of the expected \x1b[27;3;127~, breaking backward-kill-word. This was a regression introduced when PR NousResearch#87630 re-added the CSI >1u Kitty protocol push for all allowlisted terminals including Ghostty. Under modifyOtherKeys mode (CSI >4;2m), Ghostty correctly sends \x1b[27;3;127~ for Option+Backspace, which the alias table in pt_input_extras already maps to (Escape, ControlH) = backward-kill-word. Fix: for Ghostty only, push just modifyOtherKeys and skip the Kitty protocol push. All other terminals (iTerm2, WezTerm, kitty, tmux, VS Code) still get the full dual-protocol push. Ghostty upstream tracking: discussion NousResearch#9560, issue NousResearch#9895 (cmd+backspace variant of the same root cause).
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
Fixes #6666 — agents running
hermes gateway restart,hermes update, orsystemctl restart hermes-gatewayvia the terminal tool kill the gateway process mid-work. Users see the agent suddenly stop responding.Changes
tools/approval.py (+8/-2):
hermes gateway stop/restartpattern — requires approvalhermes updatepattern — requires approval (triggers gateway restart)systemctlpattern to match flags between command and action:systemctl --user restartwas previously undetected because the regex expected the action immediately aftersystemctlrestartadded to the existingstop|disable|masksystemctl patterntests/tools/test_approval.py (+2/-2):
test_systemctl_restart_not_flagged→test_systemctl_restart_flagged(intentional behavior change)What gets blocked vs allowed
hermes gateway restarthermes gateway stophermes updatesystemctl restart hermes-gatewaysystemctl --user restart hermes-gatewayhermes gateway statushermes gateway setupsystemctl status hermes-gatewayIn YOLO mode, these commands still execute without approval (by design).
Test plan