Skip to content

The agent that grows with you

fix(cli): refuse a /resume switch the gateway answers with not_found

kshitijk4poor586c578cb40a
diff --git a/hermes_cli/cli_session_switch.py b/hermes_cli/cli_session_switch.py
index 3baf4a6adc4..9c6b5364df5 100644
--- a/hermes_cli/cli_session_switch.py
+++ b/hermes_cli/cli_session_switch.py
@@ -7,12 +7,16 @@ from __future__ import annotations
from contextlib import suppress
-# A gateway that answers with one of these has refused this viewer for the target session
-# (ownership, profile), so the switch must not move the chat onto it. Every other reason it can
+from hermes_cli.gateway_session_store import RESUME_REFUSALS
+
+# A gateway that answers one of these has refused this viewer the target session, so the switch
+# must not move the chat onto it. Every other reason it can
# answer (session_busy, runtime_coordination_required, storage_unavailable, unknown_execution,
-# admission_conflict, stale_generation, runtime_draining, not_found) is transient or
+# admission_conflict, stale_generation, runtime_draining) is transient or
# ownership-free: the switch proceeds as it always did and the turn reports what is left.
-_SWITCH_REFUSALS = frozenset({'permission_denied', 'profile_mismatch'})
+# Startup resume's set plus profile_mismatch (``restore_local_session`` raises it for a receipt
+# from another profile).
+_SWITCH_REFUSALS = RESUME_REFUSALS | {'profile_mismatch'}
def _end_current_session(cli, reason: str) -> None:
diff --git a/hermes_cli/gateway_session_store.py b/hermes_cli/gateway_session_store.py
index 66daacf4b38..e05b9348291 100644
--- a/hermes_cli/gateway_session_store.py
+++ b/hermes_cli/gateway_session_store.py
@@ -45,6 +45,9 @@ _GATEWAY_OWNED = frozenset({
# Mutations the owner refuses without the execution generation they were read at (hermes_state_runtime).
_GENERATION_FENCED = frozenset({"delete", "rewind", "reset", "branch", "model", "compress"})
_COUNTED_REPAIRS = frozenset({"prune_empty_ghost_sessions", "finalize_orphaned_compression_sessions"})
+# ``session.resume`` refusals that mean "this viewer may not open that session": the caller keeps the
+# session it is on instead of adopting the target.
+RESUME_REFUSALS = frozenset({"not_found", "permission_denied"})
# Launch options main's ``cli.main`` takes that are creation policy on the gateway session.
_LAUNCH_POLICY = ("model", "provider", "toolsets", "reasoning", "api_key", "base_url", "max_turns",
"ignore_rules", "checkpoints", "pass_session_id", "skills")
@@ -142,7 +145,7 @@ class GatewaySessionStore:
try:
snapshot = self.attach(cli.session_id, typed=self.connection.launch_api_key_typed)
except GatewayClientError as exc:
- if str(exc) in {"not_found", "permission_denied"}:
+ if str(exc) in RESUME_REFUSALS:
return None
raise
# The CLI sends a coding-posture toolset pick and an env-folded ignore_rules too; only a typed