Skip to content

fix: Retry flags requests on 502 and 504#196

Merged
marandaneto merged 3 commits into
mainfrom
fix/flags-retry-502-504
Jul 2, 2026
Merged

fix: Retry flags requests on 502 and 504#196
marandaneto merged 3 commits into
mainfrom
fix/flags-retry-502-504

Conversation

@marandaneto

Copy link
Copy Markdown
Member

💡 Motivation and Context

Remote feature flag evaluation uses /flags/?v=2. The SDK already retries transient curl/network failures using feature_flag_request_max_retries; this extends that same retry loop to retry HTTP 502 and 504 responses for the flags endpoint only.

This does not change capture/batch retry behavior, and non-retryable flags HTTP statuses such as 408, 429, and 500 remain non-retryable.

💚 How did you test it?

  • composer install --no-interaction --prefer-dist
  • ./vendor/bin/phpunit --no-coverage --filter 'testFlagsRequest(RetriesHttp502And504|DoesNotRetryHttp502And504WhenConfiguredMaxRetriesIsZero|DoesNotRetryHttpStatusErrors|RetriesTransientCurlErrors|StopsAfterExhaustingTransientCurlErrorRetries|DoesNotRetryWhenConfiguredMaxRetriesIsZero|DoesNotRetryConnectionRefused)' test/FeatureFlagTest.php
  • ./vendor/bin/phpunit --no-coverage --filter 'testFlagsRequest(RetriesHttp502And504|DoesNotRetryHttp502And504WhenConfiguredMaxRetriesIsZero)' test/FeatureFlagTest.php
  • php -l lib/Client.php && php -l lib/PostHog.php && php -l test/FeatureFlagTest.php
  • ./vendor/bin/phpcs lib/Client.php lib/PostHog.php test/FeatureFlagTest.php (0 errors; existing warnings remain)

📝 Checklist

  • I reviewed the submitted code.
  • I added tests to verify the changes.
  • I updated the docs if needed.
  • No breaking change or entry added to the changelog.

If releasing new changes

  • Ran pnpm changeset to generate a changeset file

🤖 Agent context

Autonomy: Human-driven (agent-assisted)

Implemented with an AI coding agent in response to a human-directed request. The change was kept to the flags request path: HTTP 502/504 now reuse the existing feature flag retry budget, while transient curl retry behavior is preserved and other HTTP status errors remain non-retryable.

@marandaneto marandaneto self-assigned this Jul 2, 2026
@greptile-apps

greptile-apps Bot commented Jul 2, 2026

Copy link
Copy Markdown

Reviews (1): Last reviewed commit: "fix: retry flags requests on 502 and 504" | Re-trigger Greptile

Comment thread test/FeatureFlagTest.php
@github-actions

github-actions Bot commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

posthog-php Compliance Report

Date: 2026-07-02 11:46:42 UTC
Duration: 95089ms

✅ All Tests Passed!

45/45 tests passed


Capture Tests

29/29 tests passed

View Details
Test Status Duration
Format Validation.Event Has Required Fields 11ms
Format Validation.Event Has Uuid 6ms
Format Validation.Event Has Lib Properties 6ms
Format Validation.Distinct Id Is String 6ms
Format Validation.Token Is Present 6ms
Format Validation.Custom Properties Preserved 6ms
Format Validation.Event Has Timestamp 5ms
Retry Behavior.Retries On 503 5315ms
Retry Behavior.Does Not Retry On 400 2009ms
Retry Behavior.Does Not Retry On 401 2010ms
Retry Behavior.Respects Retry After Header 8015ms
Retry Behavior.Implements Backoff 15725ms
Retry Behavior.Retries On 500 5114ms
Retry Behavior.Retries On 502 5114ms
Retry Behavior.Retries On 504 5114ms
Retry Behavior.Max Retries Respected 16528ms
Deduplication.Generates Unique Uuids 11ms
Deduplication.Preserves Uuid On Retry 5113ms
Deduplication.Preserves Uuid And Timestamp On Retry 10312ms
Deduplication.Preserves Uuid And Timestamp On Batch Retry 5116ms
Deduplication.No Duplicate Events In Batch 11ms
Deduplication.Different Events Have Different Uuids 7ms
Compression.Sends Gzip When Enabled 6ms
Batch Format.Uses Proper Batch Structure 6ms
Batch Format.Flush With No Events Sends Nothing 3ms
Batch Format.Multiple Events Batched Together 11ms
Error Handling.Does Not Retry On 403 2007ms
Error Handling.Does Not Retry On 413 2009ms
Error Handling.Retries On 408 5113ms

Feature_Flags Tests

16/16 tests passed

View Details
Test Status Duration
Request Payload.Request With Person Properties Device Id 6ms
Request Payload.Flags Request Uses V2 Query Param 5ms
Request Payload.Flags Request Hits Flags Path Not Decide 4ms
Request Payload.Flags Request Omits Authorization Header 5ms
Request Payload.Token In Flags Body Matches Init 4ms
Request Payload.Groups Round Trip 5ms
Request Payload.Groups Default To Empty Object 5ms
Request Payload.Person Properties Distinct Id Auto Populated When Caller Omits It 4ms
Request Payload.Disable Geoip False Propagates As Geoip Disable False 5ms
Request Payload.Disable Geoip Omitted Defaults To False 4ms
Request Payload.Flag Keys To Evaluate Contains Only Requested Key 5ms
Request Lifecycle.No Flags Request On Init Alone 2ms
Request Lifecycle.No Flags Request On Normal Capture 6ms
Request Lifecycle.Two Flag Calls Produce Two Remote Requests 7ms
Request Lifecycle.Mock Response Value Is Returned To Caller 5ms
Side Effect Events.Get Feature Flag Captures Feature Flag Called Event 6ms

@marandaneto marandaneto marked this pull request as ready for review July 2, 2026 11:50
@marandaneto marandaneto requested a review from a team as a code owner July 2, 2026 11:50
@greptile-apps

greptile-apps Bot commented Jul 2, 2026

Copy link
Copy Markdown

Reviews (2): Last reviewed commit: "chore: add flags retry changeset" | Re-trigger Greptile

@marandaneto marandaneto merged commit 6db62ec into main Jul 2, 2026
23 checks passed
@marandaneto marandaneto deleted the fix/flags-retry-502-504 branch July 2, 2026 13:27
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.

2 participants