fix(rust): harden Anthropic transport failures - #443
Open
Seth Juarez (sethjuarez) wants to merge 1 commit into
Open
fix(rust): harden Anthropic transport failures#443Seth Juarez (sethjuarez) wants to merge 1 commit into
Seth Juarez (sethjuarez) wants to merge 1 commit into
Conversation
Honor Anthropic base URL overrides without duplicating API versions, and surface provider versus transport SSE failures with canonical outcome semantics. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR hardens the Rust Anthropic runtime’s endpoint resolution and streaming failure handling, ensuring consistent base URL selection and clearer failure semantics for SSE streams.
Changes:
- Centralize Anthropic API base URL construction (connection endpoint →
ANTHROPIC_BASE_URL→ default) and normalize/v1suffix handling. - Convert SSE/provider error events into classified
StreamFailurechunks and ensure failed streams terminate without emitting accumulated tools/usage. - Add targeted tests covering endpoint building, premature EOF detection, and failure classification.
Show a summary per file
| File | Description |
|---|---|
| runtime/rust/prompty-anthropic/src/processor.rs | Detects stream error events and maps them to determinate vs indeterminate StreamFailure; adds regression tests. |
| runtime/rust/prompty-anthropic/src/models.rs | Uses shared endpoint builder for model discovery; serializes env-sensitive test. |
| runtime/rust/prompty-anthropic/src/lib.rs | Registers the new internal endpoint module. |
| runtime/rust/prompty-anthropic/src/executor.rs | Uses shared endpoint builder for messages URL; reports premature EOF as an SSE transport error; adds tests. |
| runtime/rust/prompty-anthropic/src/endpoint.rs | New shared helper for building Anthropic API URLs with /v1 normalization and env/connection precedence. |
| runtime/rust/prompty-anthropic/README.md | Documents ANTHROPIC_BASE_URL behavior and precedence vs model.connection.endpoint. |
Review details
- Files reviewed: 6/6 changed files
- Comments generated: 1
- Review effort level: Lite
Comment on lines
+8
to
+18
| let endpoint = connection | ||
| .get("endpoint") | ||
| .and_then(Value::as_str) | ||
| .filter(|value| !value.is_empty()) | ||
| .map(ToString::to_string) | ||
| .or_else(|| { | ||
| std::env::var("ANTHROPIC_BASE_URL") | ||
| .ok() | ||
| .filter(|value| !value.is_empty()) | ||
| }) | ||
| .unwrap_or_else(|| DEFAULT_BASE_URL.to_string()); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
model.connection.endpoint, thenANTHROPIC_BASE_URL, then the Anthropic default for messages and model discovery/v1so requests never duplicate the API version segmentValidation
cargo test --manifest-path runtime/rust/Cargo.toml -p prompty-anthropiccargo test --manifest-path runtime/rust/Cargo.toml -p prompty-anthropic --test integration -- --ignored --test-threads=1(4 live Anthropic tests passed)cargo fmt --manifest-path runtime/rust/Cargo.toml --all -- --checkcargo clippy --manifest-path runtime/rust/Cargo.toml --workspace --all-targets -- -D warningscargo test --manifest-path runtime/rust/Cargo.toml --workspace