Skip to content

fix(streaming): preserve refusal-only deltas - #45323

Draft
aibysid wants to merge 1 commit into
BerriAI:mainfrom
aibysid:fix-litellm-45235
Draft

aibysid wants to merge 1 commit into
BerriAI:mainfrom
aibysid:fix-litellm-45235

Conversation

@aibysid

@aibysid aibysid commented Oct 8, 2026 •

Copy link
Copy Markdown

TLDR

Problem this solves:

  • Streaming drops refusal text and returns empty successful replies

How it solves it:

  • Treat refusal deltas as content in the shared stream filter
  • Add eight regression cases using the real streaming parser

User Flow

Before: a developer receives an empty assistant turn when the backend streams refusal text

  1. Request a streaming chat completion from a backend emitting delta.refusal
  2. Observe role and finish chunks, with the refusal fragments missing

After: the same request preserves the refusal explanation

  1. Request a streaming chat completion from a backend emitting delta.refusal
  2. Receive every refusal fragment in order and one terminal event

Relevant issues

Addresses #45235

Automated verification

uv run --no-sync python -m pytest tests/unit/litellm_core_utils/test_streaming_handler.py -q --tb=short --timeout=60 --disable-warnings: 173 passed, 30 warnings

The eight new cases cover openai and hosted_vllm, synchronous and asynchronous iteration, and refusal fragments arriving separately from or with the terminal event. They feed scripted SSE through the real parser and wrapper without patching LiteLLM's own methods. Before adding the refusal check, all eight failed because no refusal fragments reached the caller. After the change, all eight passed

make lint: passed, including Ruff, test-tree lint, strict-rule, type-discipline, test-quality and basedpyright gates, circular imports, import safety and MCP boundary checks. Type gates compare against existing repository diagnostics; this does not claim zero type errors across the repository

Scoped Ruff formatting and git diff --check: passed

Pre-Submission checklist

  • I have added meaningful tests
  • The test file covering the change passes locally
  • All 99 currently reported CI checks passed
  • My PR only solves one specific problem
  • Greptile confidence is at least 4/5 before maintainer review

Type

Bug Fix

Caveats

Medium

  • Real-provider before-and-after proof is pending
  • This draft awaits live verification and required reviews

Low

  • CLA status has not been confirmed

Manual verification

Run the issue's refusal-producing request against the same real backend at the base and PR tip. Confirm the fixed SDK preserves every refusal fragment and finishes once. Capture sanitized stream output and commit hashes before requesting maintainer review. Scripted SSE tests above are automated regression evidence, not real-provider proof

Final Attestation

  • Real-world verification and required reviews are complete

@codecov

codecov Bot commented Oct 8, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@codspeed

codspeed Bot commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 31 untouched benchmarks


Comparing aibysid:fix-litellm-45235 (5573af3) with main (7dd9aff)1

Open in CodSpeed

Footnotes

  1. No successful run was found on main (7a65997) during the generation of this report, so 7dd9aff was used instead as the comparison base. There might be some changes unrelated to this pull request in this report. ↩

@mateo-berri

Copy link
Copy Markdown
Contributor

Thanks for this. #45423 has the same one-line fix and is out of draft, so we're landing that one and will close this after

This branch has not been deployed

No deployments
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