Skip to content

fix: Retry flags only on transport errors#155

Merged
marandaneto merged 9 commits into
mainfrom
pi-flags-network-retry-20260628
Jul 2, 2026
Merged

fix: Retry flags only on transport errors#155
marandaneto merged 9 commits into
mainfrom
pi-flags-network-retry-20260628

Conversation

@marandaneto

Copy link
Copy Markdown
Member

💡 Motivation and Context

Align Elixir /flags?v=2 retry behavior with the other SDK fixes: retry only bounded network/transport/timeout failures, and do not retry HTTP/API status responses like 408, 429, or 5xx.

This overrides Req's :transient behavior for /flags so server responses are surfaced immediately while transient transport failures still get one retry by default.

💚 How did you test it?

  • mix test test/posthog/api/client_test.exs test/posthog/config_test.exs
  • mix test

📝 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 sampo add to generate a changeset file

🤖 Agent context

Autonomy: Human-driven (agent-assisted)

Implemented with pi. /flags now uses a request-specific Req retry function that skips HTTP responses, retries transport exceptions, uses default max retries of 1 with 0 disabling retries, and applies exponential backoff starting at 300ms.

@marandaneto marandaneto self-assigned this Jun 28, 2026
@github-actions

github-actions Bot commented Jun 28, 2026

Copy link
Copy Markdown
Contributor

posthog-elixir Compliance Report

Date: 2026-07-02 10:07:11 UTC
Duration: 117671ms

✅ All Tests Passed!

46/46 tests passed


Capture Tests

29/29 tests passed

View Details
Test Status Duration
Format Validation.Event Has Required Fields 609ms
Format Validation.Event Has Uuid 611ms
Format Validation.Event Has Lib Properties 610ms
Format Validation.Distinct Id Is String 610ms
Format Validation.Token Is Present 609ms
Format Validation.Custom Properties Preserved 610ms
Format Validation.Event Has Timestamp 609ms
Retry Behavior.Retries On 503 5615ms
Retry Behavior.Does Not Retry On 400 2614ms
Retry Behavior.Does Not Retry On 401 2613ms
Retry Behavior.Respects Retry After Header 5616ms
Retry Behavior.Implements Backoff 15625ms
Retry Behavior.Retries On 500 5615ms
Retry Behavior.Retries On 502 5615ms
Retry Behavior.Retries On 504 5614ms
Retry Behavior.Max Retries Respected 15626ms
Deduplication.Generates Unique Uuids 622ms
Deduplication.Preserves Uuid On Retry 5615ms
Deduplication.Preserves Uuid And Timestamp On Retry 10621ms
Deduplication.Preserves Uuid And Timestamp On Batch Retry 5618ms
Deduplication.No Duplicate Events In Batch 616ms
Deduplication.Different Events Have Different Uuids 612ms
Compression.Sends Gzip When Enabled 610ms
Batch Format.Uses Proper Batch Structure 610ms
Batch Format.Flush With No Events Sends Nothing 606ms
Batch Format.Multiple Events Batched Together 615ms
Error Handling.Does Not Retry On 403 2612ms
Error Handling.Does Not Retry On 413 2612ms
Error Handling.Retries On 408 5613ms

Feature_Flags Tests

17/17 tests passed

View Details
Test Status Duration
Request Payload.Request With Person Properties Device Id 610ms
Request Payload.Flags Request Uses V2 Query Param 609ms
Request Payload.Flags Request Hits Flags Path Not Decide 609ms
Request Payload.Flags Request Omits Authorization Header 609ms
Request Payload.Token In Flags Body Matches Init 610ms
Request Payload.Groups Round Trip 609ms
Request Payload.Groups Default To Empty Object 609ms
Request Payload.Disable Geoip False Propagates As Geoip Disable False 609ms
Request Payload.Disable Geoip Omitted Defaults To False 609ms
Request Payload.Flag Keys To Evaluate Contains Only Requested Key 610ms
Request Lifecycle.No Flags Request On Init Alone 3ms
Request Lifecycle.No Flags Request On Normal Capture 609ms
Request Lifecycle.Two Flag Calls Produce Two Remote Requests 1215ms
Request Lifecycle.Mock Response Value Is Returned To Caller 609ms
Retry Behavior.Retries Flags On 502 912ms
Retry Behavior.Retries Flags On 504 913ms
Side Effect Events.Get Feature Flag Captures Feature Flag Called Event 1212ms

@greptile-apps

greptile-apps Bot commented Jun 28, 2026

Copy link
Copy Markdown

Reviews (1): Last reviewed commit: "fix: retry flags only on transport error..." | Re-trigger Greptile

Comment thread lib/posthog/api/client.ex Outdated
Comment thread test/posthog/api/client_test.exs Outdated
@marandaneto marandaneto force-pushed the pi-flags-network-retry-20260628 branch from 0afae4f to 3a6c66d Compare July 2, 2026 08:57
@marandaneto

Copy link
Copy Markdown
Member Author

this will require PostHog/posthog-sdk-test-harness#30 to be merged/released

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

greptile-apps Bot commented Jul 2, 2026

Copy link
Copy Markdown

Reviews (2): Last reviewed commit: "Merge branch 'main' into pi-flags-networ..." | Re-trigger Greptile

@marandaneto marandaneto merged commit 6fe743f into main Jul 2, 2026
28 checks passed
@marandaneto marandaneto deleted the pi-flags-network-retry-20260628 branch July 2, 2026 10:20
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