Skip to content

The agent that grows with you

fix: local clients show the real cause when a turn raises on the gateway

Teknium51edc3cf2412
diff --git a/gateway/run_turn_persistence.py b/gateway/run_turn_persistence.py
index f70c48ec724..5bf9866e7f5 100644
--- a/gateway/run_turn_persistence.py
+++ b/gateway/run_turn_persistence.py
@@ -662,9 +662,12 @@ class GatewayTurnPersistenceMixin:
# The session's own route key is gone or changed: /retry repeats it, /new is the way out.
from agent.turn_failure_copy import launch_credentials_copy
return record_unexecuted_failure(launch_credentials_copy(e), 'launch_credentials_unavailable')
+ # A local client (CLI, TUI, Desktop) is the operator at this host: its result carries the
+ # real cause, so its details line is not the chat apology with the log pointer cut off.
+ local_error = f"{type(e).__name__}: {e}"[:500] if source.platform == Platform.LOCAL else None
return record_unexecuted_failure(self._hmwa_add_failed_turn_notice(
t("gateway.errors.generic_failed_with_hint", hint=status_hint), PARTIAL_FAILED_TURN_NOTICE,
- ))
+ ), error=local_error)
def _hmwa_discard_stale_result(self, source, _quick_key, run_generation):
"""A newer run generation superseded this turn: drop its deferred post-delivery callback."""
diff --git a/gateway/session_results.py b/gateway/session_results.py
index 3f718b70031..04e1ac247ba 100644
--- a/gateway/session_results.py
+++ b/gateway/session_results.py
@@ -7,15 +7,17 @@ execution_result: ContextVar[dict | None] = ContextVar("execution_result", defau
from hermes_state_terminal import RESULT_PREFIX as _RESULT_PREFIX, load_result
-def record_unexecuted_failure(reply, reason=None):
+def record_unexecuted_failure(reply, reason=None, error=None):
"""The admitted turn never ran because it failed (agent initialization raised, history
unreadable): commit a failed result for the executing admission, so no surface settles it
``completed`` with the apology as the turn's output. A *reason* is stamped as the turn's
- non-retryable failure code, so clients render that code's card. Returns ``reply`` unchanged."""
+ non-retryable failure code, so clients render that code's card. *error* replaces the reply
+ as the result's ``error`` (the raw cause a local client shows as its details line).
+ Returns ``reply`` unchanged."""
captured = execution_result.get()
if captured is not None and 'result' not in captured:
captured['result'] = {'final_response': '', 'messages': [], 'failed': True, 'completed': False,
- 'error': str(reply or 'The admitted turn failed.')}
+ 'error': str(error or reply or 'The admitted turn failed.')}
if reason:
from agent.turn_failure_copy import stamp_failure
stamp_failure(captured['result'], reason, False)
diff --git a/tests/gateway/test_agent_error_reply_local_detail.py b/tests/gateway/test_agent_error_reply_local_detail.py
new file mode 100644
index 00000000000..0628db9d83c
--- /dev/null
+++ b/tests/gateway/test_agent_error_reply_local_detail.py
@@ -0,0 +1,44 @@
+"""A turn that raises on the gateway keeps its real cause for a local client (CLI, TUI, Desktop),
+whose panel otherwise read ``Details: ⚠️ Something went wrong and I couldn't finish this reply.``
+Messaging platforms keep the sanitized apology: raw exception text never reaches a chat."""
+
+import asyncio
+from types import SimpleNamespace
+
+from gateway.config import Platform
+from gateway.platforms.event import MessageEvent
+from gateway.run import GatewayRunner
+from gateway.session import SessionSource
+from gateway.session_results import execution_result
+
+
+def _committed_error(platform):
+ runner = object.__new__(GatewayRunner)
+
+ async def stop_typing(event, source):
+ return None
+
+ runner._hmwa_stop_typing_for_turn = stop_typing
+ runner._session_state = lambda key: SimpleNamespace(turn=SimpleNamespace(agent=None))
+ source = SessionSource(platform=platform, chat_id="c", user_id="u")
+ prepared = runner._PreparedTurn([], "", None, None, None, None)
+ err = ImportError("The 'anthropic' package is required for the Anthropic provider: restart Hermes")
+ captured = {}
+ token = execution_result.set(captured)
+ try:
+ asyncio.run(runner._hmwa_agent_error_reply(
+ err, MessageEvent(text="x", source=source), source, None, "k", prepared,
+ ))
+ finally:
+ execution_result.reset(token)
+ return captured["result"]["error"]
+
+
+def test_local_client_sees_the_raised_cause_and_chat_keeps_the_apology():
+ from hermes_cli.cli_chat_error_copy import chat_error_response
+
+ panel = chat_error_response(_committed_error(Platform.LOCAL), provider="anthropic")
+ assert "Details: ImportError: The 'anthropic' package is required" in panel, panel
+
+ chat = _committed_error(Platform.TELEGRAM)
+ assert "anthropic" not in chat and "ImportError" not in chat, chat