fix(anthropic): parse non-streaming responses (H-04)#40
Conversation
📝 WalkthroughWalkthroughAnthropic completion handling now uses separate parsers for streaming SSE events and non-streaming JSON responses. Non-streaming parsing extracts text, tool use, thinking, usage, cache tokens, and API errors, with expanded tests. ChangesAnthropic response parsing
Estimated code review effort: 4 (Complex) | ~45 minutes Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
@coderabbitai review |
✅ Action performedReview finished.
|
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/llm/anthropic.rs (1)
550-564: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick winDefault missing Anthropic non-streaming token counts to 0 for consistency.
Anthropic non-streaming
usage.input_tokens/usage.output_tokensare normally present, but unlike the streaming parser, this complete-response path turns a missing/invalid usage object or count into a hard parse error after content has already been parsed. Default these token counts to 0 likeUsage::default()to keep empty usage from discarding otherwise-usable responses.🤖 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 `@src/llm/anthropic.rs` around lines 550 - 564, Update the non-streaming Anthropic response parsing around the usage extraction in the response-construction path to tolerate missing or invalid usage data. Default both input_tokens and output_tokens to 0, including when the usage object is absent, while preserving the parsed role and content instead of returning an error.
🤖 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 `@src/llm/anthropic.rs`:
- Around line 550-564: Update the non-streaming Anthropic response parsing
around the usage extraction in the response-construction path to tolerate
missing or invalid usage data. Default both input_tokens and output_tokens to 0,
including when the usage object is absent, while preserving the parsed role and
content instead of returning an error.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: c4737792-4120-465f-b90c-81c9448b7e1a
📒 Files selected for processing (1)
src/llm/anthropic.rs
Summary
Testing
cargo test --locked llm::anthropic::tests -- --test-threads=1(10 passed)cargo test --locked --all-targets -- --test-threads=1(227 passed)git diff --check upstream/main...HEADFixes #18