Skip to content

fix(providers): re-derive minimax api_mode to prevent stale /model-switch 404 - #44879

Closed
onepisYa wants to merge 2 commits into
NousResearch:mainfrom
onepisYa:fix/minimax-stale-api-mode-protection
Closed

fix(providers): re-derive minimax api_mode to prevent stale /model-switch 404#44879
onepisYa wants to merge 2 commits into
NousResearch:mainfrom
onepisYa:fix/minimax-stale-api-mode-protection

Conversation

@onepisYa

Copy link
Copy Markdown

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. a leftover chat_completions in model.yaml after switching away from opencode-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-investigation board — 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 (Refs #16878) because:

  1. Its base_url is hardcoded to the /anthropic suffix.
  2. Its ProviderProfile explicitly sets api_mode="anthropic_messages".

Both mask the bug — until a user typo or a stale model.yaml surfaces it. Result: /chat/completions routed under /anthropic → the MiniMax gateway returns a bare nginx 404.

The existing minimax-oauth branch already protects OAuth via a similar force-anthropic_messages policy. This PR extends the same protection to API-key minimax/minimax-cn.

How

Extend the existing _resolve_runtime_from_pool_entry branch in hermes_cli/runtime_provider.py (the one that already protects opencode-zen/opencode-go, Refs #16878) to cover minimax/minimax-cn. Force anthropic_messages against the canonical /anthropic endpoint when all three of:

  1. base_url is the provider default (/anthropic), not a user override
  2. URL auto-detect (_detect_api_mode_for_url) returns anthropic_messages
  3. The persisted api_mode is 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: /v1 override → _detect_api_mode_for_url returns chat_completions → honored (preserves the test_minimax_v1_url_uses_chat_completions semantic for regions where /anthropic 404s).
  • provider: minimax + api_mode: chat_completions (same provider family explicit) → honored (preserves test_minimax_explicit_api_mode_respected semantic).

Tests

Three new RED-then-GREEN tests in tests/hermes_cli/test_runtime_provider_resolution.py:

Test Scenario Expected
test_minimax_re_derives_stale_chat_completions_from_opencode_go provider=minimax active, configured_provider=opencode-go stale + api_mode=chat_completions stale anthropic_messages (forced)
test_minimax_cn_re_derives_stale_chat_completions_from_opencode_go Same for minimax-cn anthropic_messages (forced)
test_minimax_v1_override_still_uses_chat_completions MINIMAX_BASE_URL=/v1 override + no explicit mode chat_completions (honored)

All three FAIL on upstream main (verified locally) and PASS after the fix.

Regression verification

python -m pytest tests/hermes_cli/test_runtime_provider_resolution.py
# 132 passed
python -m pytest tests/hermes_cli/test_runtime_provider_resolution.py tests/hermes_cli/test_custom_provider_model_switch.py tests/hermes_cli/test_model_switch_opencode_anthropic.py
# 162 passed

Zero regressions in adjacent test files (model_switch_opencode_anthropic.py exercises the same path as the opencode-zen/opencode-go fix this PR mirrors).

Diff stats

hermes_cli/runtime_provider.py                          | 38 ++++++++-
tests/hermes_cli/test_runtime_provider_resolution.py   | 90 ++++++++++++++++++++++
2 files changed, 127 insertions(+), 1 deletion(-)

Net code change in runtime_provider.py: +37/-1 (one elif branch with extensive rationale comments).

Refs

🤖 Generated with Claude Code via Hermes Agent

…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.
@alt-glitch alt-glitch added type/bug Something isn't working P3 Low — cosmetic, nice to have comp/cli CLI entry point, hermes_cli/, setup wizard provider/minimax MiniMax (Anthropic transport) labels Jun 12, 2026

@tonydwb tonydwb left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/cli CLI entry point, hermes_cli/, setup wizard P3 Low — cosmetic, nice to have provider/minimax MiniMax (Anthropic transport) type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants