Skip to content

The agent that grows with you

refactor(cli): open the /resume target once and fix the switch comments

kshitijk4poorfde167f6e5b6
diff --git a/hermes_cli/cli_commands_mixin.py b/hermes_cli/cli_commands_mixin.py
index de76b833347..24037bd63f7 100644
--- a/hermes_cli/cli_commands_mixin.py
+++ b/hermes_cli/cli_commands_mixin.py
@@ -882,17 +882,13 @@ class CLICommandsMixin(CLICommandsSessionToolsMixin):
if (kanban_refusal := kanban_resume_refusal(self._session_db, target_id)):
return _cp(f" {kanban_refusal}")
read_id, target_id = target_id, _gateway_owned_id(self._session_db, target_id) # the receipt owner
- if target_id == self.session_id:
- # Already on it: a launch whose attach was refused lands here without a subscription,
- # so open it before reporting.
- if (refusal := _open_switched_session(self, target_id)):
- return _cp(f" {_gt('resume.switch_failed')} {target_id} ({refusal})")
- return _cp(f" {_t('resume.already_on')}")
- # A switched-to session must be subscribed on this viewer before its first turn
- # (``_open_switched_session``): the write side is the gateway's, and /resume can land
- # before any agent exists.
+ # Subscribe the target on this viewer before anything changes: the write side is the
+ # gateway's and /resume can land before any agent exists (also covers already-on after a
+ # refused launch attach). The agent setter's later attach is free: attach caches per id.
if (refusal := _open_switched_session(self, target_id)):
return _cp(f" {_gt('resume.switch_failed')} {target_id} ({refusal})")
+ if target_id == self.session_id:
+ return _cp(f" {_t('resume.already_on')}")
old_session_id = self.session_id
_end_current_session(self, "resumed_other")
self.session_id, self._resumed, self._pending_title = target_id, True, None
diff --git a/hermes_cli/cli_session_switch.py b/hermes_cli/cli_session_switch.py
index 9c6b5364df5..eba036395f6 100644
--- a/hermes_cli/cli_session_switch.py
+++ b/hermes_cli/cli_session_switch.py
@@ -9,13 +9,8 @@ from contextlib import suppress
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) is transient or
-# ownership-free: the switch proceeds as it always did and the turn reports what is left.
-# Startup resume's set plus profile_mismatch (``restore_local_session`` raises it for a receipt
-# from another profile).
+# 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'}
@@ -79,19 +74,7 @@ def _sync_agent_to_session(cli, session_id: str, *, parent_session_id: str, reas
cli.agent._invalidate_system_prompt()
with suppress(Exception):
_mm = getattr(cli.agent, "_memory_manager", None)
- # Notify memory providers that session_id rotated to a fresh conversation. reset=True signals
- # providers to flush accumulated per-session state (_session_turns, _turn_counter, _document_id).
- # Fires BEFORE the plugin on_session_reset hook (shell hooks only see the new id; Python providers
- # see the transition). See #6672. When the old session has history, end-of-session extraction
- # (LLM-bound, seconds) and this switch are queued as ONE task on the memory manager's serialized
- # worker — end strictly before switch, without blocking /new (#16454). With no history there is
- # nothing to extract; switch inline as before.
- # Notify memory providers that session_id rotated to a resumed session. reset=False — the provider's
- # accumulated state is still valid; it just needs to target the new session_id for subsequent
- # writes. See #6672.
- # Notify memory providers that session_id forked to a new branch. reset=False — the branched session
- # carries the transcript forward, so provider state tracks the lineage. parent_session_id links the
- # branch back to the original. See #6672.
+ # reset=False: provider state follows the new id; parent_session_id keeps lineage (#6672).
if _mm is not None:
_mm.on_session_switch(
session_id, parent_session_id=parent_session_id or "", reset=False, reason=reason)