Skip to content

fix: block agent from self-destructing gateway via terminal (#6666) - #9895

Merged
teknium1 merged 1 commit into
mainfrom
hermes/hermes-993ae0d6
Apr 14, 2026
Merged

fix: block agent from self-destructing gateway via terminal (#6666)#9895
teknium1 merged 1 commit into
mainfrom
hermes/hermes-993ae0d6

Conversation

@teknium1

Copy link
Copy Markdown
Contributor

Summary

Fixes #6666 — agents running hermes gateway restart, hermes update, or systemctl restart hermes-gateway via the terminal tool kill the gateway process mid-work. Users see the agent suddenly stop responding.

Changes

tools/approval.py (+8/-2):

  • Added hermes gateway stop/restart pattern — requires approval
  • Added hermes update pattern — requires approval (triggers gateway restart)
  • Extended systemctl pattern to match flags between command and action: systemctl --user restart was previously undetected because the regex expected the action immediately after systemctl
  • restart added to the existing stop|disable|mask systemctl pattern

tests/tools/test_approval.py (+2/-2):

  • Updated test_systemctl_restart_not_flaggedtest_systemctl_restart_flagged (intentional behavior change)

What gets blocked vs allowed

Command Blocked? Why
hermes gateway restart ✓ Requires approval Kills running agents
hermes gateway stop ✓ Requires approval Kills running agents
hermes update ✓ Requires approval Restarts gateway
systemctl restart hermes-gateway ✓ Requires approval Kills running agents
systemctl --user restart hermes-gateway ✓ Requires approval Kills running agents
hermes gateway status Safe Read-only
hermes gateway setup Safe Configuration only
systemctl status hermes-gateway Safe Read-only

In YOLO mode, these commands still execute without approval (by design).

Test plan

  • All 119 approval tests pass
  • E2E verified pattern detection for all new commands

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
@teknium1
teknium1 merged commit 1525624 into main Apr 14, 2026
4 of 5 checks passed
@teknium1
teknium1 deleted the hermes/hermes-993ae0d6 branch April 14, 2026 22:43
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).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Gateway restart from Telegram session causes process death

1 participant