Skip to content

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

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

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());
@sethjuarez

Copy link
Copy Markdown
Member Author

Superseded by #481, which re-merges this onto main's evolved prompty-anthropic crate. The value here — ANTHROPIC_BASE_URL env fallback and idempotent /v1 handling via a shared endpoint.rs::build_api_url — is included there and verified via cargo test -p prompty-anthropic (55 tests). Closing in favor of #481.

Seth Juarez (sethjuarez) added a commit that referenced this pull request Aug 18, 2026
…ing (#443) onto 0.9.0 (#481)

* fix(openai): require nested strict schema fields (rebase #441 onto emitter 0.9.0)

Salvages the still-valid correctness fix from PR #441, re-authored for main's
current state (schema reorg + @typra/emitter 0.9.0):

- prompty-openai wire.rs: in OpenAI strict mode, every object property must
  appear in 
equired (optional fields are represented as nullable).
- Vector structured_output_nested_optional authored at its NEW source of
  truth schema/model/conformance/vectors/wire.tsp; �ectors.json and the
  generated python conformance test are regenerated via
pm run generate
  (not hand-edited). PR #441's edit to the legacy spec/vectors/wire/
  wire_vectors.json is dropped since main removed that catalog.
- spec.md / wire-format.mdx: document the recursive strict-mode rule.

Verified: cargo test -p prompty-openai (lib + wire_vectors) 107 passed.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

* fix(rust): harden Anthropic transport failures (rebase #443 onto main)

Salvages PR #443, re-merged onto main's evolved prompty-anthropic crate:

- Add endpoint.rs with shared build_api_url(): adds ANTHROPIC_BASE_URL env
  fallback and idempotent /v1 handling that main's inline build_url lacked.
- executor.rs and models.rs now delegate URL construction to the shared
  helper; classify transport/SSE failures as the PR intended.
- Conflict resolution: kept main's Agent type name (PR predated the
  Prompty->Agent rename) while adopting the PR's ANTHROPIC_BASE_URL test
  env guards.

Verified: cargo test -p prompty-anthropic — 55 lib + wire/discovery/vectors
tests pass; live integration tests remain env-gated (ignored).

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

* chore(schema): regenerate TS vector-conformance test for new vector

The #441 salvage added the structured_output_nested_optional vector to
wire.tsp and regenerated vectors.json + the Python conformance test, but
the generated TypeScript vector-conformance.test.ts was inadvertently
reverted along with unrelated prettier formatting churn. Regenerated with
the TS workspace installed (prettier present) so only the genuine vector
addition remains. Fixes the 'regeneration produces no diff' CI gate.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

---------

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
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