fix: Retry on 408 and respect Retry-After header#426
Open
Conversation
408 (Request Timeout) was incorrectly treated as a non-retryable client error. Retry-After response headers were ignored during backoff. Replace backoff library usage with a manual retry loop that honours Retry-After when present and falls back to exponential backoff otherwise. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Retry-After can be seconds or an HTTP-date per RFC 7231. Fall back to email.utils.parsedate_to_datetime when the numeric parse fails. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Contributor
posthog-python Compliance ReportDate: 2026-02-06 13:05:31 UTC ✅ All Tests Passed!29/29 tests passed Capture Tests✅ 29/29 tests passed View Details
|
When APIError.status is "N/A" (no HTTP status), treat it as non-retryable to avoid unexpected retry loops on errors the SDK cannot classify. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Verify time.sleep is called with the Retry-After value when present, uses exponential backoff (2^attempt) when absent, and that 408 is retried. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.
Problem
The SDK failed 2 of 29 compliance tests:
backofflibrary's exponential backoff ignored theRetry-Afterresponse header, so the SDK didn't wait the server-requested delay before retrying.Changes
posthog/request.py: Addedretry_afterfield toAPIError. Extract theRetry-Afterheader from error responses and pass it through.posthog/consumer.py: Replacedbackoff.on_exceptionwith a manual retry loop that uses theRetry-Aftervalue when present and falls back to exponential backoff (2^attemptseconds, capped at 30s) otherwise. Added 408 to the set of retryable status codes alongside 429.Testing