feat(flags): support group-targeted and mixed-targeting flags in local eval#107
Open
patricio-posthog wants to merge 2 commits intomainfrom
Open
feat(flags): support group-targeted and mixed-targeting flags in local eval#107patricio-posthog wants to merge 2 commits intomainfrom
patricio-posthog wants to merge 2 commits intomainfrom
Conversation
turnipdabeets
approved these changes
Apr 30, 2026
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
Two related gaps in the Rust SDK's local evaluation, addressed together because supporting mixed targeting requires the underlying group-flag plumbing:
aggregation_group_type_indexis set at the flag level) weren't evaluated locally. The matcher only knew about person properties and bucketed ondistinct_idunconditionally; the publicClient::get_feature_flagacceptedgroups/group_propertiesbut silently dropped them on the local-eval path.feature-flag-mixed-targetingbeta), where individual conditions set their ownaggregation_group_type_index, couldn't be evaluated locally either. This breaks customers using flags in environments that can't make HTTP fallback calls (background workers, etc).Brings posthog-rs to parity with the other PostHog SDKs (Python, Node, Go, Ruby, PHP, .NET) which already support both. Equivalent of posthog-python#523 plus the prerequisite group-flag baseline.
How did you test it?
All 112 existing tests pass. Added 7 new tests in
tests/test_local_evaluation.rs:test_pure_group_flag_matches_with_group_passed_intest_pure_group_flag_returns_false_when_groups_not_passedtest_mixed_flag_person_condition_matches_when_no_groupstest_mixed_flag_group_condition_matches_with_group_propstest_mixed_flag_no_match_when_both_failtest_mixed_flag_only_group_condition_no_groups_returns_falsetest_group_condition_uses_group_key_for_bucketing— partial-rollout test with pre-computed hashes that would catch a regression to bucketing ondistinct_idcargo fmt --checkclean,cargo clippy --all-targetsclean.Breaking change at the public API
This is a
minorsemver bump (the SDK is at 0.5.x, pre-1.0). Public functions whose signatures changed:LocalEvaluator::evaluate_flag(key, distinct_id, person_properties)— now takesgroups: &HashMap<String, String>andgroup_properties: &HashMap<String, HashMap<String, serde_json::Value>>as additional parameters.LocalEvaluator::evaluate_flag_simple(...)— same change.LocalEvaluator::evaluate_all_flags(distinct_id, person_properties)— same change.match_feature_flag(flag, distinct_id, properties)— now takesgroups,group_properties, andgroup_type_mappingas additional parameters.match_feature_flag_with_context(flag, distinct_id, properties, ctx)— drops thedistinct_idparameter (now read fromctx.distinct_id);EvaluationContextgainsgroups,group_properties, andgroup_type_mappingfields.Client::evaluate_feature_flag_locally(...)(both async and blocking) — addsgroupsandgroup_propertiesparameters.For callers using person flags only, pass
&HashMap::new()for the new group parameters.Checklist
If releasing new changes
sampo addto generate a changeset filereleaselabel to the PR