Skip to content

fix(providers): normalize mid-stream Anthropic failures to a typed error (#4) - #317

Open
Hustler490 wants to merge 1 commit into
AyinkxLab:mainfrom
Hustler490:fix/4-anthropic-stream-errors
Open

Hustler490 wants to merge 1 commit into
AyinkxLab:mainfrom
Hustler490:fix/4-anthropic-stream-errors

Conversation

@Hustler490

Copy link
Copy Markdown

Closes #4.

What

AnthropicProvider.stream() translated the initial POST failure into a ProviderError, but read the response body outside any handler: a connection dropped mid-stream leaked
equests.exceptions.ChunkedEncodingError to the SSE layer instead of a typed error. This mirrors the OpenAI provider fix.

  • �pp/services/providers/anthropic.py: wrap the body-reading loop in ry/except requests.RequestException and re-raise ProviderUnavailableError with a safe message. The delta sequence and content_block_delta handling are unchanged.
  • ests/test_providers.py: adds est_stream_mid_stream_failure_raises_typed_error (feeds one valid delta, then raises ChunkedEncodingError; asserts the already-yielded chunk is delivered and the error is a ProviderUnavailableError). Mocks only - no live network.

Acceptance criteria

  • Non-streaming chat() returns a valid ProviderResponse (unchanged; pinned by existing tests).
  • Streaming integrates with the SSE layer (unchanged delta behaviour).
  • Anthropic SDK errors map to typed ProviderErrors - now including mid-stream transport failures.
  • Unit tests use mocks; no live network calls.

@drips-wave

drips-wave Bot commented Sep 29, 2026

Copy link
Copy Markdown

@Hustler490 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@Hustler490
Hustler490 force-pushed the fix/4-anthropic-stream-errors branch from 47addec to 9be7a2b Compare October 4, 2026 15:58
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.

Anthropic provider implementation

2 participants