Skip to content

Conversation

@hannesrudolph
Copy link
Collaborator

@hannesrudolph hannesrudolph commented Feb 10, 2026

Summary

When AI SDK providers return HTTP errors (e.g., Z.ai "Insufficient balance" or "token expired"), users saw the useless generic message "No output generated. Check the stream for errors." instead of the actual API error. This PR fixes error message extraction across all 17 AI SDK providers and eliminates duplicate error display on mid-stream failures.

Root Cause

The AI SDK's streamText() has a dual error path: the actual API error appears in the stream as an error chunk (with the correct message), but then result.usage throws a separate NoOutputGeneratedError with a generic message and no reference to the original error. The generic error was overwriting the real one.

Changes

Core utility (src/api/transform/ai-sdk.ts)

  • Add consumeAiSdkStream() — shared utility that captures stream error messages during iteration and substitutes them when result.usage throws NoOutputGeneratedError
  • Add extractMessageFromResponseBody() — parses JSON error responses from API response bodies
  • Enhance extractAiSdkErrorMessage() with responseBody extraction for AI_APICallError, AI_RetryError, and AI_NoOutputGeneratedError

17 AI SDK providers updated

  • Pattern A (12 simpler providers): Use consumeAiSdkStream() directly with optional usageHandler — zai, xai, fireworks, sambanova, deepseek, mistral, baseten, lm-studio, azure, requesty, openai-compatible, openai-native
  • Pattern B (5 complex providers): Manual lastStreamError capture preserving custom stream logic (thinking signatures, grounding, throttle handling) — anthropic, anthropic-vertex, vertex, gemini, bedrock

Duplicate error display fix (src/core/task/Task.ts)

  • When auto-retry is enabled and a stream fails mid-request, abortStream() no longer displays the error message (since backoffAndAnnounce() will display it with the retry countdown). This eliminates the duplicate "API Request Failed" + "Provider Error" display.

Tests

  • 18 new tests in ai-sdk.spec.ts covering consumeAiSdkStream, extractMessageFromResponseBody, and enhanced error extraction

Before → After

  • Before: "Provider ended the request: Z.ai: No output generated. Check the stream for errors."
  • After: "Provider ended the request: Z.ai: token expired or incorrect"

Important

This PR replaces generic error messages with specific API error messages across 17 AI SDK providers, adds a new utility for error handling, and fixes duplicate error messages during mid-stream failures.

  • Behavior:
    • Replaces generic NoOutputGeneratedError with specific API error messages across 17 AI SDK providers.
    • Fixes duplicate error messages during mid-stream failures in Task.ts.
  • Utilities:
    • Adds consumeAiSdkStream() in ai-sdk.ts to capture stream error messages and handle NoOutputGeneratedError.
    • Adds extractMessageFromResponseBody() to parse JSON error responses.
  • Providers:
    • Updates 12 providers to use consumeAiSdkStream() directly: zai, xai, fireworks, sambanova, deepseek, mistral, baseten, lm-studio, azure, requesty, openai-compatible, openai-native.
    • Updates 5 providers with custom error handling logic: anthropic, anthropic-vertex, vertex, gemini, bedrock.
  • Tests:
    • Adds 18 tests in ai-sdk.spec.ts for consumeAiSdkStream, extractMessageFromResponseBody, and enhanced error extraction.

This description was created by Ellipsis for ecd3c07. You can customize this summary. It will automatically update as commits are pushed.

@dosubot dosubot bot added size:XL This PR changes 500-999 lines, ignoring generated files. bug Something isn't working labels Feb 10, 2026
@roomote
Copy link
Contributor

roomote bot commented Feb 10, 2026

Rooviewer Clock   See task

Reviewed commit ecd3c07. The indentation fix in minimax.ts is correct and all previously flagged issues are now resolved.

  • Debug log in Task.ts interpolates streamingFailedMessage (which is undefined when auto-retry is active) instead of rawErrorMessage, losing error detail in server logs
  • Indentation inconsistency in minimax.ts -- lines 132-176 are one tab level deeper than sibling const result on line 130
Previous reviews

Mention @roomote in a comment to request specific changes to this pull request or fix all unresolved issues.

…eratedError

- Add consumeAiSdkStream() shared utility that captures stream error messages
  and substitutes them when result.usage throws NoOutputGeneratedError
- Update all 17 AI SDK providers to use the new utility
- Add extractMessageFromResponseBody() for JSON error response parsing
- Enhance extractAiSdkErrorMessage() with responseBody extraction
- Fix duplicate error display on mid-stream failures with auto-retry
- Add 18 new tests covering error extraction and stream consumption
@hannesrudolph hannesrudolph force-pushed the fix/ai-sdk-error-handling branch from ffd4870 to 739f64a Compare February 10, 2026 01:50
@dosubot dosubot bot added size:XXL This PR changes 1000+ lines, ignoring generated files. and removed size:XL This PR changes 500-999 lines, ignoring generated files. labels Feb 10, 2026
@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Feb 10, 2026
@hannesrudolph hannesrudolph merged commit 2f98490 into main Feb 10, 2026
15 of 17 checks passed
@hannesrudolph hannesrudolph deleted the fix/ai-sdk-error-handling branch February 10, 2026 02:47
@github-project-automation github-project-automation bot moved this from New to Done in Roo Code Roadmap Feb 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working lgtm This PR has been approved by a maintainer size:XXL This PR changes 1000+ lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants