fix(models): preserve streamed content part order#3822
Open
felmonon wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
When a Chat Completions stream emits a refusal before text, the raw stream assigns
content_index=0to the refusal andcontent_index=1to the text, butresponse.completedalways assembled text before refusal. Consumers replaying raw events therefore saw a different content layout from the completed response.This PR assembles the completed assistant message using the content indexes already assigned during streaming. Text-before-refusal behavior stays unchanged, while refusal-before-text now matches the raw event sequence. This is a focused follow-up to the pre-existing mismatch discussed in #3757 and follows the raw-event/final-response alignment required during #3769.
Test plan
origin/mainand passes with this change.uv run pytest -q tests/models/test_openai_chatcompletions_stream.py— 57 passed.bash .agents/skills/code-change-verification/scripts/run.sh— format, lint, and the full test suite passed.archive_ops.py,test_any_llm_model.py, andtest_run_step_execution.py).Issue number
Follow-up to #3757; related maintainer direction in #3769.
Checks