Repository navigation
fix: keep sticky buckets past a failing rule condition and honor null force rules - #166
Merged
Merged
Conversation
_eval_feature checked rule.condition for every rule before running the experiment, so a sticky-bucketed user who stopped matching a narrowed condition fell back to the default value. Check rule.condition up front only for force rules; experiment rules rely on _run_experiment, which skips the condition when a sticky bucket is found. Matches the JS SDK (core.ts) and growthbook-php#91. A forced variation now also applies when the user fails the experiment rule's condition, as in JS. Fixes #161
[Medium impact] This PR appears safe to merge. Reviews (1) · Last reviewed commit: "fix: treat a feature rule with a null fo..." · Reviewed by Greptile |
andywhite37
approved these changes
Nov 30, 2026
andywhite37
left a comment
Contributor
There was a problem hiding this comment.
Matches the JS SDK's evalFeature order. The new tests fail when either fix is reverted, and CI is green. Upstreaming the cases and the spec fix stay as follow-ups.
4 tasks
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.
Fixes #161. Supersedes #162 — its commit is carried over unchanged, authorship kept.
Summary
conditionstops matching."force": nullis a force rule that servesnull, as in the JS SDK ("force" in rule).tests/cases.jsonwith 12 new cases.Root cause
_eval_featurecheckedrule.conditionfor every rule before_run_experiment, so the sticky bucket lookup never ran. The JS SDK moved that check into the force branch when sticky bucketing shipped (Sticky bucketing (SDK) growthbook#1818); the Python port in v1.1.0 did not.rule.force is not Nonecannot tell a nullforcefrom a missing one.stickyBucketcase had a user failing the rule condition, and nofeaturecase hadforce: null, so the conformance suite passed.Behavioral change
forced_variationsand the?exp=Nquerystring override apply even when the rule condition fails.inExperiment=Falsefor experiment rules skipped by their condition."force": nullin a payload, orFeatureRule(force=None), servesNonewith sourceforce. Before, the rule was skipped, or ran as an experiment when it also hadvariations.Follow-ups
cases.json.evalFeaturein the build-your-own spec still checksrule.conditionfor every rule.Test plan
pytest tests/ -q --ignore=tests/test_live.py— 1872 passed locally; the 2 failures and 2 errors are identical onmainin the same environmentstickyBucket(+6) andfeature(+6) cases: expected values generated with@growthbook/growthbook2.2.0; the full fixture replays through it 19/19 and 70/70main: 7 failures for the sticky bucket fix, 3 forforce: nullpython3 tests/scripts/check_corpus_freshness.py— OK, no missing or drifted casespyright— 0 errors