Skip to content

fix(gateway): drop _HERMES_GATEWAY blanket guard for legit internal restarts - #37057

Closed
drzeast-png wants to merge 1 commit into
NousResearch:mainfrom
drzeast-png:pr/drop-hermes-gateway-guard
Closed

fix(gateway): drop _HERMES_GATEWAY blanket guard for legit internal restarts#37057
drzeast-png wants to merge 1 commit into
NousResearch:mainfrom
drzeast-png:pr/drop-hermes-gateway-guard

Conversation

@drzeast-png

Copy link
Copy Markdown

Problem

PR #35679 added a blanket guard that refuses all stop/restart commands from inside the gateway process (via the _HERMES_GATEWAY env var). The intent was to prevent the cron+KeepAlive respawn loop from #30719 — but it has the side effect of blocking legitimate manual restarts from WeChat/Telegram/etc., forcing users to SSH in or use an external terminal.

Additionally, the guard does not actually prevent the original #30719 loop: cron jobs run as subprocesses that inherit _HERMES_GATEWAY=1, but the guard triggers on the first attempt, not on the loop pattern itself.

Solution

Drop the guard entirely. Trust launchd KeepAlive (or systemd Restart=always / container restart policy) as the only respawn policy. With #35668 (KeepAlive unconditional) merged, the supervisor handles respawn correctly — no agent-side guard needed.

Behavior comparison

Scenario Old guard No guard (this PR)
Manual restart from WeChat/Telegram ❌ Blocked ✅ Allowed
cron fires restart once an hour ❌ Blocked (if inside gateway) ✅ Allowed
cron fires restart every 10s + KeepAlive (original #30719 loop) ❌ Blocks 1st attempt (breaks the loop but also breaks valid use) ✅ KeepAlive ensures stable respawn; the macOS race is fixed in companion PR

Companion PRs

Supersedes

Test plan

@liuhao1024

Copy link
Copy Markdown
Contributor

One concern worth noting before merge.

Companion PR #35668 is still OPEN (not merged).

The PR body states the fix depends on #35668 ("With #35668 (KeepAlive unconditional) merged, the supervisor handles respawn correctly — no agent-side guard needed"), but #35668 has not landed yet. If this PR merges first, there's a window where:

  1. The _HERMES_GATEWAY guard is removed (this PR)
  2. KeepAlive is not yet unconditional (fix(gateway): keep launchd KeepAlive unconditional for macOS resilience #35668 still open)
  3. The original Agent can schedule gateway-restart cron job that kills its own runtime, creating respawn loop with launchctl/systemd KeepAlive #30719 cron+KeepAlive respawn loop could re-occur

The PR body also references a companion "macOS via_service race fix" that is "incoming" — another dependency that isn't merged yet.

Suggestion: ensure #35668 (and the macOS race fix companion) merge before this PR, or add a runtime check that raises an error if the guard is removed but KeepAlive is still conditional. The simpler path is just ordering the merges correctly.

@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/gateway Gateway runner, session dispatch, delivery comp/cli CLI entry point, hermes_cli/, setup wizard needs-decision Awaiting maintainer decision before any implementation labels Jun 2, 2026
@drzeast-png
drzeast-png force-pushed the pr/drop-hermes-gateway-guard branch 5 times, most recently from 9ead0b8 to 334bd43 Compare June 4, 2026 11:37
@drzeast-png
drzeast-png requested a review from a team June 4, 2026 11:37
@drzeast-png
drzeast-png force-pushed the pr/drop-hermes-gateway-guard branch 8 times, most recently from 908816f to 23e7e55 Compare June 5, 2026 04:16
@drzeast-png
drzeast-png force-pushed the pr/drop-hermes-gateway-guard branch 3 times, most recently from 95d84c0 to 53be66b Compare June 5, 2026 05:30
…estarts

Allow restart/stop from inside the gateway (e.g. via WeChat/Telegram)
so the user can manage the gateway remotely. Trust launchd KeepAlive
as the only respawn policy; the upstream blanket guard (NousResearch#35679) blocks
legitimate manual restarts. Supersedes the still-open PR NousResearch#35815
(loop-detector variant).
@drzeast-png
drzeast-png force-pushed the pr/drop-hermes-gateway-guard branch from 53be66b to 057dba6 Compare June 5, 2026 09:18
@austinpickett

Copy link
Copy Markdown
Collaborator

Review notes — companion PR context

This PR removes the _HERMES_GATEWAY blanket guard for stop and restart — the guard from #30719 that prevents agent-initiated kill loops. The removal is correct in principle: the guard inadvertently blocked legitimate in-chat restart commands (WeChat, Telegram, etc.), forcing users to SSH in.

However: this PR is a strict subset of #37063 (same author). That PR does both:

  1. Removes the same blanket guard (this PR's change)
  2. Adds via_service=True routing on macOS/Darwin in gateway/run.py — which is the actual fix for the launchd KeepAlive race that the guard was protecting against
  3. Improves WeChat _is_stale_session_ret for ret=-3 edge cases

Recommendation: Close this PR in favor of #37063. The guard removal without the via_service fix still leaves macOS launchd users exposed to the KeepAlive respawn race. #37063 is the complete fix.

Tagging needs-decision is appropriate — maintainer should confirm which PR to proceed with.

@austinpickett

Copy link
Copy Markdown
Collaborator

Closing in favor of #37063 (same author), which includes this change plus the macOS fix and WeChat stale-session improvements — the complete fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/cli CLI entry point, hermes_cli/, setup wizard comp/gateway Gateway runner, session dispatch, delivery needs-decision Awaiting maintainer decision before any implementation P2 Medium — degraded but workaround exists type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants