fix: improve OpenRouter protocol interoperability - #237
Conversation
WalkthroughThe client reserves ChangesHeader forwarding
Stream error metrics
Stream translation
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.
Actionable comments posted: 2
🧹 Nitpick comments (1)
crates/switchyard-server/tests/server.rs (1)
1133-1133: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winDocument the important stream-failure contract.
Add a short comment stating that a terminal stream failure increments error statistics and metrics without recording usage or terminal latency.
As per coding guidelines, “comments for ... important tests” are required.
Proposed comment
+// A terminal stream failure records errors without usage or terminal latency. async fn streaming_error_records_error_without_usage_or_latency() -> TestResult {🤖 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-server/tests/server.rs` at line 1133, Above the streaming_error_records_error_without_usage_or_latency test, add a brief comment documenting that terminal stream failures increment error statistics and metrics while recording neither usage nor terminal latency.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.
Inline comments:
In `@crates/switchyard-server/src/usage_metrics.rs`:
- Around line 94-102: Normalize the optional tier value at the start of
record_stream_error, trimming whitespace and converting empty values to None,
then pass the normalized tier to both StatsAccumulator::record_stream_error and
attributes. Apply the same normalization consistently in the related token and
latency metric recording paths that currently pass the original tier.
In `@crates/switchyard-translation/src/sse.rs`:
- Around line 17-22: Update done_marker and the decode_stream flow so data:
[DONE] produces a distinct terminal result instead of being treated as an empty
frame. Detect the marker in parse_json_sse_frame or its caller, return the
marker-specific result, and break decoding immediately while preserving
empty-frame skipping and normal frame processing.
---
Nitpick comments:
In `@crates/switchyard-server/tests/server.rs`:
- Line 1133: Above the streaming_error_records_error_without_usage_or_latency
test, add a brief comment documenting that terminal stream failures increment
error statistics and metrics while recording neither usage nor terminal latency.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Enterprise
Run ID: 036c77bf-f046-4ebe-b59d-f6648bdfd457
📒 Files selected for processing (7)
crates/libsy-llm-client/src/client.rscrates/switchyard-server/src/stats/accumulator.rscrates/switchyard-server/src/usage_metrics.rscrates/switchyard-server/tests/server.rscrates/switchyard-translation/src/codecs/openai_chat/stream.rscrates/switchyard-translation/src/sse.rscrates/switchyard-translation/tests/stream_translation.rs
Signed-off-by: nachiketb <nachiketb@nvidia.com>
c70579a to
c210708
Compare
Signed-off-by: nachiketb <nachiketb@nvidia.com>
What
[DONE]termination on Anthropic-compatible SSE streamsWhy
OpenRouter exercises provider-compatible behavior that exposed four gaps: compressed responses the HTTP client could not decode, Anthropic streams ending with
[DONE], usage arriving afterfinish_reason, and stream failures being reported as successful in stats.How
The fixes stay at their existing ownership boundaries in the LLM client, translation codecs, and server usage observer. Routed calls remain counted once; terminal stream failures increment only the missing error counters.
What to review
Accept-EncodingValidation
cargo test -p switchyard-llm-client forwards_metadata_headers_except_reservedcargo test -p switchyard-translationcargo test -p switchyard-server streaming_error_records_error_without_usage_or_latencycargo clippy -p switchyard-llm-client -p switchyard-translation -p switchyard-server --all-targets -- -D warnings/v1/statsSummary by CodeRabbit
Accept-Encodingheaders are no longer forwarded unexpectedly.[DONE]marker across supported formats.