The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(cli): let persist_switch_by_default cover provider-scoped model picks
ahisblessed4ec2e50b3cff
diff --git a/hermes_cli/model_switch.py b/hermes_cli/model_switch.pyindex 1f072830c80..2bd402c2d4f 100644--- a/hermes_cli/model_switch.py+++ b/hermes_cli/model_switch.py@@ -514,17 +514,14 @@ def resolve_persist_behavior(Order: ``--once`` / ``--session`` -> False; ``--global`` -> True; no default configured yet(neither ``model.default`` nor ``model.provider`` — a fresh install's first pick) -> True, sothe pick does not evaporate into whatever ``*_API_KEY`` is lying around on the next launch;- ``--provider`` without a persist flag -> False (exploratory); else- ``model.persist_switch_by_default`` (default False). A flat-string ``model`` IS a configured+ ``model.persist_switch_by_default`` -> True (the user's explicit opt-in to persistence);+ ``--provider`` without a persist flag -> False (exploratory). A flat-string ``model`` IS a configureddefault; an unreadable config -> False.1. ``--once`` explicitly opts out → ``False`` (next turn only). 2. ``--session`` explicitly opts out →``False`` (this session only). 3. 4. Applies to every surface (CLI, gateway, Desktop picker) so no- client has to hardcode ``--global``. 5. Provider switches are typically exploratory — the user is trying- a different backend for this conversation, not reconfiguring the default. 6. Otherwise defer to- ``model.persist_switch_by_default`` in ``config.yaml`` (defaults to ``False``: a plain ``/model <name>``- affects only the current session). Users who want the old persist-by-default behavior can set the key to- ``true``; a one-off ``--global`` always persists. See #86414.+ client has to hardcode ``--global``. 5. ``model.persist_switch_by_default: true`` also covers provider picks (a pick between two providers sharing one ``base_url`` is tenant selection on the same backend, not exploration;+ session-scoping it silently serves the next chat with the other twin's key). 6. Without that opt-in, provider switches stay exploratory — the user is trying a different backend for this conversation, not reconfiguring the default. The key defaults to ``False`` (a plain ``/model <name>`` affects only the current session); users who want the old persist-by-default behavior can set it to ``true``; a one-off ``--global`` always persists, and ``--session`` / ``--once`` always opt out. See #86414."""if is_once or is_session:return False@@ -538,9 +535,11 @@ def resolve_persist_behavior(if isinstance(model_cfg, dict):if not (model_cfg.get("default") or model_cfg.get("provider")):return True+ if bool(model_cfg.get("persist_switch_by_default", False)):+ return Trueif explicit_provider:return False- return bool(model_cfg.get("persist_switch_by_default", False))+ return Falsereturn not model_cfgdiff --git a/tests/hermes_cli/test_model_switch_persist_default.py b/tests/hermes_cli/test_model_switch_persist_default.pyindex ce2c78bc42a..6826e1969f3 100644--- a/tests/hermes_cli/test_model_switch_persist_default.py+++ b/tests/hermes_cli/test_model_switch_persist_default.py@@ -30,6 +30,29 @@ class TestResolvePersistBehavior:with _config({"model": {"persist_switch_by_default": True}}):assert resolve_persist_behavior(False, False, explicit_provider="") is True+ def test_provider_pick_honors_persist_switch_by_default(self):+ # #123150: with twin providers sharing one base_url, an explicit provider pick+ # selects a tenant/account on the same backend. Scoping it to the session by+ # default silently serves the next chat with the other twin's key, so the+ # user's persist opt-in must cover provider picks too.+ cfg = {"model": {"default": "agnes-3.0-flash", "provider": "custom:family-snowflake",+ "persist_switch_by_default": True}}+ with _config(cfg):+ assert resolve_persist_behavior(False, False, explicit_provider="custom:family-xizhao") is True+ # --session / --once remain the explicit opt-outs.+ assert resolve_persist_behavior(False, True, explicit_provider="custom:family-xizhao") is False+ assert resolve_persist_behavior(False, False, is_once=True,+ explicit_provider="custom:family-xizhao") is False+ # --global still persists.+ assert resolve_persist_behavior(True, False, explicit_provider="custom:family-xizhao") is True++ def test_provider_pick_stays_exploratory_without_the_flag(self):+ # The exploratory default is unchanged unless the user opts in.+ cfg = {"model": {"default": "agnes-3.0-flash", "provider": "custom:family-snowflake"}}+ with _config(cfg):+ assert resolve_persist_behavior(False, False, explicit_provider="custom:family-xizhao") is False+ assert resolve_persist_behavior(False, False, explicit_provider="") is False+def test_first_pick_persists_then_session_only(self):# #90235 / #86414: the ONE policy every surface (CLI, gateway, Desktop# picker) defers to. With no default ever configured, the first pick