Skip to content

fix(rust): harden Anthropic transport failures - #443

Open
Seth Juarez (sethjuarez) wants to merge 1 commit into
microsoft:mainfrom
sethjuarez:sejuare-microsoft/fix-anthropic-transport
Open

fix(rust): harden Anthropic transport failures#443
Seth Juarez (sethjuarez) wants to merge 1 commit into
microsoft:mainfrom
sethjuarez:sejuare-microsoft/fix-anthropic-transport

Conversation

@sethjuarez

Copy link
Copy Markdown
Member

Summary

  • honor model.connection.endpoint, then ANTHROPIC_BASE_URL, then the Anthropic default for messages and model discovery
  • normalize bases ending in /v1 so requests never duplicate the API version segment
  • surface Anthropic SSE provider errors as determinate failures and transport/decode/parse/premature-EOF failures as indeterminate
  • terminate failed streams without emitting accumulated tools, usage, or truncated success

Validation

  • cargo test --manifest-path runtime/rust/Cargo.toml -p prompty-anthropic
  • cargo 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 -- --check
  • cargo clippy --manifest-path runtime/rust/Cargo.toml --workspace --all-targets -- -D warnings
  • cargo test --manifest-path runtime/rust/Cargo.toml --workspace

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>
Copilot AI lite review requested due to automatic review settings August 4, 2026 09:46

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 /v1 suffix handling.
  • Convert SSE/provider error events into classified StreamFailure chunks 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());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants