Skip to content

Conversation

@joshua-koehler
Copy link
Contributor

@joshua-koehler joshua-koehler commented Nov 13, 2025

Support complex runtime rules in local-evaluation - no network calls required!
image

GitHub Copilot Summary

This pull request introduces a new runtime rules engine for feature flag evaluation using JSON Logic, and updates the test suite to cover a wide range of rule scenarios. The main benefit is that feature flag rollouts can now be controlled by expressive, declarative rules, improving flexibility and maintainability. Legacy runtime evaluation logic is preserved for backward compatibility, but is ignored when new-style rules are present.

Feature flag evaluation logic:

  • Added dependency on json_logic and implemented _is_runtime_rules_engine_satisfied, which evaluates rollout rules using JSON Logic when runtime_evaluation_rule is present, falling back to legacy logic otherwise. [1] [2]
  • Updated rollout assignment logic to prefer runtime_evaluation_rule over legacy runtime_evaluation_definition, ensuring backward compatibility but prioritizing new rules.

Test suite enhancements:

  • Refactored test flag creation and test context usage for consistency (TEST_FLAG_KEY, USER_CONTEXT), and added helper for user context with custom properties. [1] [2]
  • Added comprehensive tests for JSON Logic rules, including equality, containment, multi-value, logical AND, comparison, and precedence over legacy definitions.
  • Ensured legacy runtime evaluation logic is correctly tested and only used when no new-style rule is present.

General test improvements:

  • Updated all test usages to use the new constants and helpers for improved readability and maintainability. [1] [2] [3] [4] [5] [6] [7] [8] [9]

@codecov
Copy link

codecov bot commented Nov 13, 2025

Codecov Report

❌ Patch coverage is 97.34513% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 94.28%. Comparing base (71c22a2) to head (f315638).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
mixpanel/flags/local_feature_flags.py 86.04% 2 Missing and 4 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #148      +/-   ##
==========================================
+ Coverage   93.81%   94.28%   +0.46%     
==========================================
  Files           9        9              
  Lines        1375     1557     +182     
  Branches       91      101      +10     
==========================================
+ Hits         1290     1468     +178     
- Misses         52       54       +2     
- Partials       33       35       +2     

☔ 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.

Copilot finished reviewing on behalf of joshua-koehler November 13, 2025 18:02
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds support for a runtime rules engine in local feature flag evaluation, enabling complex rule evaluation without network calls. The implementation uses the json-logic library to evaluate JSON-based rules against user properties.

  • Adds json-logic dependency for evaluating complex runtime rules
  • Introduces runtime_evaluation_rule field to support JSON-based rule definitions
  • Maintains backward compatibility with legacy runtime_evaluation_definition

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
pyproject.toml Adds json-logic>=0.7.0a0 dependency for rule evaluation
mixpanel/flags/types.py Adds runtime_evaluation_rule field to Rollout model to support JSON-based rules
mixpanel/flags/local_feature_flags.py Implements _is_runtime_rules_engine_satisfied() method to evaluate JSON logic rules, with fallback to legacy evaluation
mixpanel/flags/test_local_feature_flags.py Adds comprehensive test coverage for JSON logic rules including equality, contains, multi-value, AND operations, comparisons, and legacy compatibility

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

joshua-koehler and others added 2 commits November 13, 2025 12:05
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@jaredmixpanel jaredmixpanel self-requested a review November 13, 2025 18:23
joshua-koehler and others added 3 commits November 13, 2025 12:52
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@joshua-koehler joshua-koehler force-pushed the runtime-rules-engine-clean branch from d359620 to 6fb5c01 Compare November 13, 2025 22:09
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link

@msiebert msiebert left a comment

Choose a reason for hiding this comment

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

Copy link
Contributor

@jaredmixpanel jaredmixpanel left a comment

Choose a reason for hiding this comment

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

LGTM

@joshua-koehler joshua-koehler merged commit fcc255b into master Nov 14, 2025
12 checks passed
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.

4 participants