Skip to content

The agent that grows with you

fix(cli): send only a typed --provider as launch policy

unsupportedpastels30ef3754c2cd
diff --git a/hermes_cli/cli_init_mixin.py b/hermes_cli/cli_init_mixin.py
index 08814dc1fb9..0c4bcc8fcbf 100644
--- a/hermes_cli/cli_init_mixin.py
+++ b/hermes_cli/cli_init_mixin.py
@@ -27,7 +27,7 @@ _ROUTE_FLAGS = ("model", "provider", "api_key", "base_url")
def _gateway_launch(cli):
"""This run's explicit launch flags as gateway ``session.create`` policy (main handed them to AIAgent)."""
explicit_model = getattr(cli, "_explicit_model_override", False)
- provider = getattr(cli, "requested_provider", None)
+ provider = getattr(cli, "_explicit_provider", None)
return {"model": cli.model if explicit_model else None,
"provider": provider if explicit_model and provider not in {None, "", "auto"} else None,
"api_key": getattr(cli, "_explicit_api_key", None),
@@ -194,6 +194,9 @@ class CLIInitMixin:
_moa_provider_override or provider or _startup_provider_override or _nested_provider
or _cfg_provider or "auto"
)
+ # Only a provider the command line chose is gateway launch policy: the config default is the
+ # gateway's to resolve, and a resume compares launch policy against the session's frozen route.
+ self._explicit_provider = _moa_provider_override or provider or _startup_provider_override or None
# `--provider <custom>` without `-m` uses that entry's default_model, else the global
# default goes to the custom endpoint and the compressor gets the wrong context length.
# Explicit `-m` still wins. See #86978.
diff --git a/tests/hermes_cli/test_gateway_session_store.py b/tests/hermes_cli/test_gateway_session_store.py
index 04840c80475..3f5c65ea01e 100644
--- a/tests/hermes_cli/test_gateway_session_store.py
+++ b/tests/hermes_cli/test_gateway_session_store.py
@@ -544,6 +544,36 @@ def test_explicit_toolsets_on_resume_are_checked_against_the_frozen_route(store)
assert GatewaySessionStore(db.connection).open_session(host, {"toolsets": ["web"]}) == "local-old"
+def test_unchanged_model_flag_on_resume_ignores_the_configured_provider(store, monkeypatch):
+ """CLI-2: `--resume <id> -m my-model` repeats the session's frozen `-m` while the CLI resolved the
+ profile's provider; only a `--provider` the user typed is launch policy, so the repeat is accepted
+ (as the thin client accepts it) and a different `--provider` is still refused."""
+ import cli as cli_module
+ from hermes_cli.cli_init_mixin import CLIInitMixin
+ monkeypatch.setitem(cli_module.CLI_CONFIG, "model", {"default": "cfg-model", "provider": "openrouter"})
+ db, client = store
+ _frozen_launch(client, {"model": "my-model"})
+
+ def host(provider=None, resumed=True):
+ h = types.SimpleNamespace(session_id="local-old", _resumed=resumed, enabled_toolsets=["file"],
+ _session_db=GatewaySessionStore(db.connection))
+ CLIInitMixin._init_model_and_provider(h, "my-model", provider, None, None)
+ return h
+
+ repeat = host()
+ assert repeat.requested_provider == "openrouter"
+ CLIInitMixin._ensure_gateway_session(repeat)
+ assert repeat.session_id == "local-old"
+ with pytest.raises(GatewayClientError, match="Resume retains gateway session policy"):
+ CLIInitMixin._ensure_gateway_session(host("anthropic"))
+ # Creation sends a typed --provider with -m, and leaves the configured one to the gateway.
+ CLIInitMixin._ensure_gateway_session(host("anthropic", resumed=False))
+ assert [p for m, p in client.calls if m == "session.create"][-1]["provider"] == "anthropic"
+ CLIInitMixin._ensure_gateway_session(host(resumed=False))
+ created = [p for m, p in client.calls if m == "session.create"][-1]
+ assert created["model"] == "my-model" and "provider" not in created, created
+
+
def test_new_session_keeps_the_runs_launch_policy(store, monkeypatch):
"""CLI-3: `/new` keeps `--max-turns`, `--checkpoints`, `--run-budget`, `-v` and `-s` (main kept one
AIAgent across /new); only the explicit model route is left to the profile default."""