fix(llm): retry statusless mid-stream provider errors (quota/billing)

The SDK's http_status retry policy only retries errors carrying a known
HTTP status code, but quota/billing (and other provider-side) failures
often surface inside a streamed response as a bare error with no status
code, so they were failing on the first attempt. Add a statusless retry
policy to DEFAULT_MODEL_RETRY (retry count and backoff unchanged) so they
are retried before a genuine exhaustion fails the run; user aborts are
never retried.
This commit is contained in:
Ahmed Allam
2026-07-17 16:47:14 -07:00
committed by Ahmed Allam
parent b9c2592b53
commit 9aa151c687
+1 -11
View File
@@ -22,17 +22,7 @@ if TYPE_CHECKING:
def _retry_statusless_provider_errors(context: RetryPolicyContext) -> bool: def _retry_statusless_provider_errors(context: RetryPolicyContext) -> bool:
"""Retry provider errors that arrive without an HTTP status code. """Retry statusless provider errors (e.g. mid-stream quota/billing), but not aborts."""
Quota, billing, and other provider-side failures frequently surface *inside*
a streamed response as a bare error with no ``status_code`` (the transport
already returned ``200`` before the failure). The built-in ``http_status``
policy skips these because it requires a known code, so they would otherwise
fail on the first attempt. Retrying a statusless error (the runner still
refuses to replay a stream once content has been emitted, and never retries a
user abort) mirrors the pre-SDK engine, which retried any error lacking a
definitive client status code.
"""
normalized = context.normalized normalized = context.normalized
if normalized.is_abort: if normalized.is_abort:
return False return False