Skip to content

fix(gateway): detect launchd via XPC_SERVICE_NAME for Telegram /restart path - #51112

Closed
verus-services wants to merge 1 commit into
NousResearch:mainfrom
Verus-Data:fix/telegram-restart-launchd-detection
Closed

fix(gateway): detect launchd via XPC_SERVICE_NAME for Telegram /restart path#51112
verus-services wants to merge 1 commit into
NousResearch:mainfrom
Verus-Data:fix/telegram-restart-launchd-detection

Conversation

@verus-services

Copy link
Copy Markdown

Problem

The _handle_restart_command method only checked for INVOCATION_ID (systemd) and container markers to decide whether to use the service restart path (via_service=True, exit code 75). On macOS under launchd, neither env var is set — but XPC_SERVICE_NAME is always present.

Without this detection, the Telegram /restart path falls through to via_service=False (detached subprocess), which exits with code 0. launchd's KeepAlive → SuccessfulExit → false policy treats exit(0) as 'successful, don't restart', so the gateway stays down after a Telegram /restart command.

Fix

Add _under_launchd = bool(os.environ.get('XPC_SERVICE_NAME')) and include it in the service-restart condition, matching the existing systemd convention.

Testing

Verified on macOS 25.3 (arm64): XPC_SERVICE_NAME=ai.hermes.gateway-dante is set when running under launchd. The fix ensures the Telegram /restart path uses via_service=True and exits with code 75, which launchd's SuccessfulExit → false policy correctly treats as a restart trigger.

References

…rt path

The _handle_restart_command method only checked for INVOCATION_ID
(systemd) and container markers to decide whether to use the service
restart path (via_service=True, exit code 75). On macOS under launchd,
neither env var is set — but XPC_SERVICE_NAME is always present.

Without this detection, the Telegram /restart path falls through to
via_service=False (detached subprocess), which exits with code 0.
launchd's KeepAlive → SuccessfulExit → false policy treats exit(0) as
'successful, don't restart', so the gateway stays down after a
Telegram /restart command.

Add _under_launchd = bool(os.environ.get('XPC_SERVICE_NAME')) and
include it in the service-restart condition, matching the existing
systemd convention.

Refs: commit 5987b24 (original launchd fix for SIGUSR1 path)
Closes: NousResearch#28135 (Telegram /restart path was missed)
@alt-glitch alt-glitch added type/bug Something isn't working comp/gateway Gateway runner, session dispatch, delivery P2 Medium — degraded but workaround exists duplicate This issue or pull request already exists labels Jun 23, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Duplicate of #36816 — same launchd /restart fix via XPC_SERVICE_NAME detection routing through via_service=True (exit 75). This is a saturated cluster (earliest open #19940; also #34985, #33393, #37094; closed predecessor #38597). Maintainer to pick the canonical fix.

@teknium1

Copy link
Copy Markdown
Contributor

Thanks for the focused launchd investigation. This is already implemented on current main by a stronger follow-up.

  • abc3662bf6076045e4d4dc1e14a74cb35d69b86e (fix(gateway): detect launchd in /restart service-manager probe (#43475)) moved with the handler to gateway/slash_commands.py and routes a launchd job through request_restart(detached=False, via_service=True) at gateway/slash_commands.py:1302-1307.
  • The merged probe deliberately treats XPC_SERVICE_NAME="0" as non-launchd, avoiding a regression for interactive macOS shells; the PR's bool(os.environ.get("XPC_SERVICE_NAME")) condition would classify that truthy string as launchd.
  • Current coverage in tests/gateway/test_restart_service_detection.py:46-64 verifies both the launchd and interactive-shell cases.

This is an automated hermes-sweeper review.

@teknium1 teknium1 closed this Jul 15, 2026
@teknium1 teknium1 added the sweeper:implemented-on-main Sweeper: behavior already present on current main label Jul 15, 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.

hermes update via gateway leaves launchd service unrestarted on macOS

3 participants