Skip to content

fix: use ps without environment for gateway scan#9100

Open
corazzione wants to merge 1 commit into
NousResearch:mainfrom
corazzione:fix-freebsd-gateway-ps-command
Open

fix: use ps without environment for gateway scan#9100
corazzione wants to merge 1 commit into
NousResearch:mainfrom
corazzione:fix-freebsd-gateway-ps-command

Conversation

@corazzione

Copy link
Copy Markdown
Contributor

Summary

  • Use ps ww for Unix gateway process discovery so the command column does not include environment variables.
  • Add a regression test covering the expected process scan command.

Root cause

On FreeBSD, ps eww -ax -o pid=,command= prefixes the command column with the process environment. That can prevent the gateway command patterns from matching reliably, so hermes cron list and hermes cron status may warn that the gateway is not running even when it is active.

Changes

  • Removed the e flag from the Unix ps invocation while keeping wide output.
  • Added focused coverage for Unix process scanning.

Validation

  • python -m pytest tests/hermes_cli/test_update_gateway_restart.py::TestFindGatewayPidsExclude::test_unix_process_scan_does_not_include_environment -q -n0 (failed before the code change, passed after)
  • python -m pytest tests/hermes_cli/test_update_gateway_restart.py::TestFindGatewayPidsExclude -q -n0
  • python -m py_compile hermes_cli/gateway.py tests/hermes_cli/test_update_gateway_restart.py
  • git diff --check

I also ran python -m pytest tests/hermes_cli/test_update_gateway_restart.py -q -n0; unrelated Windows-local failures remain in existing launchd/POSIX PATH tests.

Fixes #9069

@xpader

xpader commented Apr 13, 2026

Copy link
Copy Markdown

Using ps www -ax -o pid,command | tail -n +2 on FreeBDS is same as ps eww -ax -o pid=,command= on linux.

@corazzione corazzione marked this pull request as ready for review April 13, 2026 16:25
IISweetHeartII added a commit to IISweetHeartII/hermes-agent that referenced this pull request Apr 16, 2026
Two issues prevent `find_gateway_pids()` from detecting the running
gateway process on macOS, causing `hermes cron status` to falsely
report "Gateway is not running" even when the process is alive and
healthy.

**1. `launchctl list <label>` output format mismatch**

Modern macOS (12+) returns a property-list dictionary format:

    "PID" = 12345;

The existing parser expected the legacy tabular format:

    PID	Status	Label

Added regex-based extraction for the modern dict format with a
fallback to the legacy tabular parser.

Refs: NousResearch#4820

**2. `ps` flag argument splitting**

`subprocess.run(["ps", "-A", "eww", ...])` passes `eww` as a
separate argument, which BSD `ps` interprets as a process name
filter rather than flags. This returns ~5 results instead of the
full process list (~400+), causing pattern matching to miss the
gateway process.

Fixed by combining flags: `["ps", "-Aeww", ...]`

Refs: NousResearch#9069, NousResearch#9100

Tested on macOS 15.4 (Sequoia) with launchd-managed gateway.
Before: `hermes cron status` → "Gateway is not running"
After: `hermes cron status` → "Gateway is running — PID: <pid>"
@alt-glitch alt-glitch added type/bug Something isn't working P3 Low — cosmetic, nice to have comp/cli CLI entry point, hermes_cli/, setup wizard labels Apr 27, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Competing PR with #9396 — both fix FreeBSD gateway process detection (ps env prefix issue, #9069). One should be closed in favor of the other.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/cli CLI entry point, hermes_cli/, setup wizard P3 Low — cosmetic, nice to have type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

3 participants