The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(gateway): the multiplex verdict precedes replacing a running gateway
Erosikaa562f90febb1
diff --git a/gateway/run_bootstrap.py b/gateway/run_bootstrap.pyindex 8ffe771a35a..ba963486f76 100644--- a/gateway/run_bootstrap.py+++ b/gateway/run_bootstrap.py@@ -452,6 +452,14 @@ async def start_gateway(config: Optional[GatewayConfig] = None, replace: bool =from gateway.code_skew import record_boot_fingerprintrecord_boot_fingerprint()+ # Config verdicts come before the duplicate-instance guard: `--replace` must not stop a healthy+ # gateway for a launch that cannot start.+ resolved_config = config if config is not None else load_gateway_config_for_runner()+ profile_homes = (_multiplex_profile_homes(resolved_config)+ if getattr(resolved_config, 'multiplex_profiles', False) else [])+ if profile_homes and not _launch_home_may_multiplex():+ return False+# Duplicate-instance guard scoped to HERMES_HOME; distinct-home multi-profile setups coexist.from gateway.status import get_running_pidexisting_pid = get_running_pid()@@ -461,11 +469,6 @@ async def start_gateway(config: Optional[GatewayConfig] = None, replace: bool =from gateway.runtime_ownership import process_ownership, OwnershipConflictfrom gateway.status import remove_pid_file, release_gateway_runtime_lock- resolved_config = config if config is not None else load_gateway_config_for_runner()- profile_homes = (_multiplex_profile_homes(resolved_config)- if getattr(resolved_config, 'multiplex_profiles', False) else [])- if profile_homes and not _launch_home_may_multiplex():- return Falsetry:process_ownership.reserve([get_hermes_home(), *(home for _, home in profile_homes)])except OwnershipConflict as exc:diff --git a/tests/gateway/test_multiplex_requires_default_profile.py b/tests/gateway/test_multiplex_requires_default_profile.pyindex cf8b02ee818..caf3a3774f9 100644--- a/tests/gateway/test_multiplex_requires_default_profile.py+++ b/tests/gateway/test_multiplex_requires_default_profile.py@@ -38,6 +38,36 @@ def test_default_profile_launch_may_multiplex(tmp_path, monkeypatch):assert run_bootstrap._launch_home_may_multiplex() is True+async def test_verdict_precedes_replacing_a_running_gateway(tmp_path, monkeypatch):+ """``hermes gateway run --replace`` on a named profile with the flag must exit EX_CONFIG while the+ healthy gateway it would have replaced keeps running."""+ from gateway import run_bootstrap+ from gateway.config import GatewayConfig++ root = _root(tmp_path)+ monkeypatch.setenv('HERMES_HOME', str(root / 'profiles' / 'foo'))+ import hermes_constants+ hermes_constants._default_hermes_root_memo = None+ monkeypatch.setattr('hermes_cli.resource_limits.apply_nofile_soft_limit', lambda: None)+ monkeypatch.setattr('gateway.code_skew.record_boot_fingerprint', lambda: None)+ monkeypatch.setattr('gateway.status.get_running_pid', lambda: 4242)+ monkeypatch.setattr('gateway.run._write_runtime_status_quiet', lambda **kw: None)+ replaced = []++ async def fake_replace(existing_pid, replace):+ replaced.append(existing_pid)+ return False++ monkeypatch.setattr(run_bootstrap, '_start_gateway_replace_existing_instance', fake_replace)+ config = GatewayConfig()+ config.multiplex_profiles = True+ with pytest.raises(SystemExit) as exc:+ await run_bootstrap.start_gateway(config=config, replace=True)+ assert exc.value.code == GATEWAY_FATAL_CONFIG_EXIT_CODE+ assert replaced == []++def test_cloned_profile_does_not_inherit_the_multiplex_flag(tmp_path, monkeypatch):import yamlfrom hermes_cli.profiles import _strip_multiplex_flag