Skip to content

fix: keep sticky bucket when experiment rule condition no longer matches - #162

Closed
vazarkevych wants to merge 1 commit into
mainfrom
fix/161-sticky-bucket-rule-condition
Closed

vazarkevych wants to merge 1 commit into
mainfrom
fix/161-sticky-bucket-rule-condition

Conversation

@vazarkevych

Copy link
Copy Markdown
Collaborator

Fixes #161

What changed and why

With sticky bucketing on, a user who was bucketed into an experiment and then stopped matching the rule's condition (for example, the condition was narrowed mid-test) fell back to the feature's default value. The JS SDK keeps them in their stored variation.

_eval_feature checked rule.condition for every rule before running the experiment, so the sticky bucket lookup in _run_experiment never ran. Now rule.condition is checked up front only for force rules, inside the rule.force is not None block. Experiment rules go straight to _run_experiment, which already checks the condition only when no sticky bucket is found.

This matches evalFeature in the JS SDK (core.ts, the "force" in rule block) and the same fix in growthbook/growthbook-php#91. The order of checks in the rule loop now matches JS: prerequisites → filters → force (condition, rollout) → experiment.

Side effects, both matching JS:

  • A sticky-bucketed user who stops matching the condition stays in the experiment, instead of falling through to a later rule.
  • A forced variation (forced_variations or ?exp=1) now applies even when the user fails the experiment rule's condition.
  • on_experiment_viewed-style subscriptions (callback_subscription) now also see experiment rules whose condition fails, with an inExperiment=False result.

How to test

  • pytest tests/test_sticky_bucket_rule_condition.py: 7 tests ported from growthbook-php#91. The first three fail without the fix:
    • sticky bucket wins over a narrowed rule condition
    • sticky bucket wins over a later force rule
    • forced variation wins over a rule condition
  • The others check that the rule condition still applies without a sticky bucket, that force-rule conditions still apply, and that filters and prerequisites still apply with a sticky bucket.
  • The repro from Sticky-bucketed users fall back to the default value when an experiment rule's condition is narrowed (JS SDK keeps them) #161 now returns new / experiment on the second call, the same as @growthbook/growthbook 2.0.0.
  • Full suite: all pass except two tests/test_typing.py mypy cases that also fail on main.

Limitations / follow-ups

  • The SDK spec's "build your own" steps still describe checking rule.condition for every rule. This PR follows the JS SDK, which is the reference implementation here.
  • No new dependencies.

_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
@greptile-apps

greptile-apps Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; no actionable defects were found.

Reviews (2) · Last reviewed commit: "fix: keep sticky bucket when experiment ..." · Reviewed by Greptile

@vazarkevych

Copy link
Copy Markdown
Collaborator Author

@greptile review

@madhuchavva

Copy link
Copy Markdown
Contributor

Thanks for addressing this. Changes are ported into PR #166 — your commit is carried over unchanged, along with conformance cases for it in tests/cases.json.

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.

Sticky-bucketed users fall back to the default value when an experiment rule's condition is narrowed (JS SDK keeps them)

2 participants