fix(providers): re-derive minimax api_mode to prevent stale /model-switch 404 - #44879
Closed
onepisYa wants to merge 2 commits into
Closed
fix(providers): re-derive minimax api_mode to prevent stale /model-switch 404#44879onepisYa wants to merge 2 commits into
onepisYa wants to merge 2 commits into
Conversation
…itch 404 What: MiniMax API-key providers (minimax, minimax-cn) now re-derive api_mode from the resolved base URL when the persisted config value belongs to a different provider family (e.g. opencode-go leftover chat_completions in model.yaml after a provider switch). How: Extend the existing _resolve_runtime_from_pool_entry branch that already protects opencode-zen/opencode-go (Refs NousResearch#16878) to cover minimax/minimax-cn. Force anthropic_messages against the canonical /anthropic endpoint when (a) the base_url is the provider default and (b) the persisted api_mode is not a same-provider explicit value. Honor explicit /v1 user overrides and same-provider explicit configs for full backward compatibility. Why: 8 historical subagent 404 incidents (5/16-6/12, 67% failure rate in 3-parallel subagent batches) traced in part to api_mode leaking across provider switches. The minimax plugin lacked the same stale-api_mode protection that opencode-zen/opencode-go already has because its base_url is hardcoded to /anthropic and its ProviderProfile explicitly sets api_mode=anthropic_messages — both masking the bug until a user typo or a stale model.yaml surfaces it. Mirrors the minimax-oauth pool protection added in the same file.
tonydwb
approved these changes
Jun 12, 2026
tonydwb
left a comment
There was a problem hiding this comment.
Clean fix for MiniMax stale api_mode. Re-derives api_mode from URL when the persisted value comes from a different provider family, preventing /chat/completions routing under /anthropic (which returns nginx 404). Backward-compatible for users with explicit /v1 base_url overrides. Good test coverage. No issues found.
Add .omx to .gitignore to prevent accidental commits of .omx files and keep repository free of those artifacts.
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.
What
MiniMax API-key providers (
minimax,minimax-cn) now re-deriveapi_modefrom the resolved base URL when the persisted config value belongs to a different provider family (e.g. a leftoverchat_completionsinmodel.yamlafter switching away fromopencode-go).Why
8 historical subagent 404 incidents (5/16 → 6/12, up to 67% failure rate in 3-parallel subagent batches) — tracked in
subagent-404-investigationboard — traced in part toapi_modeleaking across provider switches.The MiniMax plugin lacked the same stale-
api_modeprotection thatopencode-zen/opencode-goalready has (Refs #16878) because:base_urlis hardcoded to the/anthropicsuffix.ProviderProfileexplicitly setsapi_mode="anthropic_messages".Both mask the bug — until a user typo or a stale
model.yamlsurfaces it. Result:/chat/completionsrouted under/anthropic→ the MiniMax gateway returns a bare nginx 404.The existing
minimax-oauthbranch already protects OAuth via a similar force-anthropic_messagespolicy. This PR extends the same protection to API-keyminimax/minimax-cn.How
Extend the existing
_resolve_runtime_from_pool_entrybranch inhermes_cli/runtime_provider.py(the one that already protectsopencode-zen/opencode-go, Refs #16878) to coverminimax/minimax-cn. Forceanthropic_messagesagainst the canonical/anthropicendpoint when all three of:base_urlis the provider default (/anthropic), not a user override_detect_api_mode_for_url) returnsanthropic_messagesapi_modeis not a same-provider explicit value (_provider_supports_explicit_api_mode(provider, configured_provider)is False)Honor explicit user intent for full backward compatibility:
base_url: /v1override →_detect_api_mode_for_urlreturnschat_completions→ honored (preserves thetest_minimax_v1_url_uses_chat_completionssemantic for regions where/anthropic404s).provider: minimax+api_mode: chat_completions(same provider family explicit) → honored (preservestest_minimax_explicit_api_mode_respectedsemantic).Tests
Three new RED-then-GREEN tests in
tests/hermes_cli/test_runtime_provider_resolution.py:test_minimax_re_derives_stale_chat_completions_from_opencode_goprovider=minimaxactive,configured_provider=opencode-gostale +api_mode=chat_completionsstaleanthropic_messages(forced)test_minimax_cn_re_derives_stale_chat_completions_from_opencode_gominimax-cnanthropic_messages(forced)test_minimax_v1_override_still_uses_chat_completionsMINIMAX_BASE_URL=/v1override + no explicit modechat_completions(honored)All three FAIL on upstream main (verified locally) and PASS after the fix.
Regression verification
Zero regressions in adjacent test files (
model_switch_opencode_anthropic.pyexercises the same path as theopencode-zen/opencode-gofix this PR mirrors).Diff stats
Net code change in
runtime_provider.py: +37/-1 (one elif branch with extensive rationale comments).Refs
🤖 Generated with Claude Code via Hermes Agent