Use Claude Code, Codex, VSCode, Pi, and OpenCode (and 6 other harnesses) for free (1.3B+ free tokens) from your terminal, app, IDE, or phone, and now from the browser with native browser sessions (multi-harness + multi-model) like OpenClaw (voice supported + ToS friendly)
Python
Handle SSLWantReadError during provider stream recovery (#1713)
lorenzozaned213961dcb3d
diff --git a/pyproject.toml b/pyproject.tomlindex 37319f25..6d164ff4 100644--- a/pyproject.toml+++ b/pyproject.toml@@ -4,7 +4,7 @@ build-backend = "hatchling.build"[project]name = "free-claude-code"-version = "6.1.2"+version = "6.1.3"description = "Local proxy connecting coding agents to OpenAI-compatible AI providers"readme = "README.md"requires-python = ">=3.14.0"diff --git a/src/free_claude_code/providers/failure_policy.py b/src/free_claude_code/providers/failure_policy.pyindex 990ddcfc..b3c48a55 100644--- a/src/free_claude_code/providers/failure_policy.py+++ b/src/free_claude_code/providers/failure_policy.py@@ -1,6 +1,7 @@"""Provider-owned SDK classification and retry qualification."""import json+import sslfrom collections.abc import Callable, Mappingfrom contextlib import suppressfrom dataclasses import replace@@ -242,6 +243,7 @@ def is_retryable_provider_error(exc: BaseException) -> bool:exc,(TimeoutError,+ ssl.SSLWantReadError,httpx.TimeoutException,httpx2.TimeoutException,httpx.RemoteProtocolError,@@ -269,6 +271,7 @@ def is_retryable_stream_error(exc: BaseException) -> bool:exc,(TimeoutError,+ ssl.SSLWantReadError,httpx.ReadTimeout,httpx2.ReadTimeout,httpx.RemoteProtocolError,@@ -311,6 +314,8 @@ def provider_error_message(return "Could not connect to provider."if isinstance(exc, httpx.RemoteProtocolError | httpx2.RemoteProtocolError):return "Provider connection was interrupted before a response was received."+ if isinstance(exc, ssl.SSLWantReadError):+ return "Could not read the provider response."if isinstance(exc, TimeoutError):if read_timeout_s is not None:return f"Provider request timed out after {read_timeout_s:g}s."@@ -423,7 +428,9 @@ def _classify_provider_failure(kind = FailureKind.UPSTREAMif isinstance(exc, TimeoutError | httpx.TimeoutException | httpx2.TimeoutException):kind = FailureKind.TIMEOUT- elif isinstance(exc, httpx.NetworkError | httpx2.NetworkError):+ elif isinstance(+ exc, ssl.SSLWantReadError | httpx.NetworkError | httpx2.NetworkError+ ):kind = FailureKind.UNAVAILABLEreturn _failure(kind,diff --git a/tests/providers/test_failure_policy.py b/tests/providers/test_failure_policy.pyindex 288fa554..f9b39ae1 100644--- a/tests/providers/test_failure_policy.py+++ b/tests/providers/test_failure_policy.py@@ -1,5 +1,6 @@"""Raw provider failure classification into the canonical neutral model."""+import sslfrom collections.abc import Callablefrom dataclasses import asdict, dataclass@@ -120,6 +121,24 @@ def test_stream_retry_classification_only_accepts_post_open_timeouts() -> None:assert not is_retryable_stream_error(httpx.PoolTimeout("pool", request=request))[email protected]("read_timeout_s", [None, 120])+def test_ssl_want_read_error_uses_stream_failure_policy(+ read_timeout_s: float | None,+) -> None:+ error = ssl.SSLWantReadError("the operation did not complete")++ assert is_retryable_stream_error(error)+ assert is_retryable_provider_error(error)+ failure = classify_provider_failure(+ error, provider_name="NIM", read_timeout_s=read_timeout_s, request_id="request"+ )+ assert failure.kind is FailureKind.UNAVAILABLE+ assert failure.status_code == 502+ assert failure.retryable+ assert "Could not read the provider response." in failure.message+ assert "timed out" not in failure.message++@pytest.mark.parametrize(("message", "body"),(diff --git a/tests/providers/test_provider_admission.py b/tests/providers/test_provider_admission.pyindex c6d404c4..961e9c37 100644--- a/tests/providers/test_provider_admission.py+++ b/tests/providers/test_provider_admission.py@@ -1,6 +1,7 @@"""Provider-owned admission and coordinated recovery contracts."""import asyncio+import sslimport timefrom collections.abc import Callablefrom datetime import UTC, datetime, timedelta@@ -286,17 +287,21 @@ async def test_attempt_cancellation_releases_concurrency() -> None:@pytest.mark.asyncio-async def test_run_call_uses_one_five_attempt_budget() -> None:+ "error",+ [_status_error(503), ssl.SSLWantReadError("read would block")],+ ids=["http_503", "tls_want_read"],+)+async def test_run_call_uses_one_five_attempt_budget(error: Exception) -> None:controller = _controller()attempts = 0- error = _status_error(503)async def fail() -> None:nonlocal attemptsattempts += 1raise error- with pytest.raises(httpx.HTTPStatusError) as exc_info:+ with pytest.raises(type(error)) as exc_info:await controller.start_execution().run_call(fail,operation_kind=ProviderOperationKind.GENERATION,@@ -307,7 +312,12 @@ async def test_run_call_uses_one_five_attempt_budget() -> None:@pytest.mark.asyncio-async def test_run_call_succeeds_without_multiplying_attempts() -> None:+ "error",+ [_status_error(429), ssl.SSLWantReadError("read would block")],+ ids=["http_429", "tls_want_read"],+)+async def test_run_call_succeeds_without_multiplying_attempts(error: Exception) -> None:controller = _controller(max_concurrency=1)attempts = 0@@ -315,7 +325,7 @@ async def test_run_call_succeeds_without_multiplying_attempts() -> None:nonlocal attemptsattempts += 1if attempts < 3:- raise _status_error(429)+ raise errorreturn "recovered"assert (diff --git a/uv.lock b/uv.lockindex 416f7dab..026cbdc0 100644--- a/uv.lock+++ b/uv.lock@@ -598,7 +598,7 @@ wheels = [[[package]]name = "free-claude-code"-version = "6.1.2"+version = "6.1.3"source = { editable = "." }dependencies = [{ name = "aiohttp" },