fix: enable openfeature provider to initialize with cached config when available#284
fix: enable openfeature provider to initialize with cached config when available#284
Conversation
android-client-sdk/src/main/java/com/devcycle/sdk/android/api/DevCycleClient.kt
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
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.initializeto skip waiting ononInitialized. - 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.
android-client-sdk/src/main/java/com/devcycle/sdk/android/api/DevCycleClient.kt
Show resolved
Hide resolved
There was a problem hiding this comment.
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.
| 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) | ||
| } |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
What happens if the event emit fails?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
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.