fix(gateway): classify service-managed status pids - #16349
Conversation
Gateway status already includes service-owned PIDs discovered through the service manager, but when the current profile lacks its expected unit path the fallback branch labeled those PIDs as manual foreground runs. Reusing the existing service PID discovery keeps the status output accurate without changing service control behavior. Constraint: Profile-specific unit paths can be absent while a matching hermes-gateway service is still active under systemd. Rejected: Dispatch every wildcard service to systemd_status | current status helpers are scoped to get_service_name() and would misreport cross-profile units. Confidence: high Scope-risk: narrow Directive: Keep status display and service-control actions separate; this branch only corrects classification of already-discovered PIDs. Tested: pytest tests/hermes_cli/test_gateway_service.py::TestGatewaySystemServiceRouting::test_gateway_status_prefers_system_service_when_only_system_unit_exists tests/hermes_cli/test_gateway_service.py::TestGatewaySystemServiceRouting::test_gateway_status_reports_manual_process_when_service_is_stopped tests/hermes_cli/test_gateway_service.py::TestGatewaySystemServiceRouting::test_gateway_status_does_not_label_systemd_pid_manual_when_unit_file_is_profile_scoped tests/hermes_cli/test_gateway_service.py::TestGatewaySystemServiceRouting::test_gateway_status_on_termux_shows_manual_guidance -q Tested: git diff --check Not-tested: Full test file on macOS has existing systemd preflight failures unrelated to status output.
teknium1
left a comment
There was a problem hiding this comment.
Thanks for isolating the fallback classification path. The reported systemd bug remains on current main: hermes_cli/gateway.py:7038-7057 falls through when the active profile's expected unit file is absent, while find_gateway_pids() includes _get_service_pids() results at hermes_cli/gateway.py:609.
Problems
- The new
is_macos()rendering branch cannot cover a legacy/profile-mismatched launchd label:_get_service_pids()only runslaunchctl listforget_launchd_label()athermes_cli/gateway.py:143-145, which is derived from the active profile. Please add label-mismatch discovery and a test, or scope the claim to systemd. - The patch needs a small manual integration on current main:
git apply --checkapplies the main fallback hunk athermes_cli/gateway.py:7053and the test hunks, but rejects the adjacent guidance hunk.
Suggested changes
- Preserve the focused missing-unit/service-PID regression test when salvaging the systemd change.
Related PR #62195 is a different open approach in the same status-classification cluster, not evidence that this bug is fixed. This is an automated hermes-sweeper review.
| pid_text = ", ".join(map(str, managed_pids)) | ||
| if supports_systemd_services(): | ||
| print(f"✓ Gateway is running as a systemd service (PID: {pid_text})") | ||
| elif is_macos(): |
There was a problem hiding this comment.
This only renders launchd ownership after _get_service_pids() has matched the PID, but that helper queries launchctl list only for the current get_launchd_label(). A legacy/profile-mismatched launchd label therefore still falls through as manual. Please add mismatched-label discovery and coverage, or narrow this PR's claim to systemd.
Summary
hermes gateway statusfallback output when the detected gateway PID is already managed by systemd/launchdFixes #16264
Tests
pytest tests/hermes_cli/test_gateway_service.py::TestGatewaySystemServiceRouting::test_gateway_status_prefers_system_service_when_only_system_unit_exists tests/hermes_cli/test_gateway_service.py::TestGatewaySystemServiceRouting::test_gateway_status_reports_manual_process_when_service_is_stopped tests/hermes_cli/test_gateway_service.py::TestGatewaySystemServiceRouting::test_gateway_status_does_not_label_systemd_pid_manual_when_unit_file_is_profile_scoped tests/hermes_cli/test_gateway_service.py::TestGatewaySystemServiceRouting::test_gateway_status_on_termux_shows_manual_guidance -qgit diff --checkNote: running the full
tests/hermes_cli/test_gateway_service.pyfile on macOS currently hits unrelated user-systemd preflight failures in existingsystemd_start/restarttests; the status-path regression tests above pass.