Repository navigation
fix(chatgpt): preserve streamed output in chat bridge - #43412
danielphang wants to merge 7 commits into
Conversation
|
|
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
|
@greptileai Please review commit d0b0247; it addresses all three findings, adds multi-part recovery coverage, and passes the full lint/type gate |
|
@greptileai Please review 76e5741: citation offsets and immutable construction are fixed, with 134 passing tests, lint checks, and refreshed live proof |
|
Added recovery compatibility tests in 4f3973c. Local patch coverage is 53/53 lines, with 138 tests and lint passing. @greptileai please re-review |
|
@greptileai Please review b512de16dd: stream recovery tests now use the real iterator, and citation offset handling no longer uses recursion |
|
@greptileai Please review 9889aec4e1: removed redundant docstrings and typed the stream fixtures and iterator arguments. Focused tests, lint, and live proof pass |
|
@greptileai Please review e9c0037be3: all newly added test parameters and return types are annotated. All 140 tests, lint, and refreshed live proof pass |
|
Updated the stream tests, simplified citation offset handling, and addressed typing feedback. All review threads are resolved; Greptile is 5/5 and CI passes |
…am iterator The code-quality recursive_detector gate rejected _offset_annotation because it called itself to reach the nested url_citation form. The nesting is only one level deep, so a flat _offset_citation_indices helper replaces the recursion The bridge recovery tests used handwritten stand-ins for LiteLLM's own Responses streaming iterators, which tests/unit/AGENTS.md forbids. They also skipped the part that matters most: whether the typed events the real iterator yields pass _is_recoverable_stream_event and dump into payloads that recovery can read. The tests now run SyncResponsesAPIStreamingIterator and ResponsesAPIStreamingIterator over an httpx SSE body for both output_item.done and output_text.done events, and all four cases fail when recovery is disabled
e9c0037 to
cfc7d48
Compare
|
Closing as superseded by #41235, which fixes the forced SSE aggregation at the root and covers this exact case |
TLDR
Problem this solves:
How it solves it:
User Flow
Before: a developer's non-streaming ChatGPT request loses the completed answer and fails
POST http://localhost:4000/v1/chat/completionswith modelgpt-5.6-solusing the default non-streaming behaviorUnknown items in responses API response: []After: the same request returns the completed assistant answer
POST http://localhost:4000/v1/chat/completionswith modelgpt-5.6-solusing the default non-streaming behaviorRelevant issues
Relationship to #41014
Both PRs fix the same bridge failure by restoring streamed data when the terminal
response.outputis emptyresponse.output_item.doneresponse.output_item.doneandresponse.output_text.doneThis route keeps the state at the conversion boundary where a non-streaming Chat Completions response is assembled. It also gives raw SSE and bridge-collected events one recovery implementation, and can synthesize output from
response.output_text.donewhen a provider omits the completeresponse.output_item.doneitemPre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
uv run pytest tests/unit/<your_test_file>.py -v. Leave the suites (make test-unit-*,make test-unit) to CI: it finishes in ~15 minutes where a laptop takes an hour or more@greptileaito re-request a review after pushing changes)Focused validation:
140 passedacross the two Responses transformation test filesLocal patch line coverage: all 55 changed executable source lines covered (100%). Recovery tests exercise SDK event objects, full and partial dictionary terminals, unchanged input and headers, complete-output bypass, and empty-output preservation. Hosted
codecov/patchpassed on e9c0037be3 at 100.00% after all coverage uploads completed (required: 82.39%)The citation regression covers flat and nested annotations in both raw-SSE and bridge recovery, including out-of-order events and input preservation. Restoring the previous converter makes all four cases fail on incorrect citation positions; the fixed converter passes all four
The sync and async recovery regressions consume serialized SSE through the real Responses iterator, covering both output-item and text-only completion events
Repository validation:
make lintpassedGreptile reviewed e9c0037be3 at 5/5 with no remaining findings. Veria passed on the same tip.
codecov/patchpassed on the same tip. All hosted CI checks completed without failures. No Bugbot review is available, so it is not counted as a pass. The CLA bot still reports unsigned; the author must complete that separatelyScreenshots / Proof of Fix
Shared setup:
gpt-5.6-solmaps tochatgpt/gpt-5.6-sol; the request setsdisable_fallbacks: trueBefore (303434d)
http://127.0.0.1:49890POST http://127.0.0.1:49890/v1/chat/completionswith{"model":"gpt-5.6-sol","messages":[{"role":"user","content":"respond with HELLO WORLD"}],"max_tokens":8,"temperature":0,"disable_fallbacks":true}{"error":{"message":"litellm.APIConnectionError: APIConnectionError: ChatgptException - Unknown items in responses API response: []","type":"internal_server_error","param":null,"code":"500"}}After (e9c0037be3)
http://127.0.0.1:49889POST http://127.0.0.1:49889/v1/chat/completionswith the same payloadx-litellm-model-id: chatgpt-gpt-5-6-sol,x-litellm-attempted-fallbacks: 0, and{"model":"gpt-5.6-sol","content":"HELLO WORLD"}Type
Bug Fix
Caveats (if any)
Low
Final Attestation