fix: block persistent gateway self-restart jobs - #63272
Conversation
|
Thanks for pursuing a real gateway-loop gap. The premise is confirmed on current main: the gateway terminal guard only calls Problems
Suggested changes
Automated hermes-sweeper review. |
- Resolve guard cwd against get_session_cwd(session_key); fall back to env.cwd
when no session record exists yet, matching current main's per-session cwd
architecture.
- Make referenced-script reads backend-aware: local read first; if missing,
fall back to env.execute('cat ...') for SSH/Modal/Daytona backends.
- Reuse the recursive scanner in check_gateway_lifecycle so nested cron
wrapper scripts are caught, and resolve relative refs inside a script
against that script's directory.
- Add regression tests for remote-backend reads, two-session cwd, and nested
cron wrappers.
Verification: 80 passed tests/hermes_cli/test_gateway_restart_loop.py;
694 passed tests/cron; ruff + git diff --check clean.
1824941 to
1c8721d
Compare
|
Rebased onto current
Verification:
Fresh head: |
…bel-independent detection Extends the shared _GATEWAY_LIFECYCLE_PATTERN (used by BOTH the cron creation-time guard in cron/lifecycle_guard.py and the terminal execution-time hard-block in tools/terminal_tool.py) so Branch B covers launchctl submit and bootstrap alongside kickstart/unload/load/stop/ restart, and normalizes POSIX shell line continuations before matching so the exact multi-line reported shape in #62891 cannot slip past. Also extends the execution-aware, label-independent detector (contains_launchctl_submit_command, cherry-picked from #63272) to cover launchctl bootstrap, since a neutral label like ai.hermes.svc-reload-tmp defeats any label-anchored regex — the second production reproduction. Regression tests cover both sites, including `launchctl submit -l com.foo -- /path/gateway` and the bootstrap variant, plus outside-gateway pass-through. Branch B regex extension and continuation normalization drawn from PR #62896; bootstrap coverage and test shapes drawn from PR #51003. Co-authored-by: JackJin <1037461232@qq.com> Co-authored-by: joelbrilliant <joelbrilliant1@gmail.com>
|
Merged via PR #75972 (#75972) — your three commits (label-independent submit blocker + bounded recursive referenced-script scanner) were cherry-picked verbatim with your authorship preserved, extended to cover the bootstrap variant. Yours was the cleanest of the three candidate fixes. Fixes #62891. Thanks! |
…bel-independent detection Extends the shared _GATEWAY_LIFECYCLE_PATTERN (used by BOTH the cron creation-time guard in cron/lifecycle_guard.py and the terminal execution-time hard-block in tools/terminal_tool.py) so Branch B covers launchctl submit and bootstrap alongside kickstart/unload/load/stop/ restart, and normalizes POSIX shell line continuations before matching so the exact multi-line reported shape in NousResearch#62891 cannot slip past. Also extends the execution-aware, label-independent detector (contains_launchctl_submit_command, cherry-picked from NousResearch#63272) to cover launchctl bootstrap, since a neutral label like ai.hermes.svc-reload-tmp defeats any label-anchored regex — the second production reproduction. Regression tests cover both sites, including `launchctl submit -l com.foo -- /path/gateway` and the bootstrap variant, plus outside-gateway pass-through. Branch B regex extension and continuation normalization drawn from PR NousResearch#62896; bootstrap coverage and test shapes drawn from PR NousResearch#51003. Co-authored-by: JackJin <1037461232@qq.com> Co-authored-by: joelbrilliant <joelbrilliant1@gmail.com>
Summary
A real macOS gateway session scheduled a delayed shell helper through launchd's submitted-job primitive. launchd registered it as persistent (
OnDemand=false), so the helper slept 45 seconds, restarted the gateway, exited successfully, and was relaunched. It produced 762 restart cycles before removal.This patch closes the indirect execution path in the existing gateway lifecycle guard:
-c, relative-cwd, executable-shebang, and nested shell scriptsVerification
78 passed—tests/hermes_cli/test_gateway_restart_loop.py679 passed—tests/cron156 passed— focused terminal-tool suitesgit diff --checkAn independent adversarial review found hidden-script, live-cwd, parser, and unbounded-read gaps in the first realization; the second commit adds regression coverage and closes each one.