Repository navigation
fix(models): surface MiniMax rate-limit and API errors instead of generic messages - #17292
Conversation
…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.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughMinimax 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. ChangesMinimax error handling
Estimated code review effort: 3 (Moderate) | ~20 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
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. Comment |
wangq8
left a comment
There was a problem hiding this comment.
Nice improvement - surfacing the real error messages instead of generic ones is clearly the right thing to do.
What works well:
extractMinimaxAPIErrorcorrectly 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_respin 200, OpenAI-styleerrorin 429, and SSE error events. - The streaming fix (returning an error when SSE carries
base_resp/errorinstead 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.
Summary
MiniMax can return rate-limit and other API errors embedded in a HTTP 200 response body (via a
base_respblock with non-zerostatus_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:ChatWithMessages): returned a generic"no choices in response"error, hiding the real cause.ChatStreamlyWithSender): silently skipped error events (nochoicesarray →return nil), then reported"minimax: stream ended before [DONE] or finish_reason".These generic errors did not contain keywords like
"rate limit"or"429", so the upstream retry predicates (RetryPredicates.TemporaryErrors/ResourceErrorsininternal/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:
base_resp/errorbefore checkingchoices.base_resp/errorinstead of silently skipping it.ChatWithMessages,ChatStreamlyWithSender,ListModels) now useextractMinimaxErrorBodyto 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 withbase_resprate-limit payloadTestMinimaxChatSurfacesOpenAIError— HTTP 429 with OpenAI-compatibleerrorpayloadTestMinimaxStreamSurfacesBaseRespError— SSE error event withbase_resppayloadAll existing MiniMax tests continue to pass.