Skip to content

fix(responses): raise on failed chat streams - #36782

Closed
nightcityblade wants to merge 2 commits into
BerriAI:mainfrom
nightcityblade:fix/issue-36768
Closed

nightcityblade wants to merge 2 commits into
BerriAI:mainfrom
nightcityblade:fix/issue-36768

Conversation

@nightcityblade

@nightcityblade nightcityblade commented Aug 13, 2026 •

Copy link
Copy Markdown

TLDR

Problem this solves:

  • Failed Responses streams silently become successful empty chat completions
  • Router fallbacks never run after upstream stream failures

How it solves it:

  • Raise an API error for failed and error events
  • Cover both upstream event shapes with regression tests

User Flow

Before: a developer streaming chat completions receives an empty success when the upstream model fails

  1. They send POST https://<proxy>/v1/chat/completions with "stream": true
  2. The upstream Responses model emits response.failed or error
  3. The stream closes with an empty finish_reason=stop
  4. Configured fallback models never run

After: the same upstream failure triggers normal error and fallback handling

  1. They send POST https://<proxy>/v1/chat/completions with "stream": true
  2. The upstream Responses model emits response.failed or error
  3. LiteLLM surfaces the provider message as an API error
  4. Configured fallback models can run, or the client sees the error

Relevant issues

Fixes #36768

Linear ticket

Pre-Submission checklist

Please complete all items before asking a LiteLLM maintainer to review your PR

  • I have added meaningful tests
  • My PR passes all CI/CD checks (e.g., lint, format, unit tests)
  • My PR's scope is as isolated as possible; it only solves 1 specific problem
  • I have received a Greptile Confidence Score of at least 4/5 before requesting a maintainer review (Greptile reviews automatically once the PR is opened; only comment @greptileai to re-request a review after pushing changes)

Delays in PR merge?

If you're seeing a delay in your PR being merged, ping the LiteLLM Team on Slack (#pr-review).

Screenshots / Proof of Fix

The linked issue includes the intermittent live provider capture. The deterministic regression suite feeds both raw failure event shapes through the chat bridge:

67 passed, 1 warning in 2.02s

Type

🐛 Bug Fix

Caveats (if any)

  • An already-open SSE remains HTTP 200 but no longer ends silently

QA runbook

N/A — this PR adds a focused unit regression, not an e2e test.

Final Attestation

  • The tests check the right things, including the edge cases, and regressions in the respective real-world customer use-cases are not possible after this PR

@greptile-apps

greptile-apps Bot commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

Too many files changed for review (363 files, 100 file limit).

Bypass the limit by tagging @greptile-apps to review.

@CLAassistant

CLAassistant commented Aug 13, 2026 •

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.


nightcityblade seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

@nightcityblade
nightcityblade changed the base branch from main to litellm_internal_staging August 13, 2026 16:13
@codecov

codecov Bot commented Aug 13, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@nightcityblade

Copy link
Copy Markdown
Author

CI follow-up: fixed the two reportGeneralTypeIssues errors in commit 7f13522 by avoiding reuse of the earlier Final-inferred response_data local in the failure-event branch.

Verified locally:

  • focused failure-event tests: 3 passed
  • Ruff on the changed production module: passed
  • basedpyright on the changed module: no reportGeneralTypeIssues diagnostics in the modified branch
  • git diff --check: passed

The remaining OSV failure is repository-wide (nanoid 3.3.17 in the existing dashboard lockfile) and unrelated to this PR. Codecov has since completed successfully at 100% diff coverage.

@codspeed

codspeed Bot commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 31 untouched benchmarks


Comparing nightcityblade:fix/issue-36768 (7f13522) with litellm_internal_staging (9d069f2)

Open in CodSpeed

@yuneng-berri
yuneng-berri deleted the branch BerriAI:main September 13, 2026 04:41
@yuneng-berri yuneng-berri reopened this Sep 13, 2026
@devin-ai-integration
devin-ai-integration Bot changed the base branch from litellm_internal_staging to main September 23, 2026 15:08
@devin-ai-integration
devin-ai-integration Bot requested a review from a team September 23, 2026 15:08
@mateo-berri

Copy link
Copy Markdown
Contributor

Thanks for this. Main already raises on these events since #32835, and #46438 now keeps OpenAI's code and message, so closing as superseded

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.

[Bug]: /v1/chat/completions stream: response.failed becomes HTTP 200 + empty finish_reason=stop (fallbacks never run)

4 participants