Skip to content

fix(tools): catch pkill/killall targeting hermes/gateway/cli.py process#3402

Closed
JasonOA888 wants to merge 1 commit into
NousResearch:mainfrom
JasonOA888:fix/issue-3397-self-termination-pkill
Closed

fix(tools): catch pkill/killall targeting hermes/gateway/cli.py process#3402
JasonOA888 wants to merge 1 commit into
NousResearch:mainfrom
JasonOA888:fix/issue-3397-self-termination-pkill

Conversation

@JasonOA888

Copy link
Copy Markdown
Contributor

Fixes #3397

Problem

The agent can self-terminate by running pkill -f "cli.py --gateway",
which kills the gateway process from within itself.
This variant of #2617 but but uses process-name targeting instead of a known PID.

The existing DANGEROUS_PATTERNS catch pkill -9 (force kill) but not pkill -f (filter by name pattern). Any pkill/killall targeting hermes, gateway, or cli.py bypasses all guards.

Fix

Add a pattern that catches pkill/killall commands targeting hermes/gateway/cli.py processes:

(r'\b(pkill|killall)\b.*\b(hermes|gateway|cli\.py)\b', "kill hermes/gateway process (self-termination)"),

This reuses the existing approval flow — in gateway mode it sends an approval request, to the user, in CLI mode it prompts interactively.

Note: placed immediately after the existing pkill -9 pattern to ensure all pkill variants (with or without flags) are caught.

Testing

Verified against the cases from the bug report:

  • pkill -f "cli.py --gateway" → caught (pkill + cli.py)
  • pkill hermes → caught
  • killall gateway → caught
  • killall cli.py → caught
  • echo gateway → not caught
  • ps aux | grep hermes → not caught (no pkill/killall)

The allows pkill/killall commands that target hermes, gateway, or cli.py
processes to be caught by the DANGEROUS_PATTERNS approval system.

Fixes NousResearch#3397

The issue reported that running \`pkill -f \"cli.py --gateway\"\`
from within a Telegram gateway killed the hermes-agent.
The existing \`pkill -9` pattern only catches SIGKILL (signal 9),
but \`pkill -f\` (filter by name) bypasses all guards.

The new pattern catches:
- pkill/killall with hermes/gateway/cli.py in the arguments
- Works for pkill, pkill -f, killall, killall -r, etc.

Example commands now caught:
  pkill -f \"cli.py --gateway\"  -> blocked
  pkill hermes                       -> blocked
  killall gateway                    -> blocked
  pkill -f hermes-agent           -> blocked

Safe (not over-matching):
  pkill -f some_unrelated       -> not matched
  echo gateway                    -> not matched
  kill 12345                      -> not matched (caught by existing kill -9 pattern)
@teknium1

Copy link
Copy Markdown
Contributor

Duplicate of #3400, merged via #3593. Thanks @JasonOA888!

@teknium1 teknium1 closed this Mar 28, 2026
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]: agent self-terminates via pkill -f "cli.py --gateway" — not caught by DANGEROUS_PATTERNS

3 participants