Skip to content

fix(gateway): detect launchd for restart service path - #34985

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

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

Conversation

@oddrap

@oddrap oddrap commented May 29, 2026

Copy link
Copy Markdown

Summary

  • Detect macOS launchd-managed gateway processes via XPC_SERVICE_NAME when handling /restart.
  • Route launchd-managed gateway restarts through the existing service restart path (via_service=True) instead of detached restart.
  • Add regression coverage for launchd and tighten the detached-path test to require no service manager env.

Root cause

On macOS, Hermes Gateway runs under launchd. launchd sets XPC_SERVICE_NAME, not systemd's INVOCATION_ID. Without recognizing launchd, /restart falls through to the detached restart path and can exit cleanly without launchd relaunching the gateway.

Verification

  • ./venv/bin/python -m pytest tests/gateway/test_restart_notification.py -q -o 'addopts=' → 26 passed
  • ./venv/bin/python -m py_compile gateway/run.py tests/gateway/test_restart_notification.py
  • git diff --check

Related: #29180

@alt-glitch

Copy link
Copy Markdown
Collaborator

Duplicate/competing: Competing fix in the launchd restart cluster — same XPC_SERVICE_NAME detection as #19940, #24898, #33393. More comprehensive approach in #34230/#34988. Also see merged #28341.

@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/gateway Gateway runner, session dispatch, delivery duplicate This issue or pull request already exists labels May 29, 2026
@teknium1

Copy link
Copy Markdown
Contributor

Thanks for the focused launchd restart fix. This is already implemented on current main by a later, stronger version of the same approach.

Automated hermes-sweeper review evidence:

  • gateway/slash_commands.py:1302 detects launchd through XPC_SERVICE_NAME and routes the restart through request_restart(detached=False, via_service=True).
  • The merged implementation deliberately excludes XPC_SERVICE_NAME="0", which interactive macOS shells inherit; treating it as launchd would incorrectly take the service path without a supervisor.
  • tests/gateway/test_restart_service_detection.py:46 covers both a launchd job label and the "0" interactive-shell sentinel.
  • The implementation landed in abc3662bf6076045e4d4dc1e14a74cb35d69b86e (fix(gateway): detect launchd in /restart service-manager probe (#43475)) and is contained in v2026.7.1.

This also matches the duplicate/competing-fix context noted by @alt-glitch.

@teknium1 teknium1 closed this Jul 13, 2026
@teknium1 teknium1 added the sweeper:implemented-on-main Sweeper: behavior already present on current main label Jul 13, 2026
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 duplicate This issue or pull request already exists P2 Medium — degraded but workaround exists sweeper:implemented-on-main Sweeper: behavior already present on current main type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants