Skip to content

fix: wrap mid-stream transport errors - #1920

Open
xianjianlf2 wants to merge 1 commit into
anthropics:mainfrom
xianjianlf2:fix/wrap-midstream-transport-errors-1919
Open

fix: wrap mid-stream transport errors#1920
xianjianlf2 wants to merge 1 commit into
anthropics:mainfrom
xianjianlf2:fix/wrap-midstream-transport-errors-1919

Conversation

@xianjianlf2

Copy link
Copy Markdown

Summary

  • translate read timeouts raised while consuming sync and async streams into APITimeoutError
  • translate other httpx2.TransportError failures into APIConnectionError
  • preserve the original transport exception as __cause__
  • keep wrapping scoped to response-byte iteration so parsing and SDK-originated errors remain unchanged

The stream is not retried after events have already been yielded; this PR restores the SDK exception hierarchy without replaying a partially consumed response.

Fixes #1919.

Testing

  • UV_FROZEN=1 UV_SKIP_WHEEL_FILENAME_CHECK=1 ./scripts/test tests/test_streaming.py -q
    • Python 3.10 / Pydantic v2: 27 passed
    • Python 3.10 / Pydantic v1: 27 passed
    • Python 3.14 / Pydantic v2: 27 passed
    • MCP v2 suite: 39 passed
  • ./scripts/lint
    • Ruff, dependency caps, Pyright, Mypy, and import check passed
  • git diff --check

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.

Transport errors while consuming a stream escape as raw httpx exceptions instead of APITimeoutError / APIConnectionError

1 participant