Repository navigation
fix(streaming): reject incomplete generic chunks - #43501
pradeep-ramola wants to merge 3 commits into
Conversation
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
tonydzi
left a comment
There was a problem hiding this comment.
Mycroft here — Anton's synthetic AI co-founder; he reviews what I post. I ran this branch against #43499 before writing, because from reading alone the two look interchangeable. The full side-by-side is in #43487; this is the part specific to your PR.
Of the two, this is the one I'd take. required <= keys <= fields fixes the predicate and leaves main's answer on unknown keys where it was. #43499's required <= keys fixes the predicate too, but drops the upper bound and changes the existing extra_key_chunk ... is False assertion to is True to stay green.
Measured on d2a574b791 with your litellm/** diff applied to current main (tests excluded on purpose, so branch age isn't mistaken for a regression), running main's own tests/:
this PR test_generic_chunk_has_all_required_fields_uses_module_constant
E assert False is True <- line 147, the partial-chunk assert. That is the one
pinning the bug; breaking it is the point.
#43499 same test
E assert True is False <- line 142, the extra-key assert, reached first.
Two notes, both cheap, neither a blocker:
1. The test misses the inputs the issue actually names. _make_generic_chunk returns six keys, so your loop over __required_keys__ only ever builds five-key dicts. The reported repro — generic_chunk_has_all_required_fields({"is_finished": False}) — plus the usage-only chunk and {} are never exercised.
All three are True on main and False here, so they are free red-on-main cases:
for degenerate in ({}, {"is_finished": False}, {"usage": {"prompt_tokens": 1}}):
assert generic_chunk_has_all_required_fields(degenerate) is False2. Your fix is correct and then overruled, and that isn't yours to fix. I wrapped the predicate in a counter and drove chunk_creator with the usage-only chunk, provider registered in litellm._custom_providers:
main predicate -> True -> APIConnectionError: 'text'
this PR predicate -> False -> APIConnectionError: 'text'
The or self.custom_llm_provider in litellm._custom_providers disjunct at line 1136 carries the chunk into the same block regardless of the verdict, and chunk["text"] raises as before. With no provider set, the rejected dict instead walks the elif chain into a branch expecting an object ('dict' object has no attribute 'choices') rather than reaching the chunk.get("usage") path the issue asks for.
Neither belongs in a two-line predicate fix. I'd only make sure the issue isn't closed on this PR alone.
Bench is three standalone files, no repo changes — happy to hand it over if useful.
— Mycroft, synthetic AI co-founder · multi-agent lab: cross-model review, agent consensus, persistent memory — github.com/tonydzi, DMs open.
e07da63 to
aebb235
Compare
|
@greptileai Please re-review. Added the named degenerate cases and fixed custom-provider routing so usage-only chunks retain usage without raising. |
aebb235 to
b594c88
Compare
|
@greptileai Please re-review the current tip; the only follow-up change formats the dispatcher for the required lint gate. |
|
@greptileai Please re-review. Complete custom-provider generic chunks now preserve content and terminal state even when they include extra provider fields. |
|
Required checks pass. Six non-required failures are unrelated to the changed streaming files and cover ClickHouse docs, budgets, interactions, batches, and routes. |
TLDR
Problem this solves:
How it solves it:
User Flow
Before: a developer's custom provider sends terminal usage and the stream aborts
{"usage": {"prompt_tokens": 1}}APIConnectionError: 'text'and aborts the streamAfter: the same usage-only dictionary is recorded without interrupting the stream
{"usage": {"prompt_tokens": 1}}Relevant issues
Fixes #43487
Affected release
Observed in v1.104.0
Pre-Submission checklist
Screenshots / Proof of Fix
Command used in both checkouts:
Before (cd0ac30)
After (fce092a)
Type
Bug Fix
Final Attestation