Retry transient HTTP failures + require all properties in strict schemas#288
Merged
Conversation
Add bounded retry with exponential backoff to HTTPClient.post/get/post_multipart on transient network errors (httpx timeouts, connection/read errors) and retryable status codes (408/429/500/502/503/504); MAX_RETRIES=2 by default, then re-raise. Brings transport resilience in line with the openai/anthropic SDKs. Streaming is unchanged.
StrictJsonSchemaGenerator set additionalProperties:false but never required, so schemas with defaulted fields (which Pydantic omits from required) 400 on OpenAI and xAI strict mode. Force required = all properties for every object.
Code reviewNo issues found. Checked for bugs and CLAUDE.md compliance. |
Collapse the five near-identical TestHTTPClientRetry cases into one parametrized test (transient/status retried, non-retryable, exhausted) plus the reraise case.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Two independent primitive-hardening fixes, one commit each.
feat(http)— retry transient HTTP failuresHTTPClient.post/get/post_multipartnow retry transient network failures (httpx timeouts, connection/read errors) and retryable status codes (408/429/500/502/503/504) with bounded exponential backoff (MAX_RETRIES=2), then fail hard. This matches the retry the OpenAI and Anthropic Python SDKs ship by default — and httpx's built-in transportretriesonly cover connection failures, not read timeouts. Streaming requests are unchanged.fix(structured-outputs)— require all properties in strict schemasStrictJsonSchemaGeneratorforcedadditionalProperties: falsebut neverrequired. OpenAI and xAI strict mode require every property inrequired, and Pydantic omits any field that has a default — so a model with defaulted fields is rejected (400, "missing required"). The generator now forcesrequired = list(properties)on every object, completing the strict transform for OpenAI, xAI, and Anthropic at once.Both changes carry unit tests; the full unit suite plus ruff, mypy, and bandit pass (via pre-commit).