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
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