Skip to content

The agent that grows with you

fix(cli): quit and session switches end the gateway row with main's end_reason

Teknium591deb0ae1fc
diff --git a/hermes_cli/gateway_session_store.py b/hermes_cli/gateway_session_store.py
index 22811c4d372..f0a014ff41d 100644
--- a/hermes_cli/gateway_session_store.py
+++ b/hermes_cli/gateway_session_store.py
@@ -214,14 +214,18 @@ class GatewaySessionStore:
return True
def end_session(self, session_id, reason=None):
- """Detach this viewer; the gateway ends an idle session itself."""
+ """Main's ``end_session(sid, reason)``: detach this viewer with ``end_reason``; the owner ends
+ the idle local row with that reason once no viewer is left (``ended_at`` / ``end_reason``)."""
snapshot = self.snapshots.pop(session_id, None)
subscription = (snapshot or {}).get("subscription_id")
if subscription and not self.connection.closed:
+ params = {"end_reason": reason} if reason else {}
try:
- self.call("session.detach", session_id=session_id, subscription_id=subscription)
+ self.call("session.detach", session_id=session_id, subscription_id=subscription, **params)
except GatewayClientError as exc:
logger.debug("session.detach failed: %s", exc)
+ if self.current is snapshot:
+ self.current = None
def delete_session_if_empty(self, session_id, sessions_dir=None):
"""Main's quit-immediately prune, as a gateway delete: only a row with no messages, no title
diff --git a/tests/hermes_cli/test_gateway_session_store.py b/tests/hermes_cli/test_gateway_session_store.py
index daa544dc9e6..cc54522ccbb 100644
--- a/tests/hermes_cli/test_gateway_session_store.py
+++ b/tests/hermes_cli/test_gateway_session_store.py
@@ -104,7 +104,8 @@ def test_title_rename_delete_and_detach_are_gateway_verbs(store):
assert mutate["expected_revision"] == 3
assert db.connection.state("local-old").title == "Some Title"
db.end_session("local-old", "cli_close")
- assert client.calls[-1] == ("session.detach", {"session_id": "local-old", "subscription_id": "sub-local-old"})
+ assert client.calls[-1] == ("session.detach", {"session_id": "local-old", "subscription_id": "sub-local-old",
+ "end_reason": "cli_close"})
db.delete_session("local-old")
assert [p for m, p in client.calls if m == "session.mutate"][-1]["operation"] == "delete"