The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(gateway): fail fast for standalone parked profiles
KoNit-K04e06cb92a75
diff --git a/hermes_cli/gateway_runtime.py b/hermes_cli/gateway_runtime.pyindex 8ebff4db819..99e38d23aeb 100644--- a/hermes_cli/gateway_runtime.py+++ b/hermes_cli/gateway_runtime.py@@ -122,6 +122,27 @@ def _multiplexer_starting(home: Path) -> bool:return root is not None and missing_owner_state(root) == "starting"+def _standalone_multiplexer_reason(home: Path) -> str | None:+ """Return a live host's reason for not serving *home*, if it has one.++ A held root lock ordinarily means that a named profile should wait for its+ multiplexer. A host which published a guard refusal is different: it is a+ standalone gateway and can never add the named profile during that boot.+ """+ from hermes_cli.gateway_runtime_discovery import missing_owner_state+ from hermes_cli.gateway_runtime_multiplex import implied_host_root++ root = implied_host_root(home)+ if root is None or missing_owner_state(root) != "starting":+ return None+ from gateway.status import read_runtime_status, runtime_status_pid_is_live+ record = read_runtime_status(root / "gateway_state.json")+ if not runtime_status_pid_is_live(record):+ return None+ reason = record.get("multiplex_standalone_reason") if isinstance(record, dict) else None+ return str(reason)[:500] if isinstance(reason, str) and reason else None++def _parked_by_multiplexer(payload: dict, home: Path) -> GatewayDiscovery | None:"""A secondary the multiplexer could not serve (unusable store, home owned elsewhere) ispublished under ``parked_profiles`` (name -> reason). That is a terminal verdict for its@@ -309,6 +330,8 @@ def ensure_gateway_runtime(profile_home: str | Path, *, timeout: float = DEFAULTrequested = Trueif observed.state == "absent":retiring = False+ if observed.state == "absent" and not requested and (reason := _standalone_multiplexer_reason(home)):+ return GatewayDiscovery("inaccessible", reason_code="profile_parked", detail=reason)# A default multiplexer that is still starting will serve this named profile; never# spawn a competing per-profile daemon while its reservation is pending.if observed.state == "absent" and not requested and _multiplexer_starting(home):diff --git a/tests/hermes_cli/test_gateway_runtime_ensure.py b/tests/hermes_cli/test_gateway_runtime_ensure.pyindex 702c87e6dbd..f3716295923 100644--- a/tests/hermes_cli/test_gateway_runtime_ensure.py+++ b/tests/hermes_cli/test_gateway_runtime_ensure.py@@ -437,6 +437,30 @@ def test_reserved_root_never_suppresses_a_standalone_profile_start(tmp_path, monassert spawned == [home.resolve()]+def test_ensure_reports_a_standalone_host_reason_for_an_unserved_named_profile(tmp_path, monkeypatch):+ """A live standalone host cannot later add this profile, so do not wait on its root lock."""+ from gateway import status+ from hermes_cli import gateway_runtime as runtime, gateway_runtime_discovery as discovery++ root = tmp_path / ".hermes"+ home = root / "profiles" / "alpha"+ home.mkdir(parents=True, mode=0o700)+ monkeypatch.setattr(runtime, "_update_fenced", lambda homes: False)+ monkeypatch.setattr(runtime, "discover_gateway_endpoint", lambda *a, **k: runtime.GatewayDiscovery("absent"))+ monkeypatch.setattr(discovery, "missing_owner_state", lambda path: "starting")+ monkeypatch.setattr(status, "read_runtime_status", lambda path: {+ "gateway_state": "running",+ "served_profiles": [],+ "multiplex_standalone_reason": "duplicate Telegram token; run hermes gateway migrate --multiplex",+ })+ monkeypatch.setattr(status, "runtime_status_pid_is_live", lambda record: True)++ result = runtime.ensure_gateway_runtime(home, timeout=1)++ assert (result.state, result.reason_code) == ("inaccessible", "profile_parked")+ assert result.detail == "duplicate Telegram token; run hermes gateway migrate --multiplex"++@pytest.mark.platforms("linux", "macos")def test_dead_unmanaged_start_is_a_prompt_terminal_verdict(tmp_path, monkeypatch):"""The one start this call requested exited without leaving an owner: report it with the