fix(flags): deserialize cohorts payload for local evaluation - #187
Merged
slshults merged 5 commits intoAug 7, 2026
Merged
Conversation
The `/flags/definitions/?send_cohorts` response maps each cohort ID
straight to its property group (`{"type": "AND"|"OR", "values": [...]}`),
but `Cohort` required non-existent `id`/`name`/`properties` fields. serde
failed on any non-empty `cohorts` map, which took down the entire
`LocalEvaluationResponse` — so no flags loaded at all for projects with
cohorts.
`Cohort` is now transparent over the raw property group, and cohort
matching recurses through nested AND/OR groups and cohort references
(honoring `negation`) instead of flattening them and keeping only the
first property of any nested group.
Generated-By: PostHog Code
Task-Id: c95f4271-0d14-497f-b62a-49f1e8c919bb
Contributor
posthog-rs-v0 Compliance ReportDate: 2026-08-07 07:26:30 UTC ✅ All Tests Passed!46/46 tests passed Capture Tests✅ 29/29 tests passed View Details
Feature_Flags Tests✅ 17/17 tests passed View Details
|
Contributor
posthog-rs-v1 Compliance ReportDate: 2026-08-07 07:27:52 UTC ✅ All Tests Passed!111/111 tests passed Capture_V1 Tests✅ 94/94 tests passed View Details
Feature_Flags Tests✅ 17/17 tests passed View Details
|
Member
The `Cohort` struct no longer carries the invented `id`/`name` fields — it is now transparent over the raw cohort property group. Regenerate the checked-in public API snapshot accordingly so the Public API check passes. Generated-By: PostHog Code Task-Id: c95f4271-0d14-497f-b62a-49f1e8c919bb
marandaneto
reviewed
Aug 7, 2026
marandaneto
approved these changes
Aug 7, 2026
5 tasks
slshults
deleted the
posthog-self-driving/fixflags-deserialize-cohorts-correctly-ff65ce
branch
August 7, 2026 22:12
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
LocalEvaluationResponse.cohortswas typed asHashMap<String, Cohort>whereCohortrequiredid,name, andproperties. None of those exist in the payload —/flags/definitions/?send_cohortsmaps each cohort ID straight to a bare property group,{"type": "AND"|"OR", "values": [...]}. serde fails withmissing field id, and because that kills the whole response, every flag fails to load, not just cohort-targeted ones."cohorts": {}— the non-empty path was never exercised.Changes
Cohortnow matches the wire format — it's#[serde(transparent)]over the raw property group, and the owning cohort ID is the map key (dropping the inventedid/name).match_property_groupwalks nestedAND/ORgroups and cohort references (honoringnegation), mirroring posthog-python'smatch_property_group. This replaces the old flatten-to-a-flat-Vec<Property>-and-ANDlogic, which threw away the group type and kept only the first property of any nested group via.next()— silently wrong forORand nested groups even once it parsed.💚 How did you test it?
cohortspayload (nestedAND/OR) end-to-end through the cache and evaluator — the exact path that used to fail — so"cohorts": {}fixtures can't hide this again.ORgroups, nestedAND-of-OR, and cohort-referencing-cohort withnegation.cargo test --lib feature_flags(86) andcargo test --test test_local_evaluation(22) pass;cargo fmt/clippyclean. (Pre-existingerror_trackingsymbolication test failures are unrelated and present onmainin this environment.)📝 Checklist
If releasing new changes
sampo addto generate a changeset fileCreated with PostHog Desktop from this inbox report.