Skip to content

fix(gateway): detect launchd service for restart#19940

Open
hteo1337 wants to merge 1 commit into
NousResearch:mainfrom
hteo1337:fix/launchd-restart-service-detection
Open

fix(gateway): detect launchd service for restart#19940
hteo1337 wants to merge 1 commit into
NousResearch:mainfrom
hteo1337:fix/launchd-restart-service-detection

Conversation

@hteo1337

@hteo1337 hteo1337 commented May 4, 2026

Copy link
Copy Markdown

What does this PR do?

Detects launchd-managed Hermes gateways when handling /restart from the gateway. launchd sets XPC_SERVICE_NAME=ai.hermes.gateway, not INVOCATION_ID, so the previous check only recognized systemd. On macOS this could send /restart down the detached restart path, exit cleanly, and leave launchd configured with KeepAlive SuccessfulExit=false without a respawn.

The fix treats XPC_SERVICE_NAME == "ai.hermes.gateway" as service-managed and uses the existing service restart path (detached=False, via_service=True).

Related Issue

Related to #11932 and the broader launchd restart reliability work, but this is a separate /restart service-detection path.

Type of Change

  • 🐛 Bug fix (non-breaking change that fixes an issue)
  • ✨ New feature (non-breaking change that adds functionality)
  • 🔒 Security fix
  • 📝 Documentation update
  • ✅ Tests (adding or improving test coverage)
  • ♻️ Refactor (no behavior change)
  • 🎯 New skill (bundled or hub)

Changes Made

  • gateway/run.py
    • Include launchd's XPC_SERVICE_NAME=ai.hermes.gateway in the service-manager detection used by /restart.
    • Clarify the service-supervision comment for both systemd and launchd behavior.
  • tests/gateway/test_restart_drain.py
    • Clear XPC_SERVICE_NAME in the non-service restart test.
    • Add launchd coverage verifying /restart calls request_restart(detached=False, via_service=True).

How to Test

  1. Run the targeted restart-drain test file:
    python -m pytest tests/gateway/test_restart_drain.py -o 'addopts=' -q
  2. Confirm the launchd regression test passes:
    • test_restart_command_under_launchd_uses_service_restart

Checklist

Code

  • I've read the Contributing Guide
  • My commit messages follow Conventional Commits (fix(scope):, feat(scope):, etc.)
  • I searched for existing PRs to make sure this isn't a duplicate
  • My PR contains only changes related to this fix/feature (no unrelated commits)
  • I've run pytest tests/ -q and all tests pass
  • I've added tests for my changes (required for bug fixes, strongly encouraged for features)
  • I've tested on my platform: Ubuntu 24.04 / WSL2

Documentation & Housekeeping

  • I've updated relevant documentation (README, docs/, docstrings) — or N/A
  • I've updated cli-config.yaml.example if I added/changed config keys — or N/A
  • I've updated CONTRIBUTING.md or AGENTS.md if I changed architecture or workflows — or N/A
  • I've considered cross-platform impact (Windows, macOS) per the compatibility guide — or N/A
  • I've updated tool descriptions/schemas if I changed tool behavior — or N/A

Screenshots / Logs

$ python -m pytest tests/gateway/test_restart_drain.py -o 'addopts=' -q
...............                                                          [100%]
15 passed in 1.46s

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

Labels

comp/gateway Gateway runner, session dispatch, delivery P2 Medium — degraded but workaround exists type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants