Skip to content

Conversation

@kylejuliandev
Copy link
Contributor

This PR

Fixes a couple of issues when the InMemoryProvider cannot evaluate the variant. First when the variant does not exist, we should fallback to the default variant configured in the flags. Second when the ContextEvaluator throws an exception. Instead of throwing an error we can fallback to the default variant. This is the behaviour in the Java SDK, as well as behaviour described in the gherkin tests. Specifically, the Null context values scenario and the Empty evaluation context scenario.

Related Issues

Fixes #603

Notes

Follow-up Tasks

How to test

@kylejuliandev kylejuliandev requested a review from a team as a code owner October 29, 2025 22:13
@kylejuliandev
Copy link
Contributor Author

/gemini review

@gemini-code-assist
Copy link

Summary of Changes

Hello @kylejuliandev, 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 enhances the robustness of the InMemoryProvider by implementing more resilient variant evaluation logic. It addresses cases where the context evaluator fails or returns a non-existent variant, ensuring that the system gracefully falls back to the default variant as per the OpenFeature specification and other SDK implementations. This change prevents unexpected exceptions and provides a more stable feature flagging experience.

Highlights

  • Robust Variant Evaluation: The InMemoryProvider now gracefully handles scenarios where the evaluated variant does not exist or when the context evaluator throws an exception. Instead of throwing errors, it now falls back to the configured default variant.
  • Specification Alignment: This change aligns the provider's behavior with the OpenFeature specification, specifically the 'Null context values' and 'Empty evaluation context' scenarios, and mirrors the behavior found in the Java SDK.
  • Code Refactoring: A new private helper method, EvaluateDefaultVariant, has been introduced to centralize the logic for resolving and returning the default variant, improving code readability and maintainability.
  • Enhanced Test Coverage: New and updated unit tests have been added to validate the new fallback behaviors, ensuring that the provider correctly returns the default variant when an evaluated variant is missing or when the context evaluator encounters an error.
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.

@codecov
Copy link

codecov bot commented Oct 29, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.89%. Comparing base (c987b58) to head (054f7ae).
⚠️ Report is 7 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #615      +/-   ##
==========================================
+ Coverage   89.84%   89.89%   +0.04%     
==========================================
  Files          77       77              
  Lines        3162     3167       +5     
  Branches      364      364              
==========================================
+ Hits         2841     2847       +6     
  Misses        251      251              
+ Partials       70       69       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link

@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 correctly addresses issues in the InMemoryProvider by falling back to the default variant when context evaluation fails or returns a non-existent variant. The logic is sound and aligns with the behavior of other OpenFeature SDKs. The changes are accompanied by relevant tests. I've included a few suggestions to enhance code readability and improve the completeness of the tests.

Copy link

@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 correctly addresses issues in the InMemoryProvider's context evaluation. When the context evaluator throws an exception or when an evaluated variant doesn't exist, the provider now falls back to the default variant, which aligns with the OpenFeature specification. The changes are logical, and the addition of new tests ensures the new behavior is covered. I have one minor suggestion to improve code readability.

@askpt askpt added this pull request to the merge queue Oct 30, 2025
Merged via the queue into open-feature:main with commit 94fcdc1 Oct 30, 2025
23 checks passed
@kylejuliandev kylejuliandev deleted the kylej/fix-603 branch November 10, 2025 20:18
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.

[BUG] InMemoryProvider returns error if variant is not found

3 participants