The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(cli): send a --once pick through an alias named like the session model
David Dudok de Wit32c0948bc667
diff --git a/hermes_cli/gateway_agent.py b/hermes_cli/gateway_agent.pyindex 0e92f1d99bb..33521163379 100644--- a/hermes_cli/gateway_agent.py+++ b/hermes_cli/gateway_agent.py@@ -649,10 +649,14 @@ class GatewayAgent:def _take_turn_route(self):"""The ``/model --once`` pick for the admission being built, consumed here: one admission carriesit, even when a later ``run_conversation`` submits while this one's ``prompt.submit`` still blocks.- A refusal that admitted nothing (``session_busy``) puts it back with ``_give_back_turn_route``."""+ A refusal that admitted nothing (``session_busy``) puts it back with ``_give_back_turn_route``.++ Staging already compared the pick with the session's route (``_route_off_session``), so it is not+ compared again: its ``model`` may be an alias spelled like the session's model, and the owner runs a+ plain pick of the session's own route on the session's endpoint and key (``one_turn_runtime``)."""pending, reasoning = self._turn_route, self._turn_reasoningself._turn_route = self._turn_reasoning = self._taken_turn_route = None- if not pending or not self._route_off_session(**pending):+ if not pending:return Noneself._taken_turn_route = (pending, reasoning)return {**pending, **({"reasoning": reasoning} if reasoning else {})}diff --git a/tests/hermes_cli/test_cli_gateway_model_scope.py b/tests/hermes_cli/test_cli_gateway_model_scope.pyindex 41eb7de0b4d..43c48601cd7 100644--- a/tests/hermes_cli/test_cli_gateway_model_scope.py+++ b/tests/hermes_cli/test_cli_gateway_model_scope.py@@ -321,6 +321,41 @@ def test_once_sends_the_alias_it_resolved_through(monkeypatch, session_model):assert not _model_routes(conn)[0]+def test_once_through_an_alias_named_like_the_session_model_still_sends_it(monkeypatch):+ """Review by @dokterdok: the session runs ``shared-model`` on its own endpoint and key, and a+ ``model_aliases`` entry ``shared-model`` names that model at another endpoint. ``/model shared-model+ --once`` resolves the alias, but the submit compared the staged ``shared-model`` with the session's+ route again, dropped it, and the turn ran on the session's endpoint and key."""+ from gateway.session_cli_turn import one_turn_runtime+ from hermes_cli import model_switch+ resolve = model_switch.switch_model+ conn = RecordingConnection({"model": "shared-model", "provider": "custom"})+ cli_mod, stub, printed = _chat_cli(monkeypatch, conn)+ monkeypatch.setattr(model_switch, "switch_model", resolve) # the real resolver over this alias+ monkeypatch.setitem(model_switch.DIRECT_ALIASES, "shared-model", model_switch.DirectAlias(+ model="shared-model", provider="custom", base_url="http://127.0.0.1:7003/v1", api_key="sk-alias"))+ monkeypatch.setattr("hermes_cli.models_validate.validate_requested_model", lambda *_a, **_k: {+ "accepted": True, "persist": True, "recognized": True, "message": ""})+ monkeypatch.setattr("agent.models_dev.fetch_models_dev", dict)+ session = {"provider": "custom", "api_key": "sk-session", "base_url": "http://127.0.0.1:7001/v1"}+ stub.model, stub.provider, stub.requested_provider = "shared-model", "custom", "custom"+ stub.base_url = stub._explicit_base_url = session["base_url"]+ stub.api_key = stub._explicit_api_key = session["api_key"]+ stub.agent.model, stub.agent.provider = "shared-model", "custom"+ cli_mod.HermesCLI._handle_model_switch(stub, "/model shared-model --once")+ assert not [line for line in printed if "fail" in line.lower()], printed+ assert stub.base_url == "http://127.0.0.1:7003/v1", "the CLI shows the alias's endpoint"+ stub.chat("run on the alias")+ stub.chat("the turn after")+ once, after = _submits(conn)+ override = once.get("model_override")+ assert override == {"model": "shared-model", "provider": "custom"}, once+ assert "model_override" not in after, after+ _model, runtime = one_turn_runtime(override, "shared-model", {**session, "api_mode": "chat_completions"}, {})+ assert (runtime["base_url"], runtime["api_key"]) == ("http://127.0.0.1:7003/v1", "sk-alias")+ assert not _model_routes(conn)[0]++class BusyOnceConnection(RecordingConnection):"""The owner refuses the first ``prompt.submit`` with ``session_busy``: nothing was admitted."""