fix: honor filters.holdout in local flag evaluation - #978
Merged
Merged
Conversation
Local evaluation ignored the holdout on a flag's filters, so a user in an experiment holdout was bucketed into a regular variant instead of being excluded. The server resolves the holdout before release conditions and returns holdout-<id>; local evaluation now does the same. The existing _hash helper cannot be reused: it joins key and bucketing value with a dot, while the server hashes "holdout-<value>". Reusing it would look uniform and deterministic while selecting a different population. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
Contributor
posthog-python Compliance ReportDate: 2026-09-22T22:46:23.975053+00:00 ✅ All Tests Passed!121/121 tests passed Capture_V1 Tests✅ 95/95 tests passed View Details
Capture_Ai Tests✅ 5/5 tests passed View Details
Feature_Flags Tests✅ 17/17 tests passed View Details
Feature_Flags_Local_Evaluation Tests✅ 4/4 tests passed View Details
|
CodeQL flags SHA-1 on a distinct id as weak hashing of sensitive data. The digest is a bucketing value the server also computes, so it cannot change; usedforsecurity=False states the intent without altering the output. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Give _hash a separator argument instead of adding a second SHA-1 call site. The holdout hash is the same algorithm with "holdout-" in place of "<key>.", so one helper now covers both and CodeQL sees no new hashing call. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
marandaneto
approved these changes
Sep 23, 2026
marandaneto
left a comment
Member
There was a problem hiding this comment.
The code looks good; no qualifying findings. Verdict: correct.
7 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.
💡 Motivation and Context
A user in an experiment holdout still gets bucketed into a regular variant when their flag is evaluated locally. The team running that experiment believes a population is excluded from it, and it is not.
holdout-<id>(flag_matching.rs).filters.holdoutand returnedcontrolortestinstead./flags, so the holdout failed silently./local_evaluationalready sends the holdout inside the flag'sfilters, so no server-side data was missing.🔧 What changed
match_feature_flag_propertiesresolves the holdout before release conditions and returnsholdout-<id>, so a held-out value never reaches the flag's targeting._holdout_hashhashesholdout-<bucketing_value>. The existing_hashhelper cannot be reused because it joins key and value with a dot, which selects a different population while still looking uniform and deterministic.💚 How did you test it?
Four tests in
TestLocalEvaluation. Three of them fail onmainand pass with this change; the fourth (a 0% holdout excludes nobody) passes either way and is there as a control.The parity test is the one that matters. It pins the exact membership set for a 20% holdout against hashes computed from the server's algorithm, and asserts that the dot-joined variant produces a different set. Without that second assertion the test would pass with the dot bug present.
Suites run
posthog/test/test_feature_flags.pyandposthog/test/test_evaluate_flags.py, 276 passed.Not run:
mypy,make public_api_check, and the rest of the suite.📝 Checklist
If releasing new changes
sampo addto generate a changeset fileNote
The changeset was written by hand into
.sampo/changesets/, not generated bysampo add.Warning
This changes bucketing for flags that carry a holdout. On upgrade, users a holdout should always have excluded start being excluded, so variant assignment shifts for that share of traffic. The new behavior matches the server, so it removes a divergence rather than creating one.
Docs are unchanged here, but the holdouts page does not say which SDK versions honor holdouts locally. Worth adding once this ships.
🤖 Agent context
Autonomy: Human-driven (agent-assisted)
Investigated and written with Claude Code, model
claude-opus-5[1m]. Skill invoked:writing-pr-descriptions.The first approach considered was the opposite: omit holdout-bearing flags from
/local_evaluationso every SDK version falls back to the server immediately, without an SDK release. That was rejected. A holdout needs no server-side data, unlike a static cohort or experience continuity, so falling back would trade correct local behavior for a network round trip.The bug was confirmed by running local evaluation against a flag with a 100% holdout and comparing it to the same flag without one. The outputs were identical, which rules out both "holdout honored" and "fell back to the server".
Other server SDKs were not checked. Their local evaluators are separate implementations and may or may not have the same gap.
🤖 Generated with Claude Code