chore(protocol): Use LlmClientError for stream too#137
Conversation
- In `protocol` differentiate between a `DecodeError` and a `StreamError`. Previously they were both `Error`. - Introduce an LlmClientError::General(String) for the unit tests to avoid using `std::io::Error::other`. - Introduce and LlmClientError::Ffi(err) for errors at the bindings boundary. That allows wrapping the `PyErr` (or Go, etc later) directly. Fewer boxing allocations and fewer conversions. Often we can pass the LlmClientError right through. Assisted-by: Codex:GPT 5.6 Sol medium Assisted-by: Claude:Opus 5 medium Signed-off-by: Graham King <grahamk@nvidia.com>
|
@coderabbitai full review |
✅ Action performedFull review finished. |
WalkthroughThe change replaces generic boxed streaming errors with typed ChangesTyped error flow
Estimated code review effort: 4 (Complex) | ~45 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
crates/libsy/src/error.rs (1)
89-98: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick winPreserve
external_boxedor provide a deprecation plan.
LibsyError::external_boxedis a public API. Removing it is a downstream-breaking change even if all repository call sites now useexternal. Keep a deprecated forwarding shim or document the required major-version/deprecation migration before merging.As per coding guidelines, do not remove or rename public API exports without an explicit deprecation plan.
🤖 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/libsy/src/error.rs` around lines 89 - 98, Preserve the public LibsyError::external_boxed API while introducing or retaining external. Add external_boxed as a deprecated forwarding shim to external, or provide an explicit major-version deprecation and migration plan; do not remove or rename the existing export without one.Source: Coding guidelines
🧹 Nitpick comments (1)
crates/switchyard-translation/src/helpers.rs (1)
81-85: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winDocument the changed public stream APIs.
Add
///docs describing each helper’s typed error contract and streaming behavior.As per coding guidelines, “Use
///documentation comments for public Rust items.”Also applies to: 123-129
🤖 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 81 - 85, Document the public stream helpers, including encode_stream and the additionally referenced helper, with /// comments describing their streaming behavior and typed LlmClientError contract. Place the documentation directly above each public function without changing their signatures or implementation.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/protocol/src/client.rs`:
- Around line 93-104: Preserve deprecated compatibility variants for the removed
public APIs: in crates/protocol/src/client.rs lines 93-104, restore and
deprecate LlmClientError::Other(BoxError), directing callers toward Ffi or
General; in crates/protocol/src/stream.rs lines 118-123, restore and deprecate
LlmResponseChunk::Error, document DecodeError and StreamError, and describe the
migration path for stream consumers.
In `@crates/switchyard-translation/src/codecs/openai_chat/stream.rs`:
- Around line 50-54: Update the object-handling logic in the OpenAI stream event
decoder so objects containing an "error" field are classified as DecodeError
rather than proceeding to MessageStart or producing an empty response. Extract
and preserve the error message when available, matching the error-frame shape
emitted by the encoder around the existing error serialization logic, while
leaving normal object-shaped events unchanged.
---
Outside diff comments:
In `@crates/libsy/src/error.rs`:
- Around line 89-98: Preserve the public LibsyError::external_boxed API while
introducing or retaining external. Add external_boxed as a deprecated forwarding
shim to external, or provide an explicit major-version deprecation and migration
plan; do not remove or rename the existing export without one.
---
Nitpick comments:
In `@crates/switchyard-translation/src/helpers.rs`:
- Around line 81-85: Document the public stream helpers, including encode_stream
and the additionally referenced helper, with /// comments describing their
streaming behavior and typed LlmClientError contract. Place the documentation
directly above each public function without changing their signatures or
implementation.
🪄 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: b4d2eecb-6f64-4b55-8959-14feab2481b0
📒 Files selected for processing (17)
crates/libsy-llm-client/src/client.rscrates/libsy/examples/ensemble.rscrates/libsy/examples/research_agent.rscrates/libsy/examples/research_agent_core.rscrates/libsy/examples/streaming_agent.rscrates/libsy/src/algorithms/fall_through.rscrates/libsy/src/algorithms/llm_class.rscrates/libsy/src/core/algorithm.rscrates/libsy/src/error.rscrates/protocol/src/client.rscrates/protocol/src/stream.rscrates/switchyard-py/src/libsy_bindings.rscrates/switchyard-translation/src/codecs/anthropic/stream.rscrates/switchyard-translation/src/codecs/openai_chat/stream.rscrates/switchyard-translation/src/codecs/responses/stream.rscrates/switchyard-translation/src/codecs/stream.rscrates/switchyard-translation/src/helpers.rs
Previously that would go to MessageStart. Now it's StreamError. Thanks Code Rabbit. Signed-off-by: Graham King <grahamk@nvidia.com>
protocoldifferentiate between aDecodeErrorand aStreamError. Previously they were bothError.std::io::Error::other.the
PyErr(or Go, etc later) directly.Fewer boxing allocations and fewer conversions. Often we can pass the LlmClientError right through.
Follow-on to #129
Assisted-by: Codex:GPT 5.6 Sol medium
Assisted-by: Claude:Opus 5 medium
Signed-off-by: Graham King grahamk@nvidia.com
Summary by CodeRabbit
Bug Fixes
Improvements