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
|
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 |
|
Thanks for the review. |
| )?; | ||
|
|
||
| assert_eq!( | ||
| events, |
There was a problem hiding this comment.
we're sort of duplicating test behaviour here, more test code is also more code to maintain.
Lets assert labels like
assert_eq!(
event_labels(&events),
vec![
"message_start",
"thinking_start",
"thinking_delta",
"signature_delta",
"thinking_stop",
"text_start",
"text_delta",
]
);
There was a problem hiding this comment.
Done. Added an event_labels helper that reduces the stream to ordered labels and asserted the label sequence, so the test verifies reasoning-first ordering without restating each event payload. Also rebased onto the latest main.
Signed-off-by: Blake <Blakeolson5@gmail.com>
Signed-off-by: Blake <Blakeolson5@gmail.com>
Replace the duplicated per-event JSON assertion with an event_labels helper that reduces the stream to ordered labels, keeping the reasoning-before-text ordering check readable. Signed-off-by: Blake <Blakeolson5@gmail.com>
f9cb482 to
8abc003
Compare
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