Repository navigation
fix(rust): harden Anthropic transport failures - #443
Closed
Seth Juarez (sethjuarez) wants to merge 1 commit into
Closed
Seth 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()); |
Member
Author
|
Superseded by #481, which re-merges this onto |
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>
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