Skip to content

fix: add feature flag retry circuit breaker#247

Draft
marandaneto wants to merge 3 commits into
pi-flags-network-retry-20260624from
pi-flags-network-retry-circuit-breaker-20260626
Draft

fix: add feature flag retry circuit breaker#247
marandaneto wants to merge 3 commits into
pi-flags-network-retry-20260624from
pi-flags-network-retry-circuit-breaker-20260626

Conversation

@marandaneto

Copy link
Copy Markdown
Member

💡 Motivation and Context

Stacked on top of #245 to prototype a circuit breaker for /flags retry behavior in a multithreaded/stateless SDK.

The existing retry is bounded per call, but during a broad connectivity issue many concurrent request threads can each sleep and retry independently. This adds a shared circuit breaker so repeated transient /flags transport failures put the SDK into a short cooldown and subsequent calls fail fast instead of all sleeping/retrying.

💚 How did you test it?

  • dotnet test tests/UnitTests/UnitTests.csproj --filter FullyQualifiedName~HttpClientExtensionsTests
  • git diff --check

📝 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 as a draft stacked PR for review. The circuit opens after consecutive transient /flags failures, fails fast during cooldown, and allows a half-open probe after cooldown. HTTP/API status failures remain non-retryable and do not trip the transient-failure circuit.

@github-actions

github-actions Bot commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

posthog-dotnet Compliance Report

Date: 2026-06-27 10:48:18 UTC
Duration: 607ms

⚠️ 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 47ms
Request Payload.Flags Request Uses V2 Query Param 23ms
Request Payload.Flags Request Hits Flags Path Not Decide 6ms
Request Payload.Flags Request Omits Authorization Header 5ms
Request Payload.Token In Flags Body Matches Init 5ms
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 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 5ms
Request Lifecycle.No Flags Request On Init Alone 4ms
Request Lifecycle.No Flags Request On Normal Capture 188ms
Request Lifecycle.Two Flag Calls Produce Two Remote Requests 8ms
Request Lifecycle.Mock Response Value Is Returned To Caller 6ms
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'

@marandaneto

Copy link
Copy Markdown
Member Author

@haacked wdyt about this circuit break approach? (we can also make the 30s configurable)

@marandaneto marandaneto requested a review from haacked June 26, 2026 19:42
@greptile-apps

greptile-apps Bot commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

Reviews (1): Last reviewed commit: "fix: add feature flag retry circuit brea..." | Re-trigger Greptile

Comment thread src/PostHog/Library/HttpClientExtensions.cs
Comment thread src/PostHog/Library/HttpClientExtensions.cs
Comment thread src/PostHog/Library/HttpClientExtensions.cs Outdated
Comment thread tests/UnitTests/Library/HttpClientExtensionsTests.cs Outdated
Comment thread src/PostHog/Library/HttpClientExtensions.cs Outdated
Comment thread src/PostHog/Library/HttpClientExtensions.cs Outdated
Comment thread src/PostHog/Library/HttpClientExtensions.cs
Comment thread src/PostHog/Library/HttpClientExtensions.cs Outdated
Comment thread src/PostHog/Library/HttpClientExtensions.cs Outdated
Comment thread tests/UnitTests/Library/HttpClientExtensionsTests.cs
@haacked

haacked commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

@marandaneto I meant to submit the review as a comment, not approval! But I trust you to do the right thing. 😄

@marandaneto

Copy link
Copy Markdown
Member Author

@marandaneto I meant to submit the review as a comment, not approval! But I trust you to do the right thing. 😄

thx for the review, yeah it was just a draft with a concept, will check and work on it on monday, then i can port this change across other sdks that have a similar situation

@marandaneto marandaneto requested a review from haacked June 27, 2026 09:19
@marandaneto

Copy link
Copy Markdown
Member Author

i re-requested review to remove the approval, but no need to re-review until i address the comments and make it ready for review

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