Skip to content

fix: detect SSE stream error events instead of silently discarding them#192

Merged
Kamilbenkirane merged 1 commit into
mainfrom
fix/stream-error-detection
Feb 25, 2026
Merged

fix: detect SSE stream error events instead of silently discarding them#192
Kamilbenkirane merged 1 commit into
mainfrom
fix/stream-error-detection

Conversation

@Kamilbenkirane

Copy link
Copy Markdown
Member

Summary

Closes #144

  • Mid-stream error events from providers (e.g. Anthropic overloaded_error, OpenAI server_error) were silently discarded — the consumer received partial content with no indication of failure
  • Add ClassVar-driven _parse_stream_error to the base Stream class, handling both generic SSE error patterns (type-based and field-based) via a single _error_type_fields ClassVar
  • Add _build_error_from_value helper for shared error extraction logic
  • Add StreamEventError exception with error_type, event_data, provider attributes
  • Add raise_for_status() to stream_post() for HTTP-level errors
  • Only 2 providers need custom _parse_stream_error overrides (Google Interactions, OpenResponses) — all others use the base or ClassVar-only override
  • Remove dead SSE_EVENT_ERROR constant from Anthropic config

Test plan

  • 9 unit tests covering type-based errors, field-based errors, ClassVar override, string fallback, mid-stream errors, missing message default, and event data preservation
  • All 497 unit tests pass
  • mypy, ruff, bandit all pass

…carding them (#144)

Add ClassVar-driven error detection to the base Stream class. Mid-stream
error events from providers (e.g. Anthropic overloaded_error, OpenAI
server_error) now raise StreamEventError instead of being silently skipped.

- Add _error_type_fields ClassVar and _build_error_from_value helper to Stream
- Add _parse_stream_error base implementation handling type-based and field-based SSE error patterns
- Add StreamEventError exception with error_type, event_data, provider attributes
- Add raise_for_status() to stream_post() for HTTP-level errors
- Provider overrides use ClassVar only (Google GenerateContent) or ClassVar + helper (Google Interactions, OpenResponses)
- Remove dead SSE_EVENT_ERROR constant from Anthropic config
@claude

claude Bot commented Feb 25, 2026

Copy link
Copy Markdown

Code review

No issues found. Checked for bugs and CLAUDE.md compliance.

@Kamilbenkirane Kamilbenkirane merged commit eb0771d into main Feb 25, 2026
11 checks passed
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.

SSE stream error events are silently discarded — add error detection to streaming pipeline

1 participant