fix(gateway): stop self-restart and resume replay loops - #47725
Closed
alanwilhelm wants to merge 3 commits into
Closed
fix(gateway): stop self-restart and resume replay loops#47725alanwilhelm wants to merge 3 commits into
alanwilhelm wants to merge 3 commits into
Conversation
alanwilhelm
force-pushed
the
codex/gateway-self-restart-guard
branch
from
June 17, 2026 08:02
e6e8be8 to
fb0c29f
Compare
alanwilhelm
force-pushed
the
codex/gateway-self-restart-guard
branch
from
June 17, 2026 08:45
fb0c29f to
18ffb3b
Compare
Contributor
Author
|
Closing stale PR per cleanup (2026-07-07). |
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.
What does this PR do?
Fixes two gateway stability failures from the same local incident:
A gateway-run agent could bypass the existing
hermes gateway restartprotection by shelling directly to the macOS launchd service:That sent SIGTERM to the running gateway from inside an active turn.
After the interrupted turn, the affected Discord channel stayed broken because the session remained
resume_pending=Truewhile replaying an oversized transcript. The local incident had ~329k recorded prompt tokens on a configured 400k context model, below the old 85% gateway hygiene threshold but above the agent's 50% compression threshold. Incomplete turns did not clearresume_pending, so every real user message re-entered the same poisoned context.This PR now blocks gateway self-restart commands from gateway/API sessions before
/yoloorapprovals.mode=off, and adds a pre-agent restart-recovery reset gate: oversizedresume_pendingsessions are rotated to a fresh active session before any model call. The old transcript is preserved in session history; it is not replayed into the current turn.Related overlap: existing open PRs #7817, #33084, and #33562 also cover launchd gateway lifecycle commands in
DANGEROUS_PATTERNS. This PR is stricter in gateway context because it hard-blocks before yolo/off approvals and also coversexecute_codesnippets.Related Issue
No public issue for the local incident. Related to the same launchd bypass class discussed in #7817, #33084, and #33562.
Type of Change
Changes Made
tools/approval.py— adds_check_gateway_self_restart_guard()and blocks Hermes gateway lifecycle commands from gateway/API sessions before yolo or disabled approvals can bypass the approval layer.tools/approval.py— adds launchdai.hermes.gatewaylifecycle commands toDANGEROUS_PATTERNSfor ordinary dangerous-command detection outside the hard-blocked gateway context.tools/approval.py— applies the same gateway self-restart guard tocheck_execute_code_guard()so Python snippets containing launchd gateway lifecycle calls are denied from gateway sessions before whole-script approval bypasses.gateway/run.py— adds a restart-recovery safety gate forresume_pendingsessions whose transcript is already beyond the agent compression threshold, capped at 50% context. Those sessions are reset before agent startup, with session-boundary transient state cleared and Telegram topic bindings re-pointed when applicable.tests/tools/test_approval.py— covers launchd Hermes gateway lifecycle command detection and isolates thefindapproval-key regression test from host-local permanent allowlists.tests/tools/test_command_guards.py— covers terminal andexecute_codegateway-session hard blocks, including theapprovals.mode=offpath.tests/gateway/test_restart_resume_pending.py— covers the exact 329k prompt / 400k context incident shape and verifies the oversizedresume_pendingsession rotates before agent startup.How to Test
From a gateway-context guard path, verify
launchctl kickstart -k gui/501/ai.hermes.gatewayreturnsapproved: Falsebefore approval mode/yolo handling.Verify an
execute_codesnippet containingsubprocess.run(['launchctl', 'kickstart', '-k', 'gui/501/ai.hermes.gateway'])is also blocked from a gateway session before whole-script approval bypasses.Verify a
resume_pendingsession withlast_prompt_tokens=329_227andcontext_length=400_000resets before agent startup instead of replaying the transcript.Run focused CI-parity wrapper tests:
Run syntax/bytecode validation:
Checklist
Code
fix(scope):,feat(scope):, etc.)pytest tests/ -qand all tests pass; not run locally because this draft targets gateway restart/recovery behavior and focused CI-parity wrapper tests were run insteadDocumentation & Housekeeping
docs/, docstrings) — N/A; no user-facing docs changedcli-config.yaml.exampleif I added/changed config keys — N/ACONTRIBUTING.mdorAGENTS.mdif I changed architecture or workflows — N/AFor New Skills
N/A.
Screenshots / Logs
Focused wrapper test results:
Compile checks: