Skip to content

fix(flags): retry flag requests on transient network errors#587

Open
marandaneto wants to merge 6 commits into
mainfrom
pi-flags-network-retry-20260624
Open

fix(flags): retry flag requests on transient network errors#587
marandaneto wants to merge 6 commits into
mainfrom
pi-flags-network-retry-20260624

Conversation

@marandaneto

@marandaneto marandaneto commented Jun 25, 2026

Copy link
Copy Markdown
Member

💡 Motivation and Context

/flags/?v=2 evaluation should tolerate transient network failures, but should not retry HTTP/API responses such as 408, 429, or 5xx.

This PR adds bounded retry/backoff only for transient network failures (timeouts, connection resets/lost connections, and EOF-style failures) and keeps HTTP/API status errors terminal.

💚 How did you test it?

See the repo-specific command below.

📝 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 by pi after a maintainer-directed cross-SDK pass. The chosen policy is transient network-only retry/backoff for /flags/?v=2; HTTP/API statuses remain non-retryable by design. Connection-refused failures also fail fast where the platform exposes that distinction.

Tested with:

./gradlew :posthog:test --tests com.posthog.internal.PostHogApiTest --no-daemon

@marandaneto marandaneto self-assigned this Jun 25, 2026
@greptile-apps

greptile-apps Bot commented Jun 25, 2026

Copy link
Copy Markdown

Reviews (1): Last reviewed commit: "fix: retry feature flag requests on netw..." | Re-trigger Greptile

Comment thread posthog/src/test/java/com/posthog/internal/PostHogApiTest.kt
Comment thread posthog/src/test/java/com/posthog/internal/PostHogApiTest.kt
Comment thread posthog/src/main/java/com/posthog/internal/PostHogApi.kt Outdated
@github-actions

github-actions Bot commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

posthog-android Compliance Report

Date: 2026-06-26 15:09:10 UTC
Duration: 119682ms

⚠️ Some Tests Failed

38/45 tests passed, 7 failed


Capture Tests

⚠️ 28/29 tests passed, 1 failed

View Details
Test Status Duration
Format Validation.Event Has Required Fields 374ms
Format Validation.Event Has Uuid 28ms
Format Validation.Event Has Lib Properties 33ms
Format Validation.Distinct Id Is String 22ms
Format Validation.Token Is Present 24ms
Format Validation.Custom Properties Preserved 25ms
Format Validation.Event Has Timestamp 22ms
Retry Behavior.Retries On 503 7029ms
Retry Behavior.Does Not Retry On 400 4022ms
Retry Behavior.Does Not Retry On 401 4024ms
Retry Behavior.Respects Retry After Header 7026ms
Retry Behavior.Implements Backoff 17034ms
Retry Behavior.Retries On 500 7019ms
Retry Behavior.Retries On 502 7019ms
Retry Behavior.Retries On 504 7019ms
Retry Behavior.Max Retries Respected 17034ms
Deduplication.Generates Unique Uuids 38ms
Deduplication.Preserves Uuid On Retry 7014ms
Deduplication.Preserves Uuid And Timestamp On Retry 12030ms
Deduplication.Preserves Uuid And Timestamp On Batch Retry 7014ms
Deduplication.No Duplicate Events In Batch 34ms
Deduplication.Different Events Have Different Uuids 26ms
Compression.Sends Gzip When Enabled 19ms
Batch Format.Uses Proper Batch Structure 18ms
Batch Format.Flush With No Events Sends Nothing 11ms
Batch Format.Multiple Events Batched Together 32ms
Error Handling.Does Not Retry On 403 4019ms
Error Handling.Does Not Retry On 413 4017ms
Error Handling.Retries On 408 5031ms

Failures

error_handling.does_not_retry_on_413

Expected 1 requests, got 2

Feature_Flags Tests

⚠️ 10/16 tests passed, 6 failed

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

Failures

request_payload.request_with_person_properties_device_id

Expected distinct_id='test_user_123', got '019f047a-3edf-7088-8695-45f79c740631'

request_payload.groups_default_to_empty_object

Field 'groups' not found in /flags request body at path 'groups'. Available keys: ['$anon_distinct_id', '$device_id', 'api_key', 'distinct_id', 'timezone', 'person_properties']

request_payload.person_properties_distinct_id_auto_populated_when_caller_omits_it

Field 'distinct_id' not found in /flags request body at path 'person_properties.distinct_id'. Available keys: ['$lib', '$lib_version', 'email']

request_payload.disable_geoip_false_propagates_as_geoip_disable_false

Field 'geoip_disable' not found in /flags request body at path 'geoip_disable'. Available keys: ['$anon_distinct_id', '$device_id', 'api_key', 'distinct_id', 'timezone', 'person_properties']

request_payload.disable_geoip_omitted_defaults_to_false

Field 'geoip_disable' not found in /flags request body at path 'geoip_disable'. Available keys: ['$anon_distinct_id', '$device_id', 'api_key', 'distinct_id', 'timezone', 'person_properties']

request_payload.flag_keys_to_evaluate_contains_only_requested_key

Field 'flag_keys_to_evaluate' not found in /flags request body at path 'flag_keys_to_evaluate'. Available keys: ['$anon_distinct_id', '$device_id', 'api_key', 'distinct_id', 'timezone', 'person_properties']

@marandaneto marandaneto changed the title fix: retry feature flag requests on network errors fix(flags): retry flag requests on transient network errors Jun 25, 2026
@marandaneto marandaneto force-pushed the pi-flags-network-retry-20260624 branch from 161cf3e to f322de9 Compare June 26, 2026 13:42
Comment thread .changeset/quiet-flags-retry.md
@marandaneto marandaneto marked this pull request as ready for review June 26, 2026 15:02
@marandaneto marandaneto requested a review from a team as a code owner June 26, 2026 15:02
@greptile-apps

greptile-apps Bot commented Jun 26, 2026

Copy link
Copy Markdown

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

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