Skip to content

The agent that grows with you

fix(cli): commit a session /reasoning pick once, not on every agent rebuild

Teknium98892786718a
diff --git a/hermes_cli/cli_agent_setup_mixin.py b/hermes_cli/cli_agent_setup_mixin.py
index f2fb0505156..2b3d42f37ff 100644
--- a/hermes_cli/cli_agent_setup_mixin.py
+++ b/hermes_cli/cli_agent_setup_mixin.py
@@ -731,6 +731,10 @@ class CLIAgentSetupMixin:
except Exception:
pass
self._active_agent_route_signature = _route_signature(effective_model, runtime)
+ if getattr(self.agent, "reasoning_pushed", False):
+ # The session holds the pick now; later rebuilds (/fast, /personality, a route change)
+ # must not re-commit it (a resume, a prepare+commit, a receipt, an agent eviction each).
+ self._reasoning_user_set = False
# Force-create DB row on /title intent, then apply title.
if self._pending_title and self._session_db:
diff --git a/hermes_cli/gateway_agent.py b/hermes_cli/gateway_agent.py
index 9e3a1e5744b..fefcc734e29 100644
--- a/hermes_cli/gateway_agent.py
+++ b/hermes_cli/gateway_agent.py
@@ -164,8 +164,10 @@ class GatewayAgent:
self._reasoning_config = None
# Only a user-picked effort (/reasoning, a model pick's --reasoning) is committed at build; the
# config-resolved level must never override the session's frozen launch policy on resume.
+ # ``reasoning_pushed``: the commit landed, so the CLI stops re-sending it on every later rebuild.
+ self.reasoning_pushed = False
if push_reasoning:
- self.pin_reasoning(reasoning_config)
+ self.reasoning_pushed = self.pin_reasoning(reasoning_config)
else:
self._reasoning_config = reasoning_config
# Main's /moa rebuilds its agent on the MoA virtual provider for one turn (the session's info
@@ -221,8 +223,8 @@ class GatewayAgent:
def pin_reasoning(self, config):
"""``/reasoning <level>`` (session scope; main rebuilds its agent with the new config) and a model
pick's ``--reasoning``: always ``session.mutate reasoning``, even when the session already runs that
- level by inheritance, so it becomes the session's own choice."""
- self._set_reasoning(config, explicit=True)
+ level by inheritance, so it becomes the session's own choice. True when the owner committed it."""
+ return self._set_reasoning(config, explicit=True)
def stage_turn_reasoning(self, config):
"""``/model B --once --reasoning X``: X for the one-turn admission only (its ``model_override``).
@@ -239,10 +241,10 @@ class GatewayAgent:
self._reasoning_config = config
effort = _effort_word(config)
if effort is None:
- return
+ return False
info = self._state().info or {}
if not explicit and info.get("reasoning_effort") == effort:
- return
+ return True
try:
snapshot = self.connection.call("session.resume", session_id=self.session_id)
# A policy mutation is generation-fenced: the owner refuses it without the generation.
@@ -251,8 +253,10 @@ class GatewayAgent:
expected_generation=snapshot["execution_generation"], operation="reasoning",
payload={"effort": effort})
info["reasoning_effort"] = effort
+ return True
except (GatewayClientError, KeyError, TypeError) as exc:
logger.debug("session.mutate reasoning failed: %s", exc)
+ return False
def _route_off_session(self, model, provider=""):
"""``{model, provider}`` when the session runs another route, else None."""
diff --git a/tests/hermes_cli/test_cli_gateway_model_scope.py b/tests/hermes_cli/test_cli_gateway_model_scope.py
index 4627287bec0..e6c1f9bb8b9 100644
--- a/tests/hermes_cli/test_cli_gateway_model_scope.py
+++ b/tests/hermes_cli/test_cli_gateway_model_scope.py
@@ -386,3 +386,20 @@ def test_an_image_staging_failure_is_a_failed_turn_not_an_exception():
result = agent.run_conversation(parts)
assert (result.get("failed"), result.get("failure_reason")) == (True, "gateway_connection"), result
assert not _submits(conn)
+
+
+def test_a_session_reasoning_pick_is_committed_once_not_on_every_rebuild(monkeypatch):
+ """Review of #140969: ``_reasoning_user_set`` never cleared after the commit, so every later agent
+ rebuild (``/fast``, ``/personality``, a route change, a --once restore) re-sent the explicit level: a
+ full ``session.resume``, a prepare+commit, a receipt and a gateway agent eviction each time."""
+ from hermes_cli.cli_agent_setup_mixin import _retire_agent
+ conn = RecordingConnection({"model": "old/model", "provider": "openrouter"})
+ _cli_mod, stub, _printed = _chat_cli(monkeypatch, conn)
+ stub.agent = None
+ stub.reasoning_config = {"enabled": True, "effort": "high"}
+ stub._reasoning_user_set = True # ``/reasoning high`` (cli_commands_mixin) then retires the agent
+ assert stub.chat("first") == "ok"
+ _retire_agent(stub) # e.g. /personality
+ assert stub.chat("second") == "ok"
+ assert _reasoning_mutates(conn) == [{"effort": "high"}]
+ assert stub._reasoning_user_set is False