Percentage split and variant hash collide when segment key equals feature key
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 78/100
Research direction
Start in segments/evaluator.py at the PERCENTAGE_SPLIT handling and variant selection, then trace the get_evaluation_result entry point used by the reproduction. Verify that percentage splits and multivariate variants no longer collide when their keys match, and rerun the 1,000-identity example to confirm both variants are served.
Written by the indexing model from the issue text.
Description
Bug
A percentage split segment and a multivariate feature hash the same inputs when the segment key equals the feature key:
- the split hashes
[segment_key, identity_key](segments/evaluator.py,PERCENTAGE_SPLIT) - the variant hashes
[feature_key, identity_key](segments/evaluator.py, variant selection)
Both give the same number. An identity is only in a 50% split when that number is 50 or below, so it always lands in the first variant. The other variants are never served to anyone in the segment.
Segment and feature keys are ids from different tables, so they can be equal by chance.
Reproduction
from flag_engine.utils.hashing import get_hashed_percentage_for_object_ids as h
identity = "user-1"
assert h(["95", identity]) == h(["95", identity]) # split == variant
End to end: a segment with a 50% split on $.identity.key, overriding a feature with two 50/50 variants, evaluated for 1000 identities:
from collections import Counter
from flag_engine.engine import get_evaluation_result
def variants(segment_key: str, feature_key: str) -> Counter[str]:
context = {
"environment": {"key": "env", "name": "env"},
"segments": {
segment_key: {
"key": segment_key,
"name": "rollout",
"rules": [{"type": "ALL", "conditions": [
{"property": "$.identity.key", "operator": "PERCENTAGE_SPLIT", "value": "50"},
]}],
"overrides": [{
"key": feature_key, "name": "checkout", "enabled": True, "value": "control",
"variants": [
{"value": "a", "weight": 50, "priority": 0, "key": "variant-a"},
{"value": "b", "weight": 50, "priority": 1, "key": "variant-b"},
],
}],
}
},
"features": {"checkout": {"key": "1", "name": "checkout", "enabled": False, "value": None}},
}
counts: Counter[str] = Counter()
for i in range(1000):
context["identity"] = {"identifier": f"user-{i}", "key": f"user-{i}"}
flag = get_evaluation_result(context)["flags"]["checkout"]
if flag["enabled"]:
counts[flag["variant"]] += 1
return counts
print(variants("95", "96")) # Counter({'variant-b': 260, 'variant-a': 254})
print(variants("95", "95")) # Counter({'variant-a': 514})
Impact
Any segment override with variants on a percentage split segment whose key equals the feature key serves only one variant to the whole segment. For an experiment rollout, the experiment has a single arm. Seen in Flagsmith's API tests in Flagsmith/flagsmith#8646.
- Dominant language
- Python
- Stars
- 10
- Forks
- 5
- Avg merge
- 17m
- Merged PRs (30d)
- 3
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from Flagsmith/flagsmith-engine
-
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
Flagsmith/flagsmith-engine#340 ·
-
Dependency DashboardOpen
Difficulty 1/5 Under an hour Newbie friendliness 25/100
Flagsmith/flagsmith-engine#306 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 45/100
Flagsmith/flagsmith-engine#231 ·
-
Difficulty 1/5 1-3 hours Newbie friendliness 55/100
Flagsmith/flagsmith-engine#207 · 2 comments ·
-
error: global flags not at the start of the expression at position 1May be free again @khvn26 claimed this 1094 days ago, and no pull request is open. Openbug
Flagsmith/flagsmith-engine#196 · 1 comment · 1 assignee ·
All issues in Flagsmith/flagsmith-engine
Similar issues
-
Difficulty 1/5 Under an hour Newbie friendliness 73/100
-
day_or=True union silently becomes the ISC cron AND bug when a day field expands to its full range (e.g. '0 0 */1 * */2' fires only Sun/Tue/Thu/Sat)Possibly taken @rahul05ranjan claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
pallets-eco/croniter#309 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
chore
Difficulty 2/5 1-3 hours Newbie friendliness 67/100
nyjc-computing/campus-admin#105 ·
Maintainers usually reply within 1 day
-
bug enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
AOSSIE-Org/Gitcord-GithubDiscordBot#248 · 1 comment ·
Maintainers usually reply within 4 days