Skip to content

feat: provider wrapper to support state race fix#1362

Draft
toddbaert wants to merge 1 commit intomainfrom
poc/fix-provider-init-race
Draft

feat: provider wrapper to support state race fix#1362
toddbaert wants to merge 1 commit intomainfrom
poc/fix-provider-init-race

Conversation

@toddbaert
Copy link
Copy Markdown
Member

@toddbaert toddbaert commented Mar 11, 2026

PoC for open-feature/spec#365. This adds a StateManagingProvider interface (opt-in) so providers can own their state and event emissions, fixing the race between SDK-managed state writes and provider-emitted events during/after init. When a provider implements this interface, the SDK reads state directly from the provider and skips its own state writes and event emissions in the init, shutdown, and runtime event paths. Legacy providers that do not implement the interface continue to work exactly as before (SDK manages their state). Not breaking for application-authors or provider-authors.

Companion PoCs:

@toddbaert toddbaert requested review from a team as code owners March 11, 2026 17:25
@toddbaert toddbaert marked this pull request as draft March 11, 2026 17:25
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces a mechanism for providers to manage their own state, which allows for more control and potentially better concurrency. It modifies the 'ProviderWrapper' to respect this new state management, and adds a type guard to identify these new providers. This change aims to address state race conditions and improve the overall reliability of the system.

Highlights

  • State Management: Introduces the concept of 'StateManagingProvider' to allow providers to manage their own state, rather than relying on the SDK to maintain shadow state.
  • Provider Wrapper Modification: Updates the 'ProviderWrapper' to accommodate state-managing providers, ensuring that status updates are handled correctly based on whether the provider manages its own state.
  • Type Guard Implementation: Adds a type guard, 'isStateManagingProvider', to easily identify providers that manage their own state.
Changelog
  • packages/shared/src/open-feature.ts
    • Added check for state-managing providers in ProviderWrapper to handle status updates accordingly.
  • packages/shared/src/provider/provider.ts
    • Introduced StateManagingProvider interface and isStateManagingProvider type guard.
Activity
  • Initial commit of provider wrapper to support state race fix.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a StateManagingProvider interface to allow providers to manage their own state, which should help resolve state-related race conditions. The ProviderWrapper is updated to delegate state management to these providers while preserving backward compatibility. The implementation is logical, and I have one minor suggestion to improve the type safety of the new type guard.

export function isStateManagingProvider<S extends ClientProviderStatus | ServerProviderStatus>(
provider: CommonProvider<S>,
): provider is StateManagingProvider<S> {
return 'managesState' in provider && (provider as StateManagingProvider<S>).managesState === true;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Casting to the full StateManagingProvider<S> interface within the type guard that is meant to validate it can be slightly circular. A more precise approach is to cast to a minimal anonymous type that only contains the property being checked. This improves type safety by not over-stating the type before it's fully validated.

Suggested change
return 'managesState' in provider && (provider as StateManagingProvider<S>).managesState === true;
return 'managesState' in provider && (provider as { managesState?: boolean }).managesState === true;

Signed-off-by: Todd Baert <todd.baert@dynatrace.com>
@toddbaert toddbaert force-pushed the poc/fix-provider-init-race branch from 215f8d2 to a22b4a2 Compare April 8, 2026 18:35
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.

1 participant