The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(gateway): publish a one-turn session's model and provider from one profile read
Teknium1db4d6618b6e
diff --git a/gateway/session_local_inventory.py b/gateway/session_local_inventory.pyindex ae9bbb44a06..271b8752230 100644--- a/gateway/session_local_inventory.py+++ b/gateway/session_local_inventory.py@@ -227,8 +227,8 @@ def publish_settled_info(turn, agent) -> None:A ``model_override`` admission (``/model --once``, ``/moa``) built its agent on the one-turnroute. That agent must not become the route Desktop, the TUI, and resume read. Drop it from- the cache (released once this turn's running slot clears) and publish the policy model and- provider."""+ the cache (released once this turn's running slot clears) and publish the model and provider+ of the policy route, both from one read of the profile."""if agent is None:returnwith contextlib.suppress(Exception):@@ -259,7 +259,9 @@ def publish_settled_info(turn, agent) -> None:logger.debug("one-turn policy route unavailable", exc_info=True)policy = Noneif policy is not None:- info["model"] = policy.current_model(authority)- if policy.provider:- info["provider"] = policy.provider+ config, info["model"] = policy.effective(authority, secrets=False)+ section = config.get("model")+ provider = section.get("provider") if isinstance(section, dict) else None+ if provider:+ info["provider"] = providerturn._publish_execution("session.info", info)diff --git a/tests/gateway/test_one_turn_route_publish.py b/tests/gateway/test_one_turn_route_publish.pyindex ba0c1e4f7d0..adb86d6f98f 100644--- a/tests/gateway/test_one_turn_route_publish.py+++ b/tests/gateway/test_one_turn_route_publish.py@@ -9,7 +9,8 @@ from hermes_cli.model_switch import ModelSwitchResultdef test_settled_info_publishes_the_policy_route_and_drops_the_cached_agent(monkeypatch):from gateway.session_local_inventory import publish_settled_infopublished, evicted = [], []- policy = SimpleNamespace(current_model=lambda _authority: "session-model", provider="openrouter", source="cli")+ policy = SimpleNamespace(effective=lambda _authority, secrets=True: (+ {"model": {"provider": "openrouter"}}, "session-model"), source="cli")live = SimpleNamespace(route="route-1", source=SimpleNamespace())authority = SimpleNamespace(profile_id="p", sessions={"s": live})turn = SimpleNamespace(@@ -122,7 +123,7 @@ def test_a_one_turn_agent_is_released_once_its_running_slot_clears(monkeypatch):turn = SimpleNamespace(_ctx=SimpleNamespace(inbound_message_id="adm", session_key=route),_approval_owner=(authority, "s", 1), _runner=runner,_publish_execution=lambda kind, payload: published.append(payload))- policy = SimpleNamespace(current_model=lambda _a: "session-model", provider="openrouter")+ policy = SimpleNamespace(effective=lambda _a, secrets=True: ({"model": {"provider": "openrouter"}}, "session-model"))monkeypatch.setattr(session_local, "local_session_info", lambda *_a, **_k: {"model": "once-model"})monkeypatch.setattr(session_policy, "policy_for_source", lambda *_a, **_k: policy)@@ -138,3 +139,33 @@ def test_a_one_turn_agent_is_released_once_its_running_slot_clears(monkeypatch):assert wait_until(released.is_set, timeout=5, what="the one-turn agent was released")assert agent.release_clients.call_count == 1++def test_settled_info_pairs_model_and_provider_from_one_profile_read(monkeypatch):+ """Review of #140969: ``policy.provider`` read the frozen config while ``current_model`` followed+ the profile, so a following Bot Chat whose profile moved published the new model with the old+ provider."""+ from gateway import session_local, session_policy+ from gateway.session_local_inventory import publish_settled_info+ published = []++ class _Policy:+ provider = "anthropic" # the frozen config's++ def effective(self, _authority, *, secrets=True):+ assert secrets is False+ return {"model": {"provider": "openrouter", "default": "openai/gpt-b"}}, "openai/gpt-b"++ def current_model(self, _authority):+ return "openai/gpt-b"++ live = SimpleNamespace(route="route-1", source=SimpleNamespace())+ authority = SimpleNamespace(profile_id="p", sessions={"s": live})+ turn = SimpleNamespace(_ctx=SimpleNamespace(inbound_message_id="adm"), _approval_owner=(authority, "s", 1),+ _runner=SimpleNamespace(), _publish_execution=lambda kind, payload: published.append(payload))+ agent = SimpleNamespace(model="once-model", provider="nous", tools=None, _cached_system_prompt="",+ context_compressor=None)+ monkeypatch.setattr(session_local, "local_session_info", lambda *_a, **_k: {"model": "once-model", "provider": "nous"})+ monkeypatch.setattr(session_policy, "policy_for_source", lambda *_a, **_k: _Policy())+ with cli_turn_scope("adm", {"model_override": {"model": "once-model", "provider": "nous"}}):+ publish_settled_info(turn, agent)+ assert (published[-1]["model"], published[-1]["provider"]) == ("openai/gpt-b", "openrouter")