Skip to content

Conversation

@haacked
Copy link
Contributor

@haacked haacked commented Oct 22, 2025

When a feature flag has multiple conditions and one contains a static cohort, the SDK should fallback to API for the entire flag evaluation instead of skipping the static cohort condition and evaluating subsequent conditions locally. This prevents returning incorrect variants when later conditions match locally but the user is actually in the static cohort.

Changes:

  • Introduce RequiresServerEvaluationException class to distinguish missing server-side data (static cohorts, experience continuity) from evaluation errors (bad regex, invalid dates, missing properties)
  • Update matchCohort() to throw RequiresServerEvaluationException when cohort not found in local cohorts
  • Propagate RequiresServerEvaluationException immediately in matchPropertyGroup() and matchFeatureFlagProperties()
  • Catch RequiresServerEvaluationException in getFeatureFlag(), getAllFlags(), and getFeatureFlagPayload() to trigger API fallback
  • Add test cases validating multi-condition flags with static cohorts fall back to API and return correct variants and payloads

Follows same pattern as Ruby SDK fix: PostHog/posthog-ruby#80

…orts

When a feature flag has multiple conditions and one contains a static cohort,
the SDK should fallback to API for the entire flag evaluation instead of
skipping the static cohort condition and evaluating subsequent conditions
locally. This prevents returning incorrect variants when later conditions
match locally but the user is actually in the static cohort.

Changes:
- Introduce RequiresServerEvaluationException class to distinguish missing
  server-side data (static cohorts, experience continuity) from evaluation
  errors (bad regex, invalid dates, missing properties)
- Update matchCohort() to throw RequiresServerEvaluationException when cohort
  not found in local cohorts
- Propagate RequiresServerEvaluationException immediately in matchPropertyGroup()
  and matchFeatureFlagProperties()
- Catch RequiresServerEvaluationException in getFeatureFlag(), getAllFlags(),
  and getFeatureFlagPayload() to trigger API fallback
- Add test cases validating multi-condition flags with static cohorts fall
  back to API and return correct variants and payloads

Follows same pattern as Ruby SDK fix: PostHog/posthog-ruby#80
@haacked haacked requested a review from a team October 22, 2025 00:59
@posthog-project-board-bot posthog-project-board-bot bot moved this to In Review in Feature Flags Oct 22, 2025
@github-project-automation github-project-automation bot moved this from In Review to Approved in Feature Flags Oct 22, 2025
@haacked haacked merged commit 8c39f98 into master Oct 23, 2025
10 checks passed
@github-project-automation github-project-automation bot moved this from Approved to Done in Feature Flags Oct 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants