fix: include group context in $feature_flag_called dedupe key#153
Merged
gustavohstrassburger merged 4 commits intoMay 27, 2026
Merged
Conversation
In `_capture_feature_flag_called_if_needed`, the per-`distinct_id` dedupe key only included the flag key and response. For group-scoped flags this meant that when the same user was evaluated under a different group, no new `$feature_flag_called` event was fired — causing per-group exposure undercount for experiments scoped to a group key. Include the sorted `groups` hash in the dedupe key so that the same `(distinct_id, flag, response)` combination fires once per distinct group context. Repeated calls under the same group context still dedupe, and calls that pass the same map in a different key order still dedupe (the groups are canonicalized via `groups.sort.to_json` before being mixed into the dedup key). Mirrors the posthog-node fix in PostHog/posthog-js#3658 (which closes PostHog/posthog-js#3651). Both SDKs share the same dedupe shape, so backend evaluation needs the same change. Generated-By: PostHog Code Task-Id: d94308d9-7655-4bac-8f15-c61478b5fca1
Generated-By: PostHog Code Task-Id: d94308d9-7655-4bac-8f15-c61478b5fca1
Prompt To Fix All With AIFix the following 1 code review issue. Work through them one at a time, proposing concise fixes.
---
### Issue 1 of 1
spec/posthog/client_spec.rb:619-682
**Duplicated test setup across all three new examples**
The `api_feature_flag_res` hash, `stub_request`, and `Client.new` lines are copy-pasted verbatim in each of the three new `it` blocks. Extracting them into `let`/`before` inside a shared `context` would satisfy the OnceAndOnlyOnce rule and align with the team preference for parameterised tests. The deduplication pair (same-context → one event, different-context → two events) are also natural candidates for a parameterised example to remove repetition between tests 2 and 3.
Reviews (1): Last reviewed commit: "chore: add changeset" | Re-trigger Greptile |
ioannisj
approved these changes
May 27, 2026
ioannisj
left a comment
There was a problem hiding this comment.
One bot comment but not a blocker I believe
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
In
_capture_feature_flag_called_if_needed(lib/posthog/client.rb), the per-distinct_iddedupe key only included the flag key and response. For group-scoped flags this meant that when the same user was evaluated under a different group, no new$feature_flag_calledevent was fired — causing per-group exposure undercount for experiments scoped to a group key.Mirrors the posthog-node fix in PostHog/posthog-js#3658 (which closes PostHog/posthog-js#3651). Both SDKs share the same dedupe shape, so backend evaluation needs the same change.
💚 How did you test it?
Added three rspec examples covering the new behavior in
spec/posthog/client_spec.rb:$feature_flag_called fires per group context (group-scoped dedup)— same user, same flag, two different group contexts → two events.$feature_flag_called dedupes across repeated calls under the same group context— repeated access under the same group → one event.$feature_flag_called dedupes when same groups are passed in different key order— same groups passed with keys in a different order → one event (canonicalized viagroups.sort.to_json).All 78 existing client tests pass, and all 35
feature_flag_evaluations_spectests pass.📝 Checklist
If releasing new changes
pnpm changesetto generate a changeset fileCreated with PostHog Code