fix: always invoke reloadFeatureFlags callback#546
Conversation
The reloadFeatureFlags(onFeatureFlags) early-returns (SDK disabled/opted-out, blank distinctId) skipped the completion callback, so callers awaiting it (e.g. the Flutter SDK) could hang. Invoke the callback before returning. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
posthog-android Compliance ReportDate: 2026-06-02 21:36:15 UTC
|
| Test | Status | Duration |
|---|---|---|
| Request Payload.Request With Person Properties Device Id | ❌ | 331ms |
| Request Payload.Flags Request Uses V2 Query Param | ❌ | 48ms |
| Request Payload.Flags Request Hits Flags Path Not Decide | ❌ | 37ms |
| Request Payload.Flags Request Omits Authorization Header | ❌ | 23ms |
| Request Payload.Token In Flags Body Matches Init | ❌ | 21ms |
| Request Payload.Groups Round Trip | ❌ | 19ms |
| Request Payload.Groups Default To Empty Object | ❌ | 20ms |
| Request Payload.Person Properties Distinct Id Auto Populated When Caller Omits It | ❌ | 19ms |
| Request Payload.Disable Geoip False Propagates As Geoip Disable False | ❌ | 20ms |
| Request Payload.Disable Geoip Omitted Defaults To False | ❌ | 17ms |
| Request Payload.Flag Keys To Evaluate Contains Only Requested Key | ❌ | 16ms |
| Request Lifecycle.No Flags Request On Init Alone | ❌ | 11ms |
| Request Lifecycle.No Flags Request On Normal Capture | ❌ | 2057ms |
| Request Lifecycle.Two Flag Calls Produce Two Remote Requests | ❌ | 15ms |
| Request Lifecycle.Mock Response Value Is Returned To Caller | ❌ | 14ms |
| Side Effect Events.Get Feature Flag Captures Feature Flag Called Event | ❌ | 15ms |
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.no_flags_request_on_init_alone
Expected 0 /flags requests, got 1
request_lifecycle.no_flags_request_on_normal_capture
Expected 0 /flags requests, got 1
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'
Route the early-return callback invocations through a try/catch helper so a throwing caller callback can't escape reloadFeatureFlags (matching runOnFeatureFlagsCallbacks). Add a test asserting the callback fires when the SDK is not enabled. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
Re: @greptile-apps review on
|
|
Good progress — Two remaining notes: Blank
The core fix is correct and the changeset description is accurate. LGTM to merge once you decide whether to add the blank- Tip: You can customize Greptile's behavior for this repo with |
💡 Motivation and Context
https://posthoghelp.zendesk.com/agent/tickets/58925
reloadFeatureFlags(onFeatureFlags)promises to invokeonFeatureFlagswhen the reload finishes, but several early-returns skipped it:if (!isEnabled())— SDK disabled or opted-outif (distinctId.isBlank())inloadFeatureFlagsRequestWhen the callback is never invoked, any caller awaiting it stalls. This surfaced via the Flutter SDK, whose
reloadFeatureFlags()returns aFuturethat completes from this callback —await Posthog().reloadFeatureFlags()would hang forever in those states. (Once execution reaches the network load, the callback already fires on every outcome viaexecuteFeatureFlags, so only the front-door guards were affected.)💚 How did you test it?
./gradlew :posthog:compileKotlinpasses. ExistingreloadFeatureFlagsbehavior is unchanged on the normal path; the change only adds the callback invocation to the two guard returns. Happy to add a unit test asserting the callback fires when!isEnabled()if preferred.📝 Checklist
If releasing new changes
pnpm changesetto generate a changeset file