Skip to content

fix(models): surface MiniMax rate-limit and API errors instead of generic messages - #17292

Merged
wangq8 merged 3 commits into
infiniflow:mainfrom
euvre:fix/minimax-rate-limit-error
Jul 24, 2026
Merged

wangq8 merged 3 commits into
infiniflow:mainfrom
euvre:fix/minimax-rate-limit-error

Conversation

@euvre

@euvre euvre commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Summary

MiniMax can return rate-limit and other API errors embedded in a HTTP 200 response body (via a base_resp block with non-zero status_code), or as OpenAI-compatible error events in the SSE stream — rather than returning a standard non-200 status. The previous code discarded these payloads:

  • Non-streaming (ChatWithMessages): returned a generic "no choices in response" error, hiding the real cause.
  • Streaming (ChatStreamlyWithSender): silently skipped error events (no choices array → return nil), then reported "minimax: stream ended before [DONE] or finish_reason".
  • Non-200 responses: returned the raw body without extracting the human-readable error message.

These generic errors did not contain keywords like "rate limit" or "429", so the upstream retry predicates (RetryPredicates.TemporaryErrors / ResourceErrors in internal/harness/graph/pregel/retry.go) could not match them and never retried on rate limits.

What this PR changes

Adds two helpers in internal/entity/models/minimax.go:

  • extractMinimaxAPIError() — extracts the real error message from both MiniMax-specific (base_resp.status_msg) and OpenAI-compatible (error.message) payloads.
  • extractMinimaxErrorBody() — parses a raw HTTP error response body and returns the human-readable message.

All three code paths now surface the actual error:

  1. Non-streaming chat: checks for embedded base_resp/error before checking choices.
  2. Streaming chat: returns an error when an SSE event carries base_resp/error instead of silently skipping it.
  3. Non-200 HTTP: all endpoints (ChatWithMessages, ChatStreamlyWithSender, ListModels) now use extractMinimaxErrorBody to surface the real message.

This enables the retry layer to match rate-limit errors by keyword ("rate limit", "429", "too many requests", "quota exceeded") and retry appropriately.

Tests

Added three tests in internal/entity/models/minimax_test.go:

  • TestMinimaxChatSurfacesBaseRespError — HTTP 200 with base_resp rate-limit payload
  • TestMinimaxChatSurfacesOpenAIError — HTTP 429 with OpenAI-compatible error payload
  • TestMinimaxStreamSurfacesBaseRespError — SSE error event with base_resp payload

All existing MiniMax tests continue to pass.

…eric messages

MiniMax can return rate-limit and other API errors embedded in a
HTTP 200 response body (via a base_resp block with non-zero status_code)
or as OpenAI-compatible error events in the SSE stream. The previous
code discarded these payloads:

- Non-streaming: returned a generic "no choices in response" error
- Streaming: silently skipped error events, then reported
  "stream ended before [DONE] or finish_reason"
- Non-200 responses: returned the raw body without extracting the
  human-readable error message

These generic errors did not contain keywords like "rate limit" or
"429", so upstream retry predicates (RetryPredicates.TemporaryErrors /
ResourceErrors) could not match them and retry.

This change adds extractMinimaxAPIError() and extractMinimaxErrorBody()
helpers that extract the real error message from both MiniMax-specific
(base_resp.status_msg) and OpenAI-compatible (error.message) payloads.
All three code paths (non-streaming chat, streaming chat, list models)
now surface the actual error message, enabling the retry layer to
match and retry rate-limit errors appropriately.

Add tests covering: base_resp error in non-streaming, OpenAI error
with HTTP 429, and base_resp error in SSE stream.
@dosubot dosubot Bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Jul 23, 2026
@euvre euvre added the ci Continue Integration label Jul 23, 2026
@dosubot dosubot Bot added the 🐞 bug Something isn't working, pull request that fix bug. label Jul 23, 2026
@coderabbitai

coderabbitai Bot commented Jul 23, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 6101ba71-eef8-4d8f-aa77-772c85c313de

📥 Commits

Reviewing files that changed from the base of the PR and between f3d60fc and 9d4071c.

📒 Files selected for processing (1)
  • internal/entity/models/minimax.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • internal/entity/models/minimax.go

📝 Walkthrough

Walkthrough

Minimax error extraction is centralized for structured provider responses. Chat, streaming, and model-list requests now surface parsed errors for non-200 responses, while chat and streaming paths detect embedded errors in otherwise successful payloads. Tests cover rate-limit and OpenAI-compatible error formats.

Changes

Minimax error handling

Layer / File(s) Summary
Centralized error extraction and HTTP paths
internal/entity/models/minimax.go
Adds shared parsing for Minimax and OpenAI-compatible errors, applying it to non-200 chat, streaming, and model-list responses.
Embedded response error detection
internal/entity/models/minimax.go, internal/entity/models/minimax_test.go
Detects provider errors before choices processing in chat and streaming responses, with tests for rate-limit and OpenAI-style payloads.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Poem

A rabbit spots the error’s trace,
In chat and streams, it finds its place.
Rate limits hop into the light,
OpenAI shapes now read just right.
The models list can speak clearly tonight.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: surfacing MiniMax rate-limit and API errors instead of generic messages.
Description check ✅ Passed The description satisfies the template by providing a clear summary, context, implementation details, and test coverage.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@euvre
euvre requested a review from wangq8 July 23, 2026 08:02

@wangq8 wangq8 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Nice improvement - surfacing the real error messages instead of generic ones is clearly the right thing to do.

What works well:

  • extractMinimaxAPIError correctly handles both MiniMax-specific (base_resp) and OpenAI-compatible (error) error payloads, in both 200 and non-200 responses.
  • All three code paths (non-streaming, streaming, ListModels) now surface the actual error.
  • Tests cover the key scenarios: base_resp in 200, OpenAI-style error in 429, and SSE error events.
  • The streaming fix (returning an error when SSE carries base_resp/error instead of silently skipping) is particularly important - silent drops are the hardest to debug.

One thing to be aware of (not a blocker):

The contains helper in internal/harness/graph/pregel/retry.go only checks the start of the error string (both the case-sensitive and case-insensitive paths do s[:len(substr)] == substr). Since the errors now have a "minimax API error: " prefix, keywords like "rate limit" or "429" won't match at position 0 and the retry predicates won't fire. The error surfacing is still a win for observability, but if the goal is automatic retry, the contains function might need to become a proper substring scan. Something to follow up separately.

@wangq8
wangq8 requested a review from Lynn-Inf July 23, 2026 11:28

@Lynn-Inf Lynn-Inf left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@wangq8
wangq8 merged commit 40388c4 into infiniflow:main Jul 24, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🐞 bug Something isn't working, pull request that fix bug. ci Continue Integration size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants