fix(translation): reject incomplete anthropic streams - #283
Conversation
Signed-off-by: Bhuvan Agrawal <11240550+bhuvan002@users.noreply.github.com>
WalkthroughAnthropic stream decoding now tracks ChangesAnthropic stream completion validation
Estimated code review effort: 3 (Moderate) | ~20 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
crates/switchyard-translation/src/helpers.rs (1)
584-608: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winCover both terminal-frame paths.
This test covers only EOF after a normal
message_startframe. It does not cover a validmessage_stopin the normal path or the trailing-frame path at Lines 233-241. Add success cases for both paths. Add a concise comment stating that incomplete Anthropic streams must fail without synthesizingmessage_stop.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@crates/switchyard-translation/src/helpers.rs` around lines 584 - 608, Extend the Anthropic stream tests around encode_stream to cover successful completion with a valid message_stop in both the normal terminal-frame path and the trailing-frame path near the existing terminal handling. Add a concise comment explaining that incomplete streams must fail without synthesizing message_stop, while preserving the existing EOF failure assertion.Source: Coding guidelines
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@crates/switchyard-translation/src/helpers.rs`:
- Around line 584-608: Extend the Anthropic stream tests around encode_stream to
cover successful completion with a valid message_stop in both the normal
terminal-frame path and the trailing-frame path near the existing terminal
handling. Add a concise comment explaining that incomplete streams must fail
without synthesizing message_stop, while preserving the existing EOF failure
assertion.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Enterprise
Run ID: 83567ab8-0e78-43bc-a42d-6b34f6f7d41e
📒 Files selected for processing (1)
crates/switchyard-translation/src/helpers.rs
What
Explicitly throws and SSE error in case the upstream Anthropic stream ends prematurely without a
message_stopevent.Why
The motivation — what problem does this solve, or which ticket does it close?
Closes #
How tested
uv run ruff check .cleanuv run mypy switchyardcleanuv run pytest tests/greenChecklist
snake_caseof the primary class.switchyard/__init__.py.__all__if intended for downstream use.--helpupdated if customer-facing surface changed.Signed-off-by: Your Name <email>) per the DCO.Notes for reviewers
Anything reviewers should pay extra attention to — risky paths, follow-up tickets, intentional trade-offs.
Summary by CodeRabbit