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