The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(auxiliary): MiniMax OAuth route keeps third-party wire contract
Brooklyn Nicholson70d6e8356332
diff --git a/agent/auxiliary_client.py b/agent/auxiliary_client.pyindex 0f1e5474e7f..f1db973d12b 100644--- a/agent/auxiliary_client.py+++ b/agent/auxiliary_client.py@@ -5406,6 +5406,7 @@ def _resolve_registry_branch(req: _ResolveRequest) -> _ResolveResult:# (tokens live ~15 min; the Anthropic SDK re-invokes the provider each request).try:from agent.anthropic_adapter import build_anthropic_client+ from agent.anthropic_credentials import anthropic_route_is_oauthfrom hermes_cli.auth import resolve_minimax_oauth_runtime_credentialsexcept ImportError:return None, None@@ -5428,7 +5429,12 @@ def _resolve_registry_branch(req: _ResolveRequest) -> _ResolveResult:real_client = build_anthropic_client(token_provider, base_url)except ImportError:return None, None- client = AnthropicAuxiliaryClient(real_client, final_model, token_provider, base_url, is_oauth=True)+ # OAuth identity only for native api.anthropic.com routes (#114967): MiniMax is a+ # third-party Anthropic-protocol host, so no Claude Code tool-name wire+ # transforms / identity rewrites / response prefix stripping here.+ client = AnthropicAuxiliaryClient(+ real_client, final_model, token_provider, base_url,+ is_oauth=anthropic_route_is_oauth(base_url, token_provider))return _route_client(req, client, final_model)elif auth_type in {"oauth_device_code", "oauth_external"}:# nous / openai-codex / xai-oauth already returned from their explicit branches.diff --git a/tests/agent/test_auxiliary_client_minimax_oauth.py b/tests/agent/test_auxiliary_client_minimax_oauth.pyindex 15ab599ce74..3bd0d669fa2 100644--- a/tests/agent/test_auxiliary_client_minimax_oauth.py+++ b/tests/agent/test_auxiliary_client_minimax_oauth.py@@ -10,13 +10,18 @@ title_generation, …) then silently re-routes to the Step-2 fallback chain —the operator's explicit configuration never reaches the wire.The fix routes through ``resolve_minimax_oauth_runtime_credentials(as_token_provider=True)``-and wraps the resulting Anthropic SDK client in-``AnthropicAuxiliaryClient(..., is_oauth=True)``. The callable bearer mints-a fresh access token per outbound request because MiniMax's tokens live+and wraps the resulting Anthropic SDK client in ``AnthropicAuxiliaryClient``. The callable+bearer mints a fresh access token per outbound request because MiniMax's tokens live~15 minutes and a static string would 401 mid-session.++``is_oauth`` is derived via ``anthropic_route_is_oauth(base_url, token_provider)``: the+MiniMax host is a third-party Anthropic-protocol endpoint, so the wrapper must NOT carry+the Claude Code OAuth identity (mcp__ tool-name wire transforms, system-prompt rewrites,+response prefix stripping) — those are native api.anthropic.com-only (#114967)."""from __future__ import annotations+from types import SimpleNamespacefrom unittest.mock import MagicMock, patchINFERENCE_BASE_URL = "https://api.minimax.io/anthropic"@@ -33,9 +38,10 @@ def _runtime_creds():def test_resolve_minimax_oauth_builds_anthropic_wrapper_with_oauth_semantics():- """Happy path: token-provider + base_url → AnthropicAuxiliaryClient with is_oauth=True,- Anthropic SDK built with the callable bearer (not a static string), and the- resolved model passed through verbatim.+ """Happy path: token-provider + base_url → AnthropicAuxiliaryClient with the+ third-party is_oauth invariant (False for api.minimax.io), Anthropic SDK built+ with the callable bearer (not a static string), and the resolved model passed+ through verbatim."""from agent.auxiliary_client import (AnthropicAuxiliaryClient,@@ -63,7 +69,13 @@ def test_resolve_minimax_oauth_builds_anthropic_wrapper_with_oauth_semantics():f"minimax-oauth must build an AnthropicAuxiliaryClient (the inference "f"endpoint is /anthropic). Got {type(client).__name__}.")- assert client.chat.completions._is_oauth is True+ assert client.chat.completions._is_oauth is False, (+ "MiniMax is a third-party Anthropic-protocol endpoint: is_oauth enables "+ "Claude Code-native transforms (mcp__ tool-name wire prefixing, identity "+ "rewrites, response prefix stripping) that 401/403 or corrupt tool calls "+ "there. anthropic_route_is_oauth('https://api.minimax.io/anthropic', …) "+ "is False by contract (tests/agent/test_anthropic_route_oauth_identity.py)."+ )# The callable token provider — not a string — must reach the Anthropic SDK so# the SDK mints a fresh access token per outbound request (MiniMax tokens# are short-lived; a static bearer 401s mid-session).@@ -76,6 +88,52 @@ def test_resolve_minimax_oauth_builds_anthropic_wrapper_with_oauth_semantics():assert model == "MiniMax-M3"+def test_resolve_minimax_oauth_tool_names_unprefixed_on_wire():+ """Witness for the user-visible contract: a tool list sent through the+ minimax-oauth auxiliary wrapper must reach the wire with its registry names+ verbatim. ``is_oauth=True`` would rename ``read_file`` to ``mcp__read_file``+ (and alias session_search/memory) on a host that never round-trips those+ names — every tool call against MiniMax would 400 or name a nonexistent tool.+ """+ from agent.auxiliary_client import resolve_provider_client++ captured = {}++ def _fake_create(client, api_kwargs, **kwargs):+ captured["tools"] = api_kwargs.get("tools")+ return SimpleNamespace(+ content=[],+ stop_reason="end_turn",+ usage=SimpleNamespace(input_tokens=1, output_tokens=1, total_tokens=2),+ )++ with patch(+ "hermes_cli.auth.resolve_minimax_oauth_runtime_credentials",+ return_value=_runtime_creds(),+ ), patch(+ "agent.anthropic_adapter.build_anthropic_client",+ return_value=MagicMock(name="anthropic_sdk_client"),+ ), patch(+ "agent.anthropic_adapter.create_anthropic_message",+ side_effect=_fake_create,+ ):+ client, _model = resolve_provider_client("minimax-oauth", "MiniMax-M3")+ assert client is not None+ client.chat.completions.create(+ model="MiniMax-M3",+ messages=[{"role": "user", "content": "hi"}],+ tools=[+ {"type": "function", "function": {"name": "read_file", "description": "x", "parameters": {}}},+ {"type": "function", "function": {"name": "session_search", "description": "y", "parameters": {}}},+ ],+ )+ wire_names = sorted(t["name"] for t in captured["tools"])+ assert wire_names == ["read_file", "session_search"], (+ "Third-party Anthropic-protocol endpoints must see unprefixed tool names; "+ "the Claude Code OAuth wire renamer must not run for api.minimax.io."+ )++def test_resolve_minimax_oauth_missing_credentials_returns_none_without_raising():"""AuthError from the runtime resolver → (None, None), no exception.