Skip to content

The agent that grows with you

fix(messaging): stopped profile no longer wears "Start failed" on the Channels page

teknium1595d4cfe4511
diff --git a/gateway/status.py b/gateway/status.py
index 7f760f42783..6cd669dcfd7 100644
--- a/gateway/status.py
+++ b/gateway/status.py
@@ -210,6 +210,21 @@ def normalize_updated_at(value: Any) -> Optional[str]:
return None
+def retained_gateway_state(runtime: Any) -> str:
+ """What a NOT-running gateway's retained ``gateway_state.json`` says about it now:
+ ``"startup_failed"`` only while the operator still wants it running, else ``"stopped"``.
+
+ ``hermes gateway stop`` keeps the last ``startup_failed`` + ``exit_reason`` on disk for
+ diagnostics and records the durable stop intent as ``desired_state``; a profile the operator
+ stopped is "stopped", not a current failure. Any other retained state of a dead process
+ (``running``, ``starting``, missing) is also just "stopped". Shared by ``/api/status`` and
+ ``/api/messaging/platforms`` so the sidebar strip and the Channels page cannot disagree."""
+ rt = runtime if isinstance(runtime, dict) else {}
+ if rt.get("desired_state") != "stopped" and rt.get("gateway_state") == "startup_failed":
+ return "startup_failed"
+ return "stopped"
+
+
def terminate_pid(
pid: int, *, force: bool = False, expected_start_time: Optional[float] = None
) -> None:
diff --git a/hermes_cli/web_routers/messaging.py b/hermes_cli/web_routers/messaging.py
index e75c7875eb4..5d96faf7434 100644
--- a/hermes_cli/web_routers/messaging.py
+++ b/hermes_cli/web_routers/messaging.py
@@ -22,7 +22,8 @@ from typing import Any, Optional
from fastapi import APIRouter, HTTPException
from gateway.status import (
- multiplexer_liveness_for_profile, profile_platforms_from_multiplexer, resolve_gateway_liveness)
+ multiplexer_liveness_for_profile, profile_platforms_from_multiplexer, resolve_gateway_liveness,
+ retained_gateway_state)
from hermes_cli._subprocess_compat import windows_hide_flags
from hermes_cli.config import OPTIONAL_ENV_VARS, get_env_path, redact_key
from hermes_constants import get_process_hermes_home
@@ -246,7 +247,9 @@ def _messaging_platform_payload(
elif gateway_running and not state:
state = "pending_restart"
elif not gateway_running and not state:
- state = "startup_failed" if rt.get("gateway_state") == "startup_failed" else "gateway_stopped"
+ # Same verdict /api/status gives: ``hermes gateway stop`` keeps the last failure on disk,
+ # and a profile the operator stopped must not wear a "Start failed" badge for it.
+ state = "startup_failed" if retained_gateway_state(rt) == "startup_failed" else "gateway_stopped"
error_code = runtime_platform.get("error_code")
error_message = runtime_platform.get("error_message")
diff --git a/hermes_cli/web_routers/status.py b/hermes_cli/web_routers/status.py
index 3315a33cb34..64f91b0f129 100644
--- a/hermes_cli/web_routers/status.py
+++ b/hermes_cli/web_routers/status.py
@@ -20,7 +20,7 @@ from starlette.concurrency import run_in_threadpool
from fastapi import HTTPException, Request
from gateway.status import (
derive_gateway_busy, derive_gateway_drainable, normalize_updated_at, parse_active_agents,
- profile_platforms_from_multiplexer, resolve_gateway_liveness)
+ profile_platforms_from_multiplexer, resolve_gateway_liveness, retained_gateway_state)
from hermes_cli import __version__, __release_date__
from hermes_cli.config import get_config_path, get_env_path
from hermes_constants import get_process_hermes_home, profile_name_for_home
@@ -268,11 +268,9 @@ async def _resolve_gateway_status(profile_dir: Optional[Path], health_url) -> Di
if runtime:
gateway_state = runtime.get("gateway_state")
if not gateway_running:
- # ``desired_state`` is the operator's durable start/stop intent (``hermes gateway stop``
- # keeps the last ``startup_failed`` + ``exit_reason`` on disk for diagnostics). A profile
- # the operator stopped is "stopped", not a current failure the overview should alarm on.
- if runtime.get("desired_state") == "stopped" or gateway_state not in {"stopped", "startup_failed"}:
- gateway_state = "stopped"
+ # Shared with /api/messaging/platforms: a durable operator stop outranks a retained
+ # ``startup_failed`` (kept on disk for diagnostics), so the overview does not alarm on it.
+ gateway_state = retained_gateway_state(runtime)
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.
diff --git a/tests/hermes_cli/test_web_server_messaging_stale_runtime.py b/tests/hermes_cli/test_web_server_messaging_stale_runtime.py
index 49ec2801175..a4750a2d711 100644
--- a/tests/hermes_cli/test_web_server_messaging_stale_runtime.py
+++ b/tests/hermes_cli/test_web_server_messaging_stale_runtime.py
@@ -53,3 +53,25 @@ def test_stopped_gateway_does_not_report_stale_platform_error(client):
assert telegram["state"] == "gateway_stopped"
assert telegram["error_code"] is None
assert telegram["error_message"] is None
+
+
+def test_operator_stopped_gateway_does_not_report_retained_startup_failure(client):
+ """``hermes gateway stop`` keeps the last ``startup_failed`` + ``exit_reason`` on disk with
+ ``desired_state: stopped``; the Channels page must read that as stopped, exactly like
+ ``/api/status`` does, not wear a "Start failed" badge with the stale reason (#112517)."""
+ from hermes_constants import get_hermes_home
+
+ (get_hermes_home() / "gateway_state.json").write_text(json.dumps({
+ "kind": "gateway", "pid": 999_999_999, "start_time": 1.0,
+ "gateway_state": "startup_failed", "desired_state": "stopped",
+ "exit_reason": "Port 8642 already in use", "updated_at": "2026-01-01T00:00:00+00:00",
+ "platforms": {},
+ }), encoding="utf-8")
+
+ payload = client.get("/api/messaging/platforms").json()
+ telegram = next(p for p in payload["platforms"] if p["id"] == "telegram")
+
+ assert telegram["gateway_running"] is False
+ assert telegram["state"] == "gateway_stopped"
+ assert telegram["error_code"] is None
+ assert telegram["error_message"] is None