The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(status): honor stopped gateway intent
KoNit-Kaa711728e81d
diff --git a/hermes_cli/web_routers/status.py b/hermes_cli/web_routers/status.pyindex 9360f5fa781..42c919a8dc3 100644--- a/hermes_cli/web_routers/status.py+++ b/hermes_cli/web_routers/status.py@@ -268,14 +268,22 @@ async def _resolve_gateway_status(profile_dir: Optional[Path], health_url) -> Diif runtime:gateway_state = runtime.get("gateway_state")if not gateway_running:- gateway_state = gateway_state if gateway_state in {"stopped", "startup_failed"} else "stopped"+ if runtime.get("desired_state") == "stopped":+ # A native profile-scoped stop records durable operator intent while+ # retaining the last transient startup result for diagnostics. The+ # dashboard must show the current intent, not that historical failure.+ gateway_state = "stopped"+ else:+ gateway_state = (gateway_state if gateway_state in {"stopped", "startup_failed"}+ else "stopped")elif remote_health_body is not None and gateway_state in {None, "stopped"}:# The health probe confirmed the gateway is alive, but the local runtime status# file may be stale (cross-container): override so the badge is correct.gateway_state = "running"gateway_platforms = _project_gateway_platforms(runtime.get("platforms") or {}, configured, gateway_running, gateway_state)- gateway_exit_reason = runtime.get("exit_reason")+ gateway_exit_reason = (None if gateway_state == "stopped"+ else runtime.get("exit_reason"))# Contract: gateway_updated_at is RFC3339 string | null, never a number. ``runtime``# may be the local gateway_state.json (legacy gateways wrote epoch floats; hand# edits can inject anything) or a remote /health/detailed body — normalize both.diff --git a/tests/hermes_cli/test_web_server_profile_unification.py b/tests/hermes_cli/test_web_server_profile_unification.pyindex cfb57f20499..a1f207a646b 100644--- a/tests/hermes_cli/test_web_server_profile_unification.py+++ b/tests/hermes_cli/test_web_server_profile_unification.py@@ -679,6 +679,7 @@ class TestProfileScopedGateway:runtime = {"pid": 4242,"gateway_state": "startup_failed",+ "desired_state": "running","platforms": {"telegram": {"state": "fatal", "error_code": "telegram_auth_error"},"alpha:telegram": {"state": "fatal", "error_code": "credential_collision"},@@ -710,6 +711,36 @@ class TestProfileScopedGateway:assert set(data["gateway_platforms"]) == {"telegram", "alpha:telegram"}assert data["gateway_platforms"]["alpha:telegram"]["error_code"] == "credential_collision"+ def test_status_hides_historical_startup_failure_after_operator_stop(+ self, client, isolated_profiles, monkeypatch+ ):+ """A durable stop intent takes precedence over an old startup failure."""+ import hermes_cli.web_server as web_server++ runtime = {+ "pid": 4242,+ "gateway_state": "startup_failed",+ "desired_state": "stopped",+ "platforms": {"telegram": {"state": "fatal"}},+ "exit_reason": "telegram: token rejected",+ "updated_at": "2026-06-17T00:00:00+00:00",+ }+ monkeypatch.setattr(_cfg_mod, "check_config_version", lambda: (1, 1))+ monkeypatch.setattr(+ _gw_status, "get_running_pid_cached", lambda *a, **k: None+ )+ monkeypatch.setattr(_gw_status, "read_runtime_status", lambda *a, **k: runtime)+ monkeypatch.setattr(web_server, "_GATEWAY_HEALTH_URL", None)++ resp = client.get("/api/status", params={"profile": "worker_beta"})++ assert resp.status_code == 200+ data = resp.json()+ assert data["gateway_running"] is False+ assert data["gateway_state"] == "stopped"+ assert data["gateway_exit_reason"] is None+ assert data["gateway_platforms"] == {}+def test_status_clears_platforms_on_clean_stop(self, client, isolated_profiles, monkeypatch):