fix: Do not emit duplicate provider events - #37
Draft
kinyoklion wants to merge 1 commit into
Draft
Conversation
Contributor
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
Contributor
|
@cursor review |
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.
Provider events are no longer emitted for a status the application has already been told about.
PROVIDER_READYevent on top of the one the OpenFeature SDK emits for initialization itself. Subscription now happens after initialization succeeds.PROVIDER_STALE. An event is now emitted only when the provider status actually changes.shutdownunsubscribes the listeners it added.Based on #36, which also changes
init; review that one first.Found during the weekly OpenFeature provider audit.
Implementation details
Requirements
Related issues
None.
Describe the solution you've provided
The provider builds its status and flag change listeners in the constructor but registers them at the end of a successful
init, and removes them inshutdown. A failed initialization does not register them, since the OpenFeature SDK reports that outcome itself.DataSourceStatusListenerremembers the last event it emitted, guarded by a mutex because the LaunchDarkly SDK notifies listeners from its own thread, and skips an event which repeats it. A status which changes and later returns still emits again.This matches the provider event requirements of the OpenFeature provider behavior spec, and the behavior of the Python provider, which registers its emitting listener after initialization for the same reason.
Describe alternatives you've considered
Comparing the whole data source status rather than the mapped provider status: the OpenFeature event carries the provider status, so two states which map to the same status are not a change an application can act on.
Keeping the constructor subscription and filtering the first
READYonly: that would still emit duplicates for repeated states, and the ordering between the provider's event and the SDK's own initialization event would remain unspecified.Additional context
Testing:
bundle exec rspec(84 examples) andbundle exec rubocopon Ruby 3.4.5. The new tests cover no subscription beforeinit, subscription after a successfulinit, no subscription after a failedinit, a repeated status emitting once, and a status which changes back emitting again.The README's Eventing row describes when events are emitted.
Link to Devin session: https://app.devin.ai/sessions/fe1eb757fe694ef79f3d09f6307d4b47
Open in Devin Desktop: https://app.devin.ai/desktop/session/fe1eb757fe694ef79f3d09f6307d4b47?variant=devin
Requested by: @kinyoklion