The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(tui): say why the gateway refused instead of retrying silently
Teknium861afd67b2f2
diff --git a/hermes_cli/gateway_runtime.py b/hermes_cli/gateway_runtime.pyindex 7ae0c28ec05..e2efe26e88b 100644--- a/hermes_cli/gateway_runtime.py+++ b/hermes_cli/gateway_runtime.py@@ -221,8 +221,7 @@ def _update_fenced(homes) -> bool:return False-_REPLACE_FAILED_DETAIL = ("an older Hermes gateway owns this profile and is still running after a stop; "- "stop it (hermes gateway stop) and retry")+_REPLACE_FAILED_DETAIL = "an older Hermes gateway still owns this profile after a stop; run: hermes gateway stop"def ensure_gateway_runtime(profile_home: str | Path, *, timeout: float = DEFAULT_ENSURE_TIMEOUT,diff --git a/hermes_cli/gateway_runtime_replace.py b/hermes_cli/gateway_runtime_replace.pyindex d0d465f4a05..e15de3744e8 100644--- a/hermes_cli/gateway_runtime_replace.py+++ b/hermes_cli/gateway_runtime_replace.py@@ -25,17 +25,13 @@ from typing import Any_GRACEFUL_STOP_SECONDS = 10.0_FORCED_STOP_SECONDS = 5.0+# One line each, short enough for the TUI's activity row after its "gateway incompatible: " prefix.REFUSAL_DETAIL = {- "owner_newer": "a gateway from a newer Hermes owns this profile; update this Hermes or stop it "- "(hermes gateway stop)",- "foreign_install": "the gateway that owns this profile belongs to another Hermes install; stop it "- "there (hermes gateway stop)",- "owner_unverified": "an older Hermes gateway owns this profile but could not be verified; stop it "- "(hermes gateway stop) and retry",- "owner_did_not_exit": "an older Hermes gateway owns this profile and did not stop; stop it "- "(hermes gateway stop) and retry",- "owner_unreachable": "an older Hermes gateway owns this profile; stop it (hermes gateway stop) "- "and retry",+ "owner_newer": "a newer Hermes's gateway owns this profile; update Hermes or run: hermes gateway stop",+ "foreign_install": "another Hermes install's gateway owns this profile; stop it there: hermes gateway stop",+ "owner_unverified": "an older Hermes gateway owns this profile and was not verified; run: hermes gateway stop",+ "owner_did_not_exit": "an older Hermes gateway owns this profile and did not stop; run: hermes gateway stop",+ "owner_unreachable": "an older Hermes gateway owns this profile; run: hermes gateway stop",}diff --git a/tests/tui_gateway/test_gateway_bootstrap_recover.py b/tests/tui_gateway/test_gateway_bootstrap_recover.pyindex 3a7ff31f149..e9938b53eb0 100644--- a/tests/tui_gateway/test_gateway_bootstrap_recover.py+++ b/tests/tui_gateway/test_gateway_bootstrap_recover.py@@ -60,6 +60,22 @@ def test_recover_reensures_only_a_crashed_owner(monkeypatch, tmp_path, record, eassert calls == []+def test_failure_names_the_reason_and_its_remedy(monkeypatch, tmp_path):+ """The TUI echoes this text; a refusal's detail (what to do) must travel with the verdict."""+ module = _load_bootstrap()+ home = (tmp_path / "home").resolve()+ home.mkdir()+ monkeypatch.setattr(hermes_constants, "get_hermes_home", lambda: home)+ monkeypatch.setattr(gateway_runtime, "ensure_gateway_runtime", lambda h, timeout=30, idle_exit=False:+ SimpleNamespace(state="incompatible", endpoint=None, reason_code="runtime_protocol",+ detail="the gateway belongs to another Hermes install; stop it there"))+ with pytest.raises(RuntimeError) as err:+ module.bootstrap(True)+ assert str(err.value).splitlines() == [+ "gateway incompatible: runtime_protocol",+ "gateway incompatible: the gateway belongs to another Hermes install; stop it there"]++def test_started_daemon_does_not_inherit_the_launch_time_kanban_board(monkeypatch, tmp_path):"""`hermes --tui` pins HERMES_KANBAN_BOARD for its own launch; the shared daemon this bootstrapstarts (spawn_unmanaged_gateway copies os.environ) must keep the profile's current board."""diff --git a/ui-tui/scripts/gateway_bootstrap.py b/ui-tui/scripts/gateway_bootstrap.pyindex 1fb6a7ebaba..a3958515e62 100644--- a/ui-tui/scripts/gateway_bootstrap.py+++ b/ui-tui/scripts/gateway_bootstrap.py@@ -37,6 +37,19 @@ def owner_crashed(home: Path) -> bool:return idle_exited or record.get("gateway_state") in _LIVE_CLAIMS+def failure_message(receipt) -> str:+ """What the TUI shows when there is no owner to attach: the bounded verdict, then its detail+ (a refusal's remedy, or a start that died's own redacted output), each line still a verdict."""+ head = f"gateway {receipt.state}: {receipt.reason_code or 'not ready'}"+ detail = getattr(receipt, "detail", None)+ if not detail:+ return head+ if receipt.reason_code == "runtime_exited":+ return f"{head}\n{detail}"+ lines = [line.strip() for line in str(detail).splitlines() if line.strip()]+ return "\n".join([head, *(f"gateway {receipt.state}: {line}" for line in lines)])++def bootstrap(start: bool, recover: bool = False) -> dict:from hermes_constants import get_hermes_homefrom hermes_cli.gateway_runtime import control_home_for, discover_gateway_endpoint, ensure_gateway_runtime@@ -57,8 +70,7 @@ def bootstrap(start: bool, recover: bool = False) -> dict:if not start and recover and receipt.state == "absent" and owner_crashed(home):receipt = ensure_gateway_runtime(home, timeout=30, idle_exit=True)if receipt.state != "ready" or receipt.endpoint is None:- detail = f"\n{receipt.detail}" if receipt.reason_code == "runtime_exited" and receipt.detail else ""- raise RuntimeError(f"gateway {receipt.state}: {receipt.reason_code or 'not ready'}{detail}")+ raise RuntimeError(failure_message(receipt))endpoint = receipt.endpoint# A profile served by the default multiplexer has no socket of its own; the host mints its ticket.control = control_home_for(home, endpoint)diff --git a/ui-tui/src/__tests__/createGatewayEventHandler.test.ts b/ui-tui/src/__tests__/createGatewayEventHandler.test.tsindex f5bdabb6c33..a5d0849b051 100644--- a/ui-tui/src/__tests__/createGatewayEventHandler.test.ts+++ b/ui-tui/src/__tests__/createGatewayEventHandler.test.ts@@ -785,6 +785,28 @@ describe('createGatewayEventHandler', () => {expect(messages.some(m => m.includes('[startup] timed out'))).toBe(false)})+ it('echoes the canonical bootstrap verdict so a refused gateway is never a silent retry loop', () => {+ const appended: Msg[] = []+ const onEvent = createGatewayEventHandler(buildCtx(appended))++ onEvent({+ payload: {+ cwd: '',+ python: 'gateway ensure',+ stderr_tail:+ 'Command failed: python gateway_bootstrap.py --start\ngateway incompatible: runtime_protocol\n' ++ "gateway incompatible: another Hermes install's gateway owns this profile; stop it there: hermes gateway stop"+ },+ type: 'gateway.start_timeout'+ } as any)++ const messages = getTurnState().activity.map(a => a.text)++ expect(messages).toContain('gateway incompatible: runtime_protocol')+ expect(messages.some(m => m.includes('another Hermes install'))).toBe(true)+ expect(messages.some(m => m.startsWith('Command failed'))).toBe(false)+ })+it('prefers raw text over Rich-rendered ANSI on message.complete (#16391)', () => {const appended: Msg[] = []const onEvent = createGatewayEventHandler(buildCtx(appended))diff --git a/ui-tui/src/__tests__/userMessages.test.ts b/ui-tui/src/__tests__/userMessages.test.tsindex e8c032497bf..c4901ce6fa9 100644--- a/ui-tui/src/__tests__/userMessages.test.ts+++ b/ui-tui/src/__tests__/userMessages.test.ts@@ -223,6 +223,10 @@ describe('backend lifecycle copy', () => {expect(stderrLooksLikeProblem('[gateway-turn] ValueError: nope')).toBe(true)expect(stderrLooksLikeProblem('ValueError: nope')).toBe(true)expect(stderrLooksLikeProblem('INFO hermes.mcp: discovered 3 servers')).toBe(false)+ // The canonical bootstrap's verdict (and its remedy line) is the reason a TUI cannot connect.+ expect(stderrLooksLikeProblem('gateway incompatible: runtime_protocol')).toBe(true)+ expect(stderrLooksLikeProblem('gateway inaccessible: profile_parked')).toBe(true)+ expect(stderrLooksLikeProblem('the gateway incompatible: x')).toBe(false)})it('ignores dependency warning lines and does not call the failure a "backend" problem', () => {diff --git a/ui-tui/src/app/userMessages.ts b/ui-tui/src/app/userMessages.tsindex 41d8645be76..21bdaa28013 100644--- a/ui-tui/src/app/userMessages.ts+++ b/ui-tui/src/app/userMessages.ts@@ -85,9 +85,12 @@ export const backendSlowStartStatus = (): string => t('userMessages.backend.slow// ── stderr noise ──────────────────────────────────────────────────────────// Only real failures: a traceback, a CRITICAL log line, an `XxxError:` / `XxxException:`-// head, or the gateway's own turn/exit markers. Dependency `DeprecationWarning` /+// head, the gateway's own turn/exit markers, or the canonical bootstrap's verdict lines+// (`gateway incompatible: runtime_protocol`, `gateway inaccessible: …` and their remedy, see+// ui-tui/scripts/gateway_bootstrap.py failure_message). Dependency `DeprecationWarning` /// `UserWarning` lines are noise and stay in /logs only.-const STDERR_PROBLEM_RE = /Traceback|\b[A-Z][A-Za-z]*(?:Error|Exception)\b:|CRITICAL|\[gateway-turn\]|\[gateway-exit\]/+const STDERR_PROBLEM_RE =+ /Traceback|\b[A-Z][A-Za-z]*(?:Error|Exception)\b:|CRITICAL|\[gateway-turn\]|\[gateway-exit\]|^gateway (?:absent|conflict|draining|inaccessible|incompatible|starting): //** Only lines that look like a failure earn an activity row; the rest stay in /logs. */export const stderrLooksLikeProblem = (line: string): boolean => STDERR_PROBLEM_RE.test(line)