Repository navigation
fix(agent): anchor ZAI/Kimi base_url host matching to avoid substring false positives - #85715
Closed
pierrenode wants to merge 1 commit into
Closed
pierrenode wants to merge 1 commit into
pierrenode wants to merge 1 commit into
Conversation
… false positives _to_openai_base_url() matched ZAI (open.bigmodel.cn, api.z.ai, bare "bigmodel") and Kimi (api.kimi.com) via `substring in url`, so any custom gateway whose base_url happened to contain one of those strings as a path segment (e.g. a reverse-proxy prefix like /proxy/bigmodel-fallback/) was silently misrouted to the wrong OpenAI-wire endpoint shape. This is the same false-positive class 6f33f51 just fixed for the MiniMax branch in the same function by switching to base_url_host_matches() (hostname-anchored). Apply the same fix to the ZAI and Kimi branches, which that commit didn't touch. Drops the bare "bigmodel" substring check since open.bigmodel.cn is the only canonical bigmodel-family host referenced anywhere else in the codebase (agent/model_metadata.py, hermes_cli/auth.py). Added regression tests mirroring the MiniMax marker-in-path tests added in the same commit.
teknium1
added a commit
that referenced
this pull request
Aug 15, 2026
Follow-up to #85737, which migrated five provider-identity sites onto utils.base_url_host_matches()/base_url_hostname(). This completes the class sweep (never-patch-predicates: one owner, every site) and folds in the two open contributor PRs attacking individual sites: - agent/auxiliary_client.py ZAI/Kimi OpenAI-wire rewrite (PR #85715, pierrenode): 'bigmodel'/'api.z.ai'/'api.kimi.com' substring checks rewrote proxy paths containing those markers. - hermes_cli/runtime_provider.py Azure endpoint detection (PR #74721, RelaxJonh, issue #74312): 'azure.com' substring picked the Azure key for non-Azure hosts whose path contained the text. - run_agent.py: _is_azure_openai_url, _is_copilot_url, Anthropic credential-refresh azure guard, _anthropic_preserve_dots host allowlist, OpenRouter/mistral reasoning gates. - agent/chat_completion_helpers.py: nousresearch / nvidia detection. - agent/conversation_loop.py: GitHub Models 413 hint. - agent/usage_pricing.py: localhost billing-route detection. - hermes_cli/model_switch.py: api.openai.com catalog fallback and localhost custom-provider detection. - cli.py: local-model autodetect and Ollama/LM Studio context-length hints (port-anchored instead of '11434' in URL). - tools/mcp_oauth.py: Figma remote-MCP detection. - tools/skills_hub.py: raw.githubusercontent.com source-URL check. Regression tests extend tests/hermes_cli/test_base_url_host_identity.py (azure/copilot/dotted-model/figma proxy-path + lookalike cases) and tests/agent/test_minimax_auxiliary_url.py (ZAI/Kimi path false positives). Closes #74312. Salvages #85715 and #74721 with authorship preserved.
Collaborator
bobaba76
pushed a commit
to bobaba76/hermes-agent
that referenced
this pull request
Aug 27, 2026
Follow-up to NousResearch#85737, which migrated five provider-identity sites onto utils.base_url_host_matches()/base_url_hostname(). This completes the class sweep (never-patch-predicates: one owner, every site) and folds in the two open contributor PRs attacking individual sites: - agent/auxiliary_client.py ZAI/Kimi OpenAI-wire rewrite (PR NousResearch#85715, pierrenode): 'bigmodel'/'api.z.ai'/'api.kimi.com' substring checks rewrote proxy paths containing those markers. - hermes_cli/runtime_provider.py Azure endpoint detection (PR NousResearch#74721, RelaxJonh, issue NousResearch#74312): 'azure.com' substring picked the Azure key for non-Azure hosts whose path contained the text. - run_agent.py: _is_azure_openai_url, _is_copilot_url, Anthropic credential-refresh azure guard, _anthropic_preserve_dots host allowlist, OpenRouter/mistral reasoning gates. - agent/chat_completion_helpers.py: nousresearch / nvidia detection. - agent/conversation_loop.py: GitHub Models 413 hint. - agent/usage_pricing.py: localhost billing-route detection. - hermes_cli/model_switch.py: api.openai.com catalog fallback and localhost custom-provider detection. - cli.py: local-model autodetect and Ollama/LM Studio context-length hints (port-anchored instead of '11434' in URL). - tools/mcp_oauth.py: Figma remote-MCP detection. - tools/skills_hub.py: raw.githubusercontent.com source-URL check. Regression tests extend tests/hermes_cli/test_base_url_host_identity.py (azure/copilot/dotted-model/figma proxy-path + lookalike cases) and tests/agent/test_minimax_auxiliary_url.py (ZAI/Kimi path false positives). Closes NousResearch#74312. Salvages NousResearch#85715 and NousResearch#74721 with authorship preserved.
melon-xf
added a commit
to melon-xf/hermes-agent
that referenced
this pull request
Sep 3, 2026
Follow-up to NousResearch#85737, which migrated five provider-identity sites onto utils.base_url_host_matches()/base_url_hostname(). This completes the class sweep (never-patch-predicates: one owner, every site) and folds in the two open contributor PRs attacking individual sites: - agent/auxiliary_client.py ZAI/Kimi OpenAI-wire rewrite (PR NousResearch#85715, pierrenode): 'bigmodel'/'api.z.ai'/'api.kimi.com' substring checks rewrote proxy paths containing those markers. - hermes_cli/runtime_provider.py Azure endpoint detection (PR NousResearch#74721, RelaxJonh, issue NousResearch#74312): 'azure.com' substring picked the Azure key for non-Azure hosts whose path contained the text. - run_agent.py: _is_azure_openai_url, _is_copilot_url, Anthropic credential-refresh azure guard, _anthropic_preserve_dots host allowlist, OpenRouter/mistral reasoning gates. - agent/chat_completion_helpers.py: nousresearch / nvidia detection. - agent/conversation_loop.py: GitHub Models 413 hint. - agent/usage_pricing.py: localhost billing-route detection. - hermes_cli/model_switch.py: api.openai.com catalog fallback and localhost custom-provider detection. - cli.py: local-model autodetect and Ollama/LM Studio context-length hints (port-anchored instead of '11434' in URL). - tools/mcp_oauth.py: Figma remote-MCP detection. - tools/skills_hub.py: raw.githubusercontent.com source-URL check. Regression tests extend tests/hermes_cli/test_base_url_host_identity.py (azure/copilot/dotted-model/figma proxy-path + lookalike cases) and tests/agent/test_minimax_auxiliary_url.py (ZAI/Kimi path false positives). Closes NousResearch#74312. Salvages NousResearch#85715 and NousResearch#74721 with authorship preserved.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
_to_openai_base_url()inagent/auxiliary_client.pymatches ZAI (open.bigmodel.cn,api.z.ai, bare"bigmodel") and Kimi (api.kimi.com) hosts via rawsubstring in urlchecks. Any custom Anthropic-compatible gateway whosebase_urlhappens to contain one of those strings as a path segment (e.g. a reverse-proxy prefix like/proxy/bigmodel-fallback/anthropic, or a mirror namedapi.z.ai-mirror) is silently misrouted to the wrong OpenAI-wire endpoint shape instead of being left untouched.This is the exact same false-positive class
6f33f510e8(merged earlier the same day as this PR's base) fixed for the MiniMax branch in the same function, by switching from substring matching tobase_url_host_matches()(hostname-anchored, viaurlparse). That commit added_is_dual_surface_anthropic_host()plus regression tests (test_marker_in_path_does_not_false_positive,test_lookalike_host_suffix_not_matched) — but only touched the MiniMax branch. The adjacent ZAI and Kimi branches, a few lines above/below in the same function, kept the pre-fix substring pattern.Fix
base_url_host_matches(url, "open.bigmodel.cn") or base_url_host_matches(url, "api.z.ai"), dropping the bare"bigmodel"substring check —open.bigmodel.cnis the only canonical bigmodel-family host referenced anywhere else in the codebase (agent/model_metadata.py's provider-detection dict,hermes_cli/auth.py's provider base-URL table).base_url_host_matches(url, "api.kimi.com"), matching the pattern already used elsewhere in this same file for Kimi host checks (e.g. lines 2663, 2703, 4504, 6002, 6394, 6666).Out of scope: two unrelated
"bigmodel" in base_urlchecks elsewhere in the file (error-string heuristics gated on a specific error code, not endpoint routing) are a different, much lower-risk bug class and were intentionally left untouched to keep this fix narrowly scoped.Verification
HEAD~1(pre-fix): a gateway URL containingbigmodel-fallback,api.z.ai-mirror, orapi.kimi.com-proxyas a path segment got rewritten to the ZAI/Kimi-specific endpoint shape instead of being left alone.tests/agent/test_minimax_auxiliary_url.py, mirroring the MiniMax marker-in-path tests added by6f33f510e8.test_minimax_auxiliary_url.pysuite (13/13 pass) plus the direct neighbor suites (test_auxiliary_client.py,test_minimax_provider.py,test_set_runtime_main_custom_provider.py,test_auxiliary_explicit_base_anthropic.py,test_fallback_api_mode_preservation.py,test_minimax_profile.py— 245/246 pass). The one pre-existing failure (test_named_custom_anthropic_messages_keeps_full_name_and_url) reproduces identically with the fix stashed out — it's an unrelated, pre-existing environment gap (anthropicSDK not installed in this sandbox), not a regression from this change.ruff checkclean on both changed files.Test plan
ruff checkclean