fix(gateway): handle planned service stops (salvage of #19876)#19936
Merged
Conversation
This was referenced May 4, 2026
1 task
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Salvage of #19876 onto current main.
Adds a short-lived
.gateway-planned-stop.jsonmarker so deliberate stop paths (hermes gateway stop, systemd stop, launchd stop, profile-scoped stop) and foreground Ctrl+C can be distinguished from an unexpected external SIGTERM. On a planned stop the gateway exits code 0 so service managers (most notably launchdKeepAlive, and--replacetakeover races) don't immediately revive it with stale platform identities (Feishuapp_id, Telegram getUpdates, etc.).Follows the existing
--replacetakeover-marker pattern — factored into a shared_consume_pid_marker_for_self()helper ingateway/status.py.Note: this closes the revival / identity-conflict class, but does NOT fix slow drains on wedged adapter sockets (e.g. WSL with a hung Feishu websocket). That's the separate drain-hang issue tracked in a follow-up.
Changes
gateway/status.py:write_planned_stop_marker(),consume_planned_stop_marker_for_self(),clear_planned_stop_marker(); shared_consume_pid_marker_for_self()helperhermes_cli/gateway.py:stop_profile_gateway(),systemd_stop(),launchd_stop()write the marker before SIGTERMgateway/run.py: signal handler consumes the marker, treats SIGINT as a planned foreground stop, exits cleanlytests/gateway/test_status.py+tests/hermes_cli/test_gateway_service.py: marker + systemd_stop wiring coverage, deterministicTimeoutStopSecassertionsValidation
py_compileall three modified modules: cleanscripts/run_tests.sh tests/gateway/test_status.py tests/hermes_cli/test_gateway_service.py tests/gateway/test_clean_shutdown_marker.py tests/gateway/test_runner_startup_failures.py: 171 passedCredit to @helix4u — cherry-picked with authorship preserved. Closes #19876.