fix(translation): preserve reasoning order in mixed stream chunks - #387
fix(translation): preserve reasoning order in mixed stream chunks#387Blakeolson21 wants to merge 3 commits into
Conversation
Signed-off-by: Blake <Blakeolson5@gmail.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Enterprise Run ID: 📒 Files selected for processing (2)
WalkthroughThe OpenAI Chat stream decoder now emits reasoning before text when both fields occur in one delta. A regression test verifies the translated Anthropic events: thinking block, reasoning deltas, block closure, then text block and delta. ChangesStream event ordering
Estimated code review effort: 2 (Simple) | ~10 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
Comment Warning |
Signed-off-by: Blake <Blakeolson5@gmail.com>
Signed-off-by: Blake <Blakeolson5@gmail.com>
|
Thanks for the review. |
What
Preserve reasoning-before-content order when an OpenAI Chat stream chunk contains both
reasoning_contentand visiblecontent.Add a focused OpenAI Chat to Anthropic Messages stream regression test using the one-chunk
reproducer from Issue 242. The test asserts the complete thinking block, thinking close, and text
block event sequence.
Why
Reasoning models can return reasoning and final content in the same stream delta. Emitting visible
content first makes the Anthropic translation close the text block and open a later thinking block,
which can interleave reasoning with the final answer. We hit this while streaming reasoning models
through the translation layer.
Closes #242
How tested
uv run ruff check .cleanuv run mypy switchyardcleanuv run pytest tests/green (134 passed,2 deselectedwith integration tests excluded)cargo fmt --all --checkcleancargo clippy --workspace --all-targets -- -D warningscleancargo test --workspacegreenChecklist
snake_caseof the primary class. No new classes or files.switchyard/__init__.py.__all__if intended for downstream use. No new public symbols.--helpupdated if customer-facing surface changed. No customer-facing API surface changed.Signed-off-by: Your Name <email>) per the DCO.Notes for reviewers
The production diff only moves existing
contentdelta emission below the existing reasoning-fieldloop. Parsing, field precedence, tool calls, finish reasons, and error behavior are unchanged.
The regression test asserts the exact Anthropic event order from the reported reproducer: thinking
block start, reasoning delta, signature delta, thinking block stop, text block start, and text delta.
Chunks containing only reasoning or only content retain their existing output.
Summary by CodeRabbit
Bug Fixes
Tests