Repository navigation
Conversation
The chat-completions to Responses API streaming bridge hardcoded sequence_number=1 on the final response.output_item.done event for the text message. When a response contains a tool call, every other event in the same stream uses a growing counter, so that event ends up with a sequence_number lower than events that were actually emitted earlier (observed live: [...9, 10, 1]). A client that orders streamed events by sequence_number treats the message's out-of-order done event as a new, later item and re-renders the already-streamed message text a second time. This reproduced with claude-sonnet-5 through our ChatGPT/Anthropic Responses bridge whenever the model replied with text before calling a tool. Advance the existing per-stream sequence_number counter for this event instead of hardcoding 1, matching every other event type in this class. Confirmed still present in upstream v1.101.0 and v1.102.0 (stable).
Merging this PR will not alter performance1 warning
Comparing |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
|
Alexandr A. Alexandrov 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. |
|
Thanks for this. #44944 numbers every bridged streaming event from zero, which covers this case, so we plan to close this after it merges |
|
Closing as superseded by #44944, which is now merged and numbers every bridged streaming event from zero. Thanks for the fix! |
TLDR
Problem this solves:
response.output_item.donewithsequence_number=1[..., 9, 10, 1])sequence_number(Codex CLI) render the message text twiceHow it solves it:
User Flow
Before: a Codex CLI user on a model served through the chat-completions bridge sees the reply duplicated
"stream": trueto a non-Responses-native model (e.g. an Anthropic model)response.output_item.donearrives withsequence_number: 1, lower than earlier eventsAfter: the reply shows once
sequence_numberis strictly increasing, and Codex shows the text oncePre-Submission checklist
uv run pytest tests/unit/responses/litellm_completion_transformation/test_streaming_iterator_transformation.py -vScreenshots / Proof of Fix
We have run this patch in production on a self-hosted proxy since v1.101.0. Codex CLI sessions on Claude models through
/v1/responsesthen showed each text item once, with strictly increasingsequence_numbervalues. A Before/After run captured on this branch's merge base and tip will be added before review is requested.Type
🐛 Bug Fix