Skip to content

fix: surface API errors in SDK streams - #290

Open
ch-z-hc wants to merge 1 commit into
MiniMax-AI:mainfrom
ch-z-hc:fix/sdk-stream-api-errors
Open

ch-z-hc wants to merge 1 commit into
MiniMax-AI:mainfrom
ch-z-hc:fix/sdk-stream-api-errors

Conversation

@ch-z-hc

@ch-z-hc ch-z-hc commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Bug

The shared SDK SSE iterator yields every JSON payload as a successful event, including server error frames delivered after HTTP 200. A consumer can finish a failed text or speech generation without an exception, or receive an API error as a transcription delta and later lose its cause to the generic incomplete-transcript error.

The Anthropic streaming contract includes in-stream error events; MiniMax's text endpoint uses this compatible format. The CLI audio decoder already checks both error and nonzero base_resp.status_code, but the SDK shared iterator does not.

Fix

Check both error shapes before yielding and reuse mapApiError, including the response URL for endpoint-specific hints. Keep JSON parsing in its own catch so quota/content-filter errors are not relabeled as parse failures. Preserve previous valid chunks, successful status code 0, empty events and [DONE] handling. No new dependency or public API.

This is separate from #279 (response-body ownership/cleanup). It does not duplicate that cleanup change or claim to solve it.

Validation

  • Five new regressions through the public text, speech synthesis and transcription SDK methods, using loopback HTTP/SSE fixtures. Unchanged product code with the same tests: 43 passed / 5 failed. Patched SDK, HTTP, SSE parser and audio decoder tests: 96 passed / 0 failed.
  • Production SDK bundles against the same local fixture: original bundle silently completes all three error scenarios; patched bundle rejects all three with quota exit code 4, preserving only the earlier valid event. All three successful controls still complete. No live model requests.
  • Two independent automated blind reviews: no actionable findings. Additional reviewer probes cover malformed JSON, empty/DONE events, successful status code 0 and business-error mappings. These are automated reviews, not human approval.
  • Windows and Linux typecheck, lint and CLI/SDK/declaration builds pass. Lint retains the existing explicit-any warning in test/sdk/speech.test.ts.
  • Full Linux suite, same added tests on both versions: unchanged main 596 passed / 8 failed; patched 601 passed / 3 failed. The five new failures are fixed. The remaining three fail on both versions: two unreachable-region timeout cases and the FileSDK upload base-URL assertion. Those failures were not diagnosed or changed; the full suite is not green.

Full-suite validation uses temporary configuration, a process-local no-op URL opener and a validation-only fetch preload rejecting external hosts by default (test-owned mocks can override it). Windows OAuth/full-suite tests were not run because of the existing browser-opening mock issue. No existing assertions, timeouts or skip conditions were relaxed.

Implemented and tested with Codex assistance.


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need.

@ch-z-hc

ch-z-hc commented Oct 16, 2026

Copy link
Copy Markdown
Contributor Author

Could a maintainer approve the pending CI and AI review runs for this PR and #283, #284, #285, #286, #288 and #289? The runs currently report action_required, so they have not produced test results yet.

I only have read access to the upstream repository and cannot authorize the runs myself.

@NianJiuZst

Copy link
Copy Markdown
Collaborator

Could a maintainer approve the pending CI and AI review runs for this PR and #283, #284, #285, #286, #288 and #289? The runs currently report action_required, so they have not produced test results yet.

I only have read access to the upstream repository and cannot authorize the runs myself.

OK

@NianJiuZst

Copy link
Copy Markdown
Collaborator

I will review all of them.Thanks for your contribution!

@NianJiuZst
NianJiuZst self-requested a review October 16, 2026 17:50
@NianJiuZst NianJiuZst self-assigned this Oct 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants