Skip to content

fix(gateway): harden macOS PID detection - #12849

Closed
BrennerSpear wants to merge 1 commit into
NousResearch:mainfrom
BrennerSpear:fix/macos-gateway-pid-detection
Closed

fix(gateway): harden macOS PID detection#12849
BrennerSpear wants to merge 1 commit into
NousResearch:mainfrom
BrennerSpear:fix/macos-gateway-pid-detection

Conversation

@BrennerSpear

Copy link
Copy Markdown
Contributor

Summary

This hardens macOS gateway PID discovery so Hermes stops producing false negatives when a launchd-managed gateway is alive.

Specifically, this PR:

  • parses both legacy tabular and newer plist-style launchctl list <label> output in _get_service_pids()
  • uses macOS-safe ps arguments for manual gateway process discovery while preserving the existing non-macOS path
  • adds regression coverage for plist-style launchctl output and the macOS process-scan path
  • updates an existing PID-file fallback test to match the macOS-safe ps invocation

Problem

On the affected macOS install, these commands disagreed:

  • hermes gateway status
  • hermes cron status

launchctl showed the gateway loaded and running with a real PID, but find_gateway_pids() returned no processes, so hermes cron status incorrectly claimed the gateway was not running.

Root cause

There were two macOS-specific detection bugs:

  1. _get_service_pids() only understood older tabular launchctl list <label> output, but newer macOS returns plist-style output like:

    {
        "Label" = "ai.hermes.gateway";
        "PID" = 7817;
    };
    
  2. _scan_gateway_pids() used ps -A eww -o pid=,command= for every non-Windows platform. That works on Linux, but the macOS ps on the repro machine rejects that invocation.

What changed

launchd PID parsing

Added _parse_launchctl_pid() and used it from _get_service_pids() so Hermes now accepts both:

  • legacy tabular launchctl list output
  • plist-style launchctl list output from newer macOS

macOS-safe process scanning

_scan_gateway_pids() now chooses:

  • macOS: ps -A -ww -o pid=,command=
  • non-macOS: existing ps -A eww -o pid=,command= path

Tests

Run locally:

  • pytest tests/hermes_cli/test_gateway.py tests/hermes_cli/test_update_gateway_restart.py -q

Result:

  • 61 passed

Notes

I found two existing open PRs in similar territory (#11293 and #10636). I'm opening this because I reproduced the bug locally against a live macOS launchd install, implemented the fix against current main, and validated it in the current test layout.

@BrennerSpear

Copy link
Copy Markdown
Contributor Author

Closing this as a duplicate of #11293.

I compared the overlapping PRs after opening this and #11293 is the best existing upstream thread for this bug: same root cause, narrower scope, and good regression coverage. I left a supporting comment there with the local macOS repro details from my install.

Keeping discussion and maintainer attention on that PR.

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.

1 participant