The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(acp): retain provider identity in gateway model picks
funky-xamarin80fd5d70fbf1
diff --git a/acp_adapter/gateway_server.py b/acp_adapter/gateway_server.pyindex f1075b94aec..c66c02ba0fe 100644--- a/acp_adapter/gateway_server.py+++ b/acp_adapter/gateway_server.py@@ -440,7 +440,10 @@ class GatewayACPAgent(GatewayReplyMixin, acp.Agent):from acp.schema import SetSessionModelResponsesession_id = self._aliases.get(session_id, session_id)client = await self._client()- payload = {'model': model_id}+ from hermes_cli.models import parse_model_input+ # Picker IDs include the provider, as on the in-process ACP switch path.+ provider, model = await asyncio.to_thread(parse_model_input, model_id, '')+ payload = {'model': model, **({'provider': provider} if provider else {})}self._unacked.pop(session_id, None) # a control between a lost submit and its repeat retires itresult = await self._mutations.apply(client, session_id, 'model', payload,confirm=self._model_confirmer(session_id))diff --git a/tests/acp_adapter/test_gateway_model_provider.py b/tests/acp_adapter/test_gateway_model_provider.pynew file mode 100644index 00000000000..d52a2d05ed4--- /dev/null+++ b/tests/acp_adapter/test_gateway_model_provider.py@@ -0,0 +1,71 @@+"""Regression for #139165: ACP picker identity reaches canonical model mutations."""+import pytest++from acp_adapter.gateway_server import GatewayACPAgent+++ "model_id, expected",+ [+ ("deepseek:deepseek-flash", {"provider": "deepseek", "model": "deepseek-flash"}),+ ("openrouter:deepseek/example", {"provider": "openrouter", "model": "deepseek/example"}),+ ("anthropic/claude-example:beta", {"model": "anthropic/claude-example:beta"}),+ ("plain-model", {"model": "plain-model"}),+ ("", {"model": ""}),+ ("custom:fixture:local-model:tag", {"provider": "custom:fixture", "model": "local-model:tag"}),+ ],+)+async def test_picker_identity_reaches_prepared_mutation(model_id, expected, tmp_path, monkeypatch):+ monkeypatch.setenv("HERMES_HOME", str(tmp_path))+ (tmp_path / "config.yaml").write_text(+ 'custom_providers:\n - name: fixture\n base_url: http://127.0.0.1:9/v1\n',+ encoding="utf-8",+ )+ agent = GatewayACPAgent()+ calls = []++ class RPC:+ async def rpc(self, method, **params):+ calls.append((method, params))+ if method == "session.resume":+ return {"execution_generation": 3, "revision": 7}+ assert method == "session.mutate"+ return {"status": "applied"}++ agent._gateway = RPC()+ agent._aliases["editor-tip"] = "logical-session"+ await agent.set_session_model(model_id=model_id, session_id="editor-tip")+ mutation = next(params for method, params in calls if method == "session.mutate")+ assert mutation["payload"] == expected+ assert mutation["session_id"] == "logical-session"+ assert mutation["expected_generation"] == 3+ assert mutation["expected_revision"] == 7+ assert agent._mutations.pending == {}++[email protected]("reason", ["connection_lost", "session_busy"])+async def test_prefixed_pick_preserves_mutation_failure_contract(reason):+ from hermes_cli.gateway_client import GatewayClientError++ agent = GatewayACPAgent()+ calls = []++ class RPC:+ async def rpc(self, method, **params):+ if method == "session.resume":+ return {"execution_generation": 3, "revision": 7}+ calls.append(params)+ if len(calls) == 1:+ raise GatewayClientError(reason)+ return {"status": "applied"}++ agent._gateway = RPC()+ with pytest.raises(GatewayClientError, match=reason):+ await agent.set_session_model(model_id="deepseek:example", session_id="session")+ assert "session" not in agent._snapshots+ await agent.set_session_model(model_id="deepseek:example", session_id="session")+ assert calls[0]["payload"] == calls[1]["payload"] == {"provider": "deepseek", "model": "example"}+ assert (calls[0]["request_id"] == calls[1]["request_id"]) == (reason == "connection_lost")+ assert agent._mutations.pending == {}