Skip to content

fix(gateway): replace deprecated launchctl start/stop with kickstart/kill#4892

Closed
tmchow wants to merge 2 commits into
NousResearch:mainfrom
tmchow:fix/4820-launchd-kickstart-kill
Closed

fix(gateway): replace deprecated launchctl start/stop with kickstart/kill#4892
tmchow wants to merge 2 commits into
NousResearch:mainfrom
tmchow:fix/4820-launchd-kickstart-kill

Conversation

@tmchow

@tmchow tmchow commented Apr 3, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

Replaces all deprecated launchctl subcommands in hermes_cli/gateway.py with their modern equivalents. On current macOS, launchctl start and launchctl stop silently fail (printing "Not privileged to start service" and exiting 0), which means hermes gateway start reports success while the gateway never actually starts.

The migration:

Old (deprecated) New
launchctl load <plist> launchctl bootstrap gui/<uid> <plist>
launchctl unload <plist> launchctl bootout gui/<uid>/<label>
launchctl start <label> launchctl kickstart gui/<uid>/<label>
launchctl stop <label> launchctl kill SIGTERM gui/<uid>/<label>

Additionally, launchd_restart() now uses launchctl kickstart -k for an atomic kill+restart instead of a two-step stop/start. This fixes the case where the gateway triggers a restart from inside its own process tree (e.g. via Telegram). The old approach killed the shell before the start command was reached, leaving the gateway stranded offline. Credit to @boobutler for the detailed analysis that surfaced this.

Related Issue

Fixes #4820

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

  • hermes_cli/gateway.py: Added _launchd_domain() helper (returns gui/<uid> target domain). Updated refresh_launchd_plist_if_needed(), launchd_install(), launchd_uninstall(), launchd_start(), and launchd_stop() to use bootstrap/bootout/kickstart/kill instead of load/unload/start/stop. Replaced the two-step launchd_restart() with a single launchctl kickstart -k call.
  • tests/hermes_cli/test_gateway_service.py: Updated test assertions for the repair path and start-retry path to match the new command signatures.

launchctl list calls (in status.py, main.py) are unchanged, they're not deprecated.

How to Test

  1. On macOS, run hermes gateway start and verify the gateway actually starts (check with hermes gateway status)
  2. Run hermes gateway stop and confirm it stops
  3. Run hermes gateway restart and confirm it cycles correctly
  4. Trigger a restart from inside a Telegram conversation and confirm the gateway comes back
  5. Run pytest tests/hermes_cli/test_gateway_service.py -q (40 tests pass)

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: macOS 15 (Darwin 25.3.0)

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

This contribution was developed with AI assistance (Codex).

Compound Engineering

…kill

launchctl load/unload/start/stop are deprecated on macOS since 10.10
and fail silently on modern versions. This replaces them with the
current equivalents:

- load -> bootstrap gui/<uid> <plist>
- unload -> bootout gui/<uid>/<label>
- start -> kickstart gui/<uid>/<label>
- stop -> kill SIGTERM gui/<uid>/<label>

Adds _launchd_domain() helper returning the gui/<uid> target domain.
Updates test assertions to match the new command signatures.

Fixes NousResearch#4820
Replace the two-step stop/start restart with a single
launchctl kickstart -k call. When the gateway triggers a
restart from inside its own process tree, the old stop
command kills the shell before the start half is reached.
kickstart -k lets launchd handle the kill+restart atomically.
@tmchow

tmchow commented Apr 5, 2026

Copy link
Copy Markdown
Contributor Author

Updated based on @boobutler's analysis. The restart path now uses launchctl kickstart -k for an atomic kill+restart instead of the two-step stop/start that gets stranded when invoked from inside the gateway's own process tree.

The two other items @boobutler raised (approval.py guard for launchctl self-targeting commands, and the python-dotenv import failure in scripts/hermes-gateway) are separate from this PR's scope but worth tracking as follow-ups.

teknium1 added a commit that referenced this pull request Apr 5, 2026
- Fix GatewayApp → GatewayRunner import in api_server.py (PR #4976)
- Update launchd test assertions for new bootstrap/bootout/kickstart commands (PR #4892)
- Add nonlocal message declaration in run_sync() to fix UnboundLocalError (pre-existing scoping bug)
teknium1 added a commit that referenced this pull request Apr 5, 2026
- Fix GatewayApp → GatewayRunner import in api_server.py (PR #4976)
- Update launchd test assertions for new bootstrap/bootout/kickstart commands (PR #4892)
- Add nonlocal message declaration in run_sync() to fix UnboundLocalError (pre-existing scoping bug)
@teknium1

teknium1 commented Apr 5, 2026

Copy link
Copy Markdown
Contributor

Merged via PR #5288 (consolidated bugfix salvage). Your commit(s) were cherry-picked onto current main with your authorship preserved in git log. Thanks @tmchow for the fix!

@teknium1 teknium1 closed this Apr 5, 2026
Tommyeds pushed a commit to Tommyeds/hermes-agent that referenced this pull request Apr 12, 2026
- Fix GatewayApp → GatewayRunner import in api_server.py (PR NousResearch#4976)
- Update launchd test assertions for new bootstrap/bootout/kickstart commands (PR NousResearch#4892)
- Add nonlocal message declaration in run_sync() to fix UnboundLocalError (pre-existing scoping bug)
angelburgosrosado pushed a commit to angelburgosrosado/hermes-agent that referenced this pull request Apr 27, 2026
- Fix GatewayApp → GatewayRunner import in api_server.py (PR NousResearch#4976)
- Update launchd test assertions for new bootstrap/bootout/kickstart commands (PR NousResearch#4892)
- Add nonlocal message declaration in run_sync() to fix UnboundLocalError (pre-existing scoping bug)
angelburgosrosado pushed a commit to angelburgosrosado/hermes-agent that referenced this pull request Apr 28, 2026
- Fix GatewayApp → GatewayRunner import in api_server.py (PR NousResearch#4976)
- Update launchd test assertions for new bootstrap/bootout/kickstart commands (PR NousResearch#4892)
- Add nonlocal message declaration in run_sync() to fix UnboundLocalError (pre-existing scoping bug)
02356abc pushed a commit to 02356abc/hermes-agent that referenced this pull request May 14, 2026
- Fix GatewayApp → GatewayRunner import in api_server.py (PR NousResearch#4976)
- Update launchd test assertions for new bootstrap/bootout/kickstart commands (PR NousResearch#4892)
- Add nonlocal message declaration in run_sync() to fix UnboundLocalError (pre-existing scoping bug)
olympus-terminal pushed a commit to olympus-terminal/hermes-agent that referenced this pull request May 16, 2026
- Fix GatewayApp → GatewayRunner import in api_server.py (PR NousResearch#4976)
- Update launchd test assertions for new bootstrap/bootout/kickstart commands (PR NousResearch#4892)
- Add nonlocal message declaration in run_sync() to fix UnboundLocalError (pre-existing scoping bug)
gweeteve pushed a commit to gweeteve/hermes-agent that referenced this pull request Jun 2, 2026
- Fix GatewayApp → GatewayRunner import in api_server.py (PR NousResearch#4976)
- Update launchd test assertions for new bootstrap/bootout/kickstart commands (PR NousResearch#4892)
- Add nonlocal message declaration in run_sync() to fix UnboundLocalError (pre-existing scoping bug)
Egavasyug pushed a commit to Egavasyug/hermes-agent that referenced this pull request Jun 10, 2026
- Fix GatewayApp → GatewayRunner import in api_server.py (PR NousResearch#4976)
- Update launchd test assertions for new bootstrap/bootout/kickstart commands (PR NousResearch#4892)
- Add nonlocal message declaration in run_sync() to fix UnboundLocalError (pre-existing scoping bug)
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.

fix(launchd): use kickstart/kill instead of deprecated start/stop on macOS

2 participants