Skip to content

fix: enable openfeature provider to initialize with cached config when available#284

Open
luxscious wants to merge 7 commits intomainfrom
ICP-2248-use-cached-config-if-avail-on-init-openfeature
Open

fix: enable openfeature provider to initialize with cached config when available#284
luxscious wants to merge 7 commits intomainfrom
ICP-2248-use-cached-config-if-avail-on-init-openfeature

Conversation

@luxscious
Copy link

@luxscious luxscious commented Mar 11, 2026

Previously, the DevCycle Provider forced the OpenFeature Provider to wait for full client SDK initialization before becoming ready. This PR allows the provider to become ready immediately when a cached config is available. The state of the Open Feature provider will be set to stale until the client is fully initialized, to when it will be set as Ready.

@luxscious luxscious requested a review from kaushalkapasi March 11, 2026 16:37
@luxscious luxscious changed the title fix: enable provider to initialize with cached config when available fix: enable openfeature provider to initialize with cached config when available Mar 11, 2026
@luxscious luxscious requested a review from JamieSinn March 11, 2026 17:41
@luxscious luxscious marked this pull request as ready for review March 11, 2026 17:42
@luxscious luxscious requested a review from a team as a code owner March 11, 2026 17:42
Copilot AI review requested due to automatic review settings March 11, 2026 17:42
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the Android OpenFeature integration so the DevCycle OpenFeature Provider can report readiness immediately when a usable cached config is present, rather than always blocking on full client SDK initialization.

Changes:

  • Add a cached-config fast path in DevCycleProvider.initialize to skip waiting on onInitialized.
  • Introduce DevCycleClient.hasUsableCachedConfig() to detect when the current config came from cache and is usable.
  • Add unit tests covering cached-config readiness, cached evaluation serving, and the non-cached initialization path.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
android-client-sdk/src/main/java/com/devcycle/sdk/android/openfeature/DevCycleProvider.kt Returns from initialize immediately when a cached config is available.
android-client-sdk/src/main/java/com/devcycle/sdk/android/api/DevCycleClient.kt Adds an internal helper to detect usable cached config state.
android-client-sdk/src/test/java/com/devcycle/sdk/android/openfeature/DevCycleProviderTest.kt Adds tests validating behavior with/without cached config and evaluation serving.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@luxscious luxscious marked this pull request as draft March 11, 2026 18:38
@luxscious luxscious marked this pull request as ready for review March 11, 2026 20:13
Copilot AI review requested due to automatic review settings March 11, 2026 20:13
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +115 to +122
if (client.hasUsableCachedConfig()) {
DevCycleLogger.d("DevCycle OpenFeature provider initialized successfully from cached config")
providerEvents.tryEmit(OpenFeatureProviderEvents.ProviderStale)
client.onInitialized(object : DevCycleCallback<String> {
override fun onSuccess(result: String) {
DevCycleLogger.d("DevCycle OpenFeature provider refreshed successfully after cached startup")
providerEvents.tryEmit(OpenFeatureProviderEvents.ProviderReady)
}
Copy link

Copilot AI Mar 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

providerEvents.tryEmit(...) return values are ignored. With the current MutableSharedFlow(replay = 1, extraBufferCapacity = 1) configuration, tryEmit can return false (e.g., if initialize is invoked multiple times without active collectors), silently dropping state transition events. Consider configuring onBufferOverflow = DROP_OLDEST (so the latest state always wins) and/or checking/logging failed emits; where you’re already in a suspend context you can also use emit to guarantee delivery.

Copilot uses AI. Check for mistakes.
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI said this: Because we should avoid silently dropping provider state events, changing to DROP_OLDEST could hide the STALE -> READY transition we specifically want to preserve. Logging failed emits gives us visibility without changing that behavior.


if (client.hasUsableCachedConfig()) {
DevCycleLogger.d("DevCycle OpenFeature provider initialized successfully from cached config")
providerEvents.tryEmit(OpenFeatureProviderEvents.ProviderStale)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if the event emit fails?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For this code, a failed emit was getting dropped silently.

I just pushed a change so we now log when the emit fails instead of failing quietly. Let me know if you think there’s a better approach.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pushed another change so that initialization doesn’t get stuck if provider events are emitted while nothing is listening. In that case, we now drop the oldest buffered event instead.

@luxscious luxscious requested a review from jsalaber March 12, 2026 19:18
Copilot AI review requested due to automatic review settings March 12, 2026 19:26
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@luxscious luxscious requested a review from JamieSinn March 12, 2026 19:49
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.

3 participants