Bug/onboarding flag issue - #3058
Merged
Merged
Conversation
Comment on lines
62
to
66
| val listener = object : UnleashStateListener { | ||
| override fun onStateChanged() { | ||
| trySend(Unit) | ||
| } | ||
| } |
Member
There was a problem hiding this comment.
I think I am mostly concerned with this, if it's equivalent and fits all of our needs here.
I think we can make this a bit more complete with this change
Suggested change
| val listener = object : UnleashStateListener { | |
| override fun onStateChanged() { | |
| trySend(Unit) | |
| } | |
| } | |
| val listener = object : UnleashStateListener, UnleashReadyListener { | |
| override fun onStateChanged() { trySend(Unit) } | |
| override fun onReady() { trySend(Unit) } | |
| } |
StylianosGakis
approved these changes
Aug 14, 2026
valueOf() branches on client.isReady(), but the SDK sets that flag from readyOnFeaturesReceived(), a coroutine independent of the one that delivers onStateChanged() to registered state listeners. Both are collectors of the same cache updates SharedFlow, so on the first cache write they race with no ordering guarantee. When the state listener wins, featureUpdatedFlow emits, valueOf() sees isReady() == false and returns the neverFetchedDefaults value even though the cache already holds real toggles. Nothing corrects that afterwards on a fresh install: doFetchToggles emits to featuresReceivedFlow only on a successful fetch, and once the fetcher has an ETag the following polls answer 304, so there is no further cache write and no further emission. The flag stays at its default for the rest of the process. With a backup on disk a second write follows shortly and hides the problem, which is why it only bites the never-fetched case the defaults exist for. Registering the same listener object as an UnleashReadyListener too closes it. onReady() runs after readyOnFeaturesReceived() has flipped the flag, so whichever collector wins, a re-read follows. distinctUntilChanged() in UnleashFeatureFlagProvider absorbs the duplicate emission. Also drops a paragraph from FEATURE_FLAG_DEFAULTS.md claiming a 304 in a fresh process keeps the cache near-empty via an ETag carried in the OkHttp disk cache. UnleashFetcher.etag is an in-memory var, so a fresh process sends no If-None-Match of its own, and OkHttp never surfaces a 304 to the caller: it merges and returns the stored 200, which repopulates.
…ner-emit Emit on Unleash readiness, not only on toggle state change
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix for the bug where onboarding showed on every cold start regardless of the disable_onboarding F flag.
Seems like it was an existing bug that never surfaced since we don't have any other flag that is needed only once on start and is never re-fetched again.
The cause description from Claude:
So the fix mainly removed bootstrap from isReady(), and did adjustments: added 3 existing defaults for 3 flags to neverFetchedDefaults map consulted only while !client.isReady(), added valueOf(feature), switched featureUpdatedFlow to UnleashStateListener.onStateChanged().