fix(anthropic): preserve valid complete responses#45
Conversation
Amp-Thread-ID: https://ampcode.com/threads/T-019f8c77-2625-751e-8ea1-8bfd0511a4d1 Co-authored-by: Amp <amp@ampcode.com>
Amp-Thread-ID: https://ampcode.com/threads/T-019f8c77-2625-751e-8ea1-8bfd0511a4d1 Co-authored-by: Amp <amp@ampcode.com>
📝 WalkthroughWalkthroughThe changes improve JSON escaping and parsing, make non-streaming Anthropic response handling tolerant of incomplete usage metadata while validating tool inputs, and isolate notification tests that modify ChangesJSON serialization and parsing
Anthropic response parsing
Notification test isolation
Estimated code review effort: 3 (Moderate) | ~20 minutes Possibly related PRs
Suggested reviewers: 🚥 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 |
Amp-Thread-ID: https://ampcode.com/threads/T-019f8e51-b5fa-7669-80da-ef0145d2ede9 Co-authored-by: Pierre Bruno <pierrebruno@hotmail.ch>
Co-authored-by: Pierre Bruno <pierrebruno@hotmail.ch>
✅ Action performedReview finished.
|
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/notify.rs (1)
148-158: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick winRestore the default-behavior assertion.
enabled_defaults_true_without_envno longer tests its named contract. RemoveCAIRN_SOUNDunder the guard and assertenabled()is true before testing the explicit"0","false", and"1"values.🤖 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/notify.rs` around lines 148 - 158, Update enabled_defaults_true_without_env to remove CAIRN_SOUND while ENV_LOCK is held, then assert enabled() returns true before setting and validating the explicit "0", "false", and "1" values. Preserve the existing SoundEnv guard and explicit-value assertions.
🤖 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 `@src/notify.rs`:
- Line 149: Update the test guards acquiring ENV_LOCK at both locations to
recover from mutex poisoning by using the poisoned guard’s inner value instead
of calling unwrap directly. Preserve the existing guard lifetime and environment
restoration behavior so subsequent tests can run after a prior panic.
---
Outside diff comments:
In `@src/notify.rs`:
- Around line 148-158: Update enabled_defaults_true_without_env to remove
CAIRN_SOUND while ENV_LOCK is held, then assert enabled() returns true before
setting and validating the explicit "0", "false", and "1" values. Preserve the
existing SoundEnv guard and explicit-value assertions.
🪄 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: Pro Plus
Run ID: 1be713e6-0999-4acd-9f42-6ef64eaa4d9e
📒 Files selected for processing (3)
src/json.rssrc/llm/anthropic.rssrc/notify.rs
|
|
||
| #[test] | ||
| fn enabled_defaults_true_without_env() { | ||
| let _guard = ENV_LOCK.lock().unwrap(); |
There was a problem hiding this comment.
🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win
Recover from mutex poisoning in these test guards.
If either test panics after acquiring ENV_LOCK, the mutex becomes poisoned and the other test will panic at .unwrap() before restoring or testing its environment. Use unwrap_or_else(|error| error.into_inner()) so one failed assertion does not cascade into unrelated test failures.
Also applies to: 163-163
🤖 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/notify.rs` at line 149, Update the test guards acquiring ENV_LOCK at both
locations to recover from mutex poisoning by using the poisoned guard’s inner
value instead of calling unwrap directly. Preserve the existing guard lifetime
and environment restoration behavior so subsequent tests can run after a prior
panic.
euxaristia
left a comment
There was a problem hiding this comment.
LGTM! Approved after audit.
Summary
Testing
cargo test llm::anthropic::tests --locked -- --nocapturecargo test json::tests --locked -- --nocapturecargo test --locked(232 passed)cargo check --lockedcargo build --lockedgit diff --checkFollow-up to #40.
Fixes #46.
Summary by CodeRabbit
Bug Fixes
Tests