The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
refactor(cli): keep the session.resume refusal sets in one place
kshitijk4poor6513b97f1162
diff --git a/hermes_cli/cli_session_switch.py b/hermes_cli/cli_session_switch.pyindex eba036395f6..8e5d6e7294a 100644--- a/hermes_cli/cli_session_switch.py+++ b/hermes_cli/cli_session_switch.py@@ -7,11 +7,7 @@ from __future__ import annotationsfrom contextlib import suppress-from hermes_cli.gateway_session_store import RESUME_REFUSALS--# session.resume refusals that keep the chat on its current session (startup resume's set plus-# profile_mismatch, which restore_local_session raises for another profile's receipt).-_SWITCH_REFUSALS = RESUME_REFUSALS | {'profile_mismatch'}+from hermes_cli.gateway_connection import RESUME_GONEdef _end_current_session(cli, reason: str) -> None:@@ -48,7 +44,7 @@ def _open_switched_session(cli, session_id: str) -> str | None:except GatewayRPCError as exc:# The owner answered: only an ownership refusal stops the switch.reason = str(exc)- return reason if reason in _SWITCH_REFUSALS else None+ return reason if reason in RESUME_GONE else Noneexcept GatewayClientError:# No answer (unavailable, disconnected, timeout). The switch's reads are local, so it# proceeds as before; the turn reports the lost connection itself.diff --git a/hermes_cli/gateway_connection.py b/hermes_cli/gateway_connection.pyindex a5f070f5378..f52a9dede8d 100644--- a/hermes_cli/gateway_connection.py+++ b/hermes_cli/gateway_connection.py@@ -24,8 +24,12 @@ DISCONNECTED = ("Gateway disconnected; turn outcome is unknown. Resume the print"whether it completed or was interrupted; do not resend the work.")# A request refused before it reached any socket: nothing is in doubt, so never the copy above.NOT_SENT = "Gateway disconnected before the request was sent; nothing was sent."-# Resume refusals meaning the session itself is gone for this viewer (gateway/session_controls).-_GONE = frozenset({"not_found", "permission_denied", "profile_mismatch"})+# ``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 (startup resume).+RESUME_REFUSALS = frozenset({"not_found", "permission_denied"})+# Resume refusals meaning the session itself is gone for this viewer (gateway/session_controls): the+# above plus profile_mismatch, raised for another profile's session (reconnect, /resume switch).+RESUME_GONE = RESUME_REFUSALS | {"profile_mismatch"}# Keyed-resume refusals a plain resume answers as main did: the key does not apply to this session# (``rebind_launch_key``: keyless or non-local, another key held, another fingerprint), or the viewer# lacks the ``session:control`` a rebind needs but may still read. Any other refusal is the resume's.@@ -297,7 +301,7 @@ class GatewayConnection:try:state.adopt_snapshot(await self._resume(client, session_id))except GatewayClientError as exc:- if str(exc) not in _GONE:+ if str(exc) not in RESUME_GONE:raiselogger.debug("session.resume %s after reconnect: %s", session_id, exc)state.subscription_id = Nonediff --git a/hermes_cli/gateway_session_store.py b/hermes_cli/gateway_session_store.pyindex e05b9348291..70c3662825a 100644--- a/hermes_cli/gateway_session_store.py+++ b/hermes_cli/gateway_session_store.py@@ -23,7 +23,7 @@ import sysimport uuidfrom hermes_cli.gateway_client import GatewayClientError-from hermes_cli.gateway_connection import GatewayConnection+from hermes_cli.gateway_connection import RESUME_REFUSALS, GatewayConnectionlogger = logging.getLogger(__name__)@@ -45,9 +45,6 @@ _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")