Skip to content

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

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

fix(flags): retry flag requests on transient network errors#245
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:

dotnet test tests/UnitTests/UnitTests.csproj --filter FullyQualifiedName~HttpClientExtensionsTests

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

github-actions Bot commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

posthog-dotnet Compliance Report

Date: 2026-06-26 15:01:32 UTC
Duration: 610ms

⚠️ Some Tests Failed

2/16 tests passed, 14 failed


Feature_Flags Tests

⚠️ 2/16 tests passed, 14 failed

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

Failures

request_payload.request_with_person_properties_device_id

404, message='Not Found', url='http://sdk-adapter:8080/get_feature_flag'

request_payload.flags_request_uses_v2_query_param

404, message='Not Found', url='http://sdk-adapter:8080/get_feature_flag'

request_payload.flags_request_hits_flags_path_not_decide

404, message='Not Found', url='http://sdk-adapter:8080/get_feature_flag'

request_payload.flags_request_omits_authorization_header

404, message='Not Found', url='http://sdk-adapter:8080/get_feature_flag'

request_payload.token_in_flags_body_matches_init

404, message='Not Found', url='http://sdk-adapter:8080/get_feature_flag'

request_payload.groups_round_trip

404, message='Not Found', url='http://sdk-adapter:8080/get_feature_flag'

request_payload.groups_default_to_empty_object

404, message='Not Found', url='http://sdk-adapter:8080/get_feature_flag'

request_payload.person_properties_distinct_id_auto_populated_when_caller_omits_it

404, message='Not Found', url='http://sdk-adapter:8080/get_feature_flag'

request_payload.disable_geoip_false_propagates_as_geoip_disable_false

404, message='Not Found', url='http://sdk-adapter:8080/get_feature_flag'

request_payload.disable_geoip_omitted_defaults_to_false

404, message='Not Found', url='http://sdk-adapter:8080/get_feature_flag'

request_payload.flag_keys_to_evaluate_contains_only_requested_key

404, message='Not Found', url='http://sdk-adapter:8080/get_feature_flag'

request_lifecycle.two_flag_calls_produce_two_remote_requests

404, message='Not Found', url='http://sdk-adapter:8080/get_feature_flag'

request_lifecycle.mock_response_value_is_returned_to_caller

404, message='Not Found', url='http://sdk-adapter:8080/get_feature_flag'

side_effect_events.get_feature_flag_captures_feature_flag_called_event

404, message='Not Found', url='http://sdk-adapter:8080/get_feature_flag'

@greptile-apps

greptile-apps Bot commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

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

Comment thread tests/UnitTests/Library/HttpClientExtensionsTests.cs
Comment thread src/PostHog/Library/HttpClientExtensions.cs
@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

Copy link
Copy Markdown
Member Author

Addressed the compliance-bot 404 feedback in b4e9886 by adding the SDK compliance adapter /get_feature_flag endpoint so feature-flag harness calls are routed through the SDK instead of returning 404. Validation run locally: unit tests pass; adapter builds. Docker compliance run could not be started because the local Docker daemon/socket was unavailable.

@marandaneto marandaneto force-pushed the pi-flags-network-retry-20260624 branch from b4e9886 to e2f7ffa Compare June 26, 2026 13:50
@marandaneto

Copy link
Copy Markdown
Member Author

Follow-up: amended the review-feedback commit to e2f7ffa with the remaining compliance payload/side-effect fixes. The latest GitHub Actions SDK compliance report is now green: 16/16 feature flag compliance tests passed.

Comment thread src/PostHog/Api/PostHogApiClient.cs Outdated
@marandaneto marandaneto marked this pull request as ready for review June 26, 2026 15:00
@marandaneto marandaneto requested a review from a team as a code owner June 26, 2026 15:00
@greptile-apps

greptile-apps Bot commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

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

turnipdabeets
turnipdabeets approved these changes Jun 26, 2026
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