Skip to content

The agent that grows with you

fix(cli): keep owner refusals at prompt.submit out of gateway_connection

unsupportedpastels765056548b2d
diff --git a/hermes_cli/gateway_agent.py b/hermes_cli/gateway_agent.py
index 8038b26715a..90d398846f2 100644
--- a/hermes_cli/gateway_agent.py
+++ b/hermes_cli/gateway_agent.py
@@ -17,7 +17,7 @@ import threading
import time
import uuid
-from hermes_cli.gateway_client import GatewayClientError
+from hermes_cli.gateway_client import GatewayClientError, GatewayRPCError
from hermes_cli.gateway_connection import DISCONNECTED, lost_before
logger = logging.getLogger(__name__)
@@ -529,6 +529,12 @@ class GatewayAgent:
try:
receipt = self.connection.call("prompt.submit", **self._submit_params(
user_message, persist_user_message, turn_author))
+ except GatewayRPCError as exc:
+ # The owner answered and refused: not a lost connection. Only its own site code
+ # (session_busy: send again) is a verdict; any other refusal stays unclassified.
+ busy = str(exc) == "session_busy"
+ return self._failed(history, user_message, str(exc),
+ failure_reason="session_busy" if busy else None, retryable=busy)
except GatewayClientError as exc:
return self._failed(history, user_message, str(exc), failure_reason="gateway_connection")
self._epoch = getattr(self.connection, "epoch", None)
@@ -815,13 +821,13 @@ class GatewayAgent:
return staged
return {"role": "user", "content": user_message}
- def _failed(self, history, user_message, error, *, failure_reason=None):
+ def _failed(self, history, user_message, error, *, failure_reason=None, retryable=False):
"""``failure_reason="gateway_connection"``: the CLI shows ``error`` as written instead of
classifying a lost gateway as a model failure ("Run /model to switch...")."""
out = {**_RESULT_DEFAULTS, "final_response": "", "messages": history + [self._user_row(user_message)],
"failed": True, "completed": False, "error": error, "session_id": self.session_id}
if failure_reason:
- out.update(failure_reason=failure_reason, failure_retryable=False)
+ out.update(failure_reason=failure_reason, failure_retryable=retryable)
return out
def _result(self, history, user_message, complete):
diff --git a/tests/hermes_cli/test_gateway_agent.py b/tests/hermes_cli/test_gateway_agent.py
index e1e34701557..aad541bdd5f 100644
--- a/tests/hermes_cli/test_gateway_agent.py
+++ b/tests/hermes_cli/test_gateway_agent.py
@@ -6,8 +6,8 @@ from contextlib import asynccontextmanager
import pytest
from hermes_cli.gateway_agent import GatewayAgent
-from hermes_cli.gateway_client import GatewayClientError
-from hermes_cli.gateway_connection import GatewayConnection
+from hermes_cli.gateway_client import GatewayClientError, GatewayRPCError
+from hermes_cli.gateway_connection import DISCONNECTED, GatewayConnection
SID = "local-abc"
@@ -659,3 +659,51 @@ def test_fast_tier_reaches_the_session_on_each_rebuild_and_back_to_normal(make_a
assert fast and again and normal
sets = [p["value"] for m, p in client.calls if m == "config.set" and p.get("key") == "service_tier"]
assert sets == ["priority", "normal"]
+
+
+class RefusingClient(FakeClient):
+ """``prompt.submit`` raises ``error`` instead of admitting the turn."""
+
+ def __init__(self, error):
+ super().__init__([])
+ self.error = error
+
+ async def rpc(self, method, *, _timeout=None, **params):
+ if method == "prompt.submit":
+ self.calls.append((method, params))
+ raise self.error
+ return await super().rpc(method, _timeout=_timeout, **params)
+
+
+def submit_against(error):
+ conn = GatewayConnection(connect=connect_with(RefusingClient(error)))
+ conn.start(5)
+ try:
+ return GatewayAgent(connection=conn, session_id=SID).run_conversation("q")
+ finally:
+ conn.close()
+
+
+def test_a_session_busy_refusal_at_submit_is_the_session_busy_verdict():
+ """The owner answered: the session is busy. That is the busy verdict (send again), not a
+ lost gateway connection."""
+ result = submit_against(GatewayRPCError("session_busy"))
+ assert result["failed"] is True and result["completed"] is False
+ assert result["failure_reason"] == "session_busy"
+ assert result["failure_retryable"] is True
+
+
[email protected]("reason", ["permission_denied", "runtime_draining", "invalid_params"])
+def test_other_owner_refusals_at_submit_are_not_a_lost_connection(reason):
+ """A received refusal keeps main's unclassified failed result: no gateway_connection label and
+ no retryability verdict."""
+ result = submit_against(GatewayRPCError(reason))
+ assert result["failed"] is True and result["error"] == reason
+ assert result["failure_reason"] is None
+ assert "failure_retryable" not in result
+
+
+def test_a_transport_loss_at_submit_is_still_gateway_connection():
+ result = submit_against(GatewayClientError(DISCONNECTED))
+ assert result["failed"] is True and result["error"] == DISCONNECTED
+ assert result["failure_reason"] == "gateway_connection" and result["failure_retryable"] is False