Skip to content

[Bug]: hermes cron list: Gateway process detection fails on FreeBSD due to ps eww output format #9069

@xpader

Description

@xpader

Bug Description

On FreeBSD, hermes cron list and hermes cron status incorrectly report "Gateway is not running" even when the gateway is actively running and processing messages.

Steps to Reproduce

  1. Run hermes gateway run
  2. Send message to create cron job from channel
  3. Run hermes cron list, you will get schedule jobs list and Gateway is not running - jobs won't fire automatically.

Expected Behavior

No warning and error, and cron jobs are running normally.

Actual Behavior

Cron job not running and get warning message in hermes cron list.

Affected Component

Gateway (Telegram/Discord/Slack/WhatsApp), CLI (interactive chat)

Messaging Platform (if gateway-related)

No response

Operating System

FreeBSD 15.0-RELEASE-p5

Python Version

3.11.15

Hermes Version

0.8.0

Relevant Logs / Traceback

Root Cause Analysis (optional)

The function find_gateway_pids() in hermes_cli/gateway.py uses this ps command to list processes:

["ps", "eww", "-ax", "-o", "pid=,command="]

On FreeBSD, the eww flags (environment variables + unlimited width) cause the command column to be prefixed with all environment variables, in this format:

PID  COMMAND
87727 _=/home/pader/.local/bin/hermes PWD=/home/pader/.hermes RUSTUP_UPDATE_ROOT=... PATH=... /home/pader/.hermes/hermes-agent/venv/bin/python3 /home/pader/.local/bin/hermes gateway run -v (python3.11)

The parsing logic then uses split(None, 1) to split the line, expecting the PID to be the first token and the command to be the second. However, because the entire environment block comes before the actual command, the second token is _=/home/... (an env var assignment), not the executable path.
As a result, none of the gateway detection patterns match:

patterns = [
    "hermes_cli.main gateway",
    "hermes gateway",
    "gateway/run.py",
    # etc.
]

Evidence
ps eww output (broken):

87727 _=/home/pader/.local/bin/hermes PWD=/home/pader/.hermes ... /home/pader/.hermes/hermes-agent/venv/bin/python3 /home/pader/.local/bin/hermes gateway run -v (python3.11)

ps -aww output (correct):

87727 /home/pader/.hermes/hermes-agent/venv/bin/python3 /home/pader/.local/bin/hermes gateway run -v (python3.11)

The ps -aww format does not include environment variables and correctly shows the executable path, allowing pattern matching to work.

Proposed Fix (optional)

In hermes_cli/gateway.py, line ~224, change:

["ps", "eww", "-ax", "-o", "pid=,command="]

to:

["ps", "ww", "-ax", "-o", "pid=,command="]

Removing the e flag avoids including environment variables in the output, which fixes the parsing issue on FreeBSD while maintaining the unlimited width output needed for long command lines.

Are you willing to submit a PR for this?

  • I'd like to fix this myself and submit a PR

Metadata

Metadata

Assignees

No one assigned

    Labels

    type/bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions