Skip to content

fix(litellm): record partial output on early stream close - #4016

Merged
caroger merged 2 commits into
Arize-ai:mainfrom
px12811:fix/litellm-partial-stream-output
Oct 20, 2026
Merged

caroger merged 2 commits into
Arize-ai:mainfrom
px12811:fix/litellm-partial-stream-output

Conversation

@px12811

@px12811 px12811 commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #4011

Summary

LiteLLM streaming spans only recorded output.value and llm.output_messages after the stream loop completed. If an application stopped iterating early and closed or dropped the stream, the generator was closed at its yield and the span was ended with no output attributes.

This change extracts the streaming output finalization into a shared helper. Normal completion records the full output as before, while generator shutdown also records the output received so far before ending the span.

Validation

  • Added sync and async regression tests that consume one chunk, close the stream, and assert both output.value and llm.output_messages.0.message.content
  • tox run -e py313-ci-litellm on macOS: 131 passed
  • Focused tests/test_streaming_transparency.py: 8 passed on Python 3.10, 3.13, and 3.14
  • Ruff format, Ruff lint, and mypy passed

@px12811
px12811 requested a review from a team as a code owner October 10, 2026 07:53
@github-actions

github-actions Bot commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

CLA Assistant Lite bot All contributors have signed the CLA ✍️ ✅

@px12811

px12811 commented Oct 10, 2026

Copy link
Copy Markdown
Contributor Author

I have read the CLA Document and I hereby sign the CLA

…o exception event

The partial-output tests now also check the span status and events, so a change that marks a caller's early close as an error fails them.
@caroger
caroger enabled auto-merge (squash) October 20, 2026 04:22
@caroger
caroger merged commit 87387bd into Arize-ai:main Oct 20, 2026
23 checks passed
@mikeldking mikeldking mentioned this pull request Oct 20, 2026
@caroger

caroger commented Oct 20, 2026

Copy link
Copy Markdown
Contributor

Maintainer's note

I pushed one commit to this branch, as a fast-forward with no rebase.

  • c062c4c1 test(litellm): assert early stream close leaves the span unset with no exception event. The PR's tests checked the partial output and the span count, but not the status. The new assertions pin that a caller's early close isn't recorded as an error. They fail if the except clause is widened to BaseException.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

[bug] litellm: a stream the app stops reading early records no output (llm.output_messages / output.value missing)

2 participants