Skip to content

The agent that grows with you

fix(gateway): multiplex refusal must exit EX_CONFIG (78), not 1

Sam Campbell2fb1e62b2ee0
diff --git a/hermes_cli/gateway.py b/hermes_cli/gateway.py
index dced8278a5b..1d0bf451ab7 100644
--- a/hermes_cli/gateway.py
+++ b/hermes_cli/gateway.py
@@ -5619,7 +5619,18 @@ def _guard_named_profile_under_multiplexer(force: bool = False) -> None:
print()
print(" Pass --force to start a separate profile gateway anyway (not")
print(" recommended while the multiplexer is running).")
- sys.exit(1)
+ # EX_CONFIG, not a generic failure. This refusal is decided entirely by
+ # configuration (multiplex_profiles plus the allowlist), so it is permanent:
+ # no number of retries can change the answer. Exiting 1 made it look
+ # transient to a service manager -- and the systemd unit this module
+ # generates pairs Restart=always/RestartSec=5 with StartLimitIntervalSec=0,
+ # deliberately trading systemd's generic start-rate limiter for the specific
+ # RestartPreventExitStatus=GATEWAY_FATAL_CONFIG_EXIT_CODE backstop declared
+ # beside it. Returning 1 left that backstop unarmed with the limiter already
+ # off, so a correct refusal became an unbounded restart loop. 78 also reaches
+ # the s6 finish script's 125 "permanent failure" translation (see #51228),
+ # the same path the other fatal-config exits take.
+ sys.exit(GATEWAY_FATAL_CONFIG_EXIT_CODE)
def _guard_supervised_gateway_conflict(force: bool = False) -> None:
diff --git a/tests/gateway/test_multiplex_lifecycle.py b/tests/gateway/test_multiplex_lifecycle.py
index fbc04b7e1b1..1809a337d67 100644
--- a/tests/gateway/test_multiplex_lifecycle.py
+++ b/tests/gateway/test_multiplex_lifecycle.py
@@ -2,6 +2,7 @@
import pytest
from gateway.config import GatewayConfig
+from gateway.restart import GATEWAY_FATAL_CONFIG_EXIT_CODE
class TestServedProfilesStatus:
@@ -82,8 +83,9 @@ class TestNamedProfileMultiplexerGuard:
from hermes_cli import gateway as gw
- with pytest.raises(SystemExit, match="1"):
+ with pytest.raises(SystemExit) as excinfo:
gw._guard_named_profile_under_multiplexer(force=False)
+ assert excinfo.value.code == GATEWAY_FATAL_CONFIG_EXIT_CODE
def test_served_profile_is_still_guarded(self, monkeypatch, tmp_path):
self._fake_running_default_gateway(monkeypatch, tmp_path)
@@ -97,8 +99,9 @@ class TestNamedProfileMultiplexerGuard:
from hermes_cli import gateway as gw
- with pytest.raises(SystemExit, match="1"):
+ with pytest.raises(SystemExit) as excinfo:
gw._guard_named_profile_under_multiplexer(force=False)
+ assert excinfo.value.code == GATEWAY_FATAL_CONFIG_EXIT_CODE
@pytest.mark.parametrize(
"allowlist_yaml",