Repository navigation
feat(server): evaluate early-access feature enrollment locally - #997
marandaneto merged 4 commits into
Conversation
Early-access features create flags with filters.feature_enrollment, and a person's opt-in is the person property $feature_enrollment/<flag key>. posthog-server ignored it and went straight to release conditions, so an opted-out person who matched a release condition got true while /flags returned false, and a flag was evaluated locally when the enrollment property was missing. Follow the local-feature-flag-evaluator spec: after the active check, and with experience continuity still taking precedence, enrollment decides the flag. true or "true" is enrolled, any other value that was passed (null included) is opted out, and a missing property is inconclusive (missing_context) so the flag falls back to /flags. Group-aggregated flags read the person's enrollment before any group is resolved, and dependent flags use the same rule. definitionUnresolvedReason no longer reports an enrollment flag as unsupported because of release conditions it never reads. Adds FlagFilters.featureEnrollment. Part of PostHog/posthog#138580 (posthog-server) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
dustinbyrne
left a comment
There was a problem hiding this comment.
AI-assisted review.
Thanks for implementing local early-access feature enrollment for posthog-server — the core enrollment matching in FlagEvaluator.matchFeatureEnrollment, definitionUnresolvedReason, and the @PostHogInternal FlagFilters.featureEnrollment field align cleanly with PostHog/sdk-specs and the PostHog backend.
A few issues stood out before approval (details inline):
- Breaking: When a group-aggregated flag depends on an early-access enrollment flag,
FlagEvaluator.matchFeatureFlagPropertiesreadsgroupPropertiesinstead ofpersonProperties. - Concern: On a group-aggregated enrollment flag with
ensure_experience_continuity: true, omittinggroupsfalls through toreturn falselocally instead of reportingEXPERIENCE_CONTINUITY. - Concern:
FeatureEnrollmentTestdoes not yet exercise the primaryevaluateFlags()/unresolvedFlagsentry path or severalsdk-specsedge cases (active: false,"feature_enrollment": null, static-cohort load-time warning suppression, and missing person enrollment when group properties contain the enrollment key).
Follow-up (cross-repo, non-blocking): Once this releases in posthog-server, PostHog/posthog.com (contents/docs/libraries/java/index.mdx and contents/docs/feature-flags/local-evaluation/index.mdx) still state that local evaluation is not possible for early-access feature flags and will need a follow-up update.
(Note: static source review only; GitHub Actions workflows have not yet run on this head and local Gradle execution was not run during review.)
A group flag passed the group's properties to the flags it depends on, so an early-access dependency read its enrollment from them. Keep the person's properties through the evaluation. Also report experience continuity before a group is resolved, like the load-time check. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… them on A forgotten argument would have fallen back to the group properties. Also test the payload of an enrollment flag. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Resolve the conflicts with PostHog#996. Both fields stay on FlagFilters, and evaluateCondition takes the person's properties. Drop isConditionMatch, which nothing has called since PostHog#996. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
marandaneto
left a comment
There was a problem hiding this comment.
The code looks good; no qualifying findings. Verdict: correct.
Thank you for your contribution!
💡 Motivation and Context
Part of PostHog/posthog#138580, for
posthog-server.Early-access features create flags with
filters.feature_enrollment: true, and a person's opt-in is the person property$feature_enrollment/<flag key>.posthog-serverignored it and went straight to the release conditions, so:false) who matched a release condition gottruelocally while/flagsreturnedfalse;/flags.Following the
local-feature-flag-evaluatorspec (PostHog/sdk-specs#178) and the posthog-python implementation (PostHog/posthog-python#1176):FlagEvaluator.matchFeatureEnrollment:trueor"true"is enrolled;nullincluded, is opted out;InconclusiveMatchExceptionwithMISSING_CONTEXT.matchFeatureFlagPropertiescalls it right after the experience continuity check, so continuity still wins. Dependent flags go through it too, with the person properties: a group flag that depends on an enrollment flag, directly or through a cohort, reads the person's opt-in.computeFlagLocallychecks experience continuity before it resolves a group. Any group flag with it is now reported asEXPERIENCE_CONTINUITYwhen its group is missing, where it used to returnfalse. That matches the load-time check.PostHogFeatureFlags.computeFlagLocallyhandles group-aggregated enrollment flags before resolving the group. It reads the person properties, so a group flag answers from the person's opt-in even without group context, and group properties can't turn an opt-out into enrollment.definitionUnresolvedReasonreturnsnullfor an enrollment flag, so a static cohort in release conditions it never reads doesn't trigger the "unsupported definition" warning.FlagFilters.featureEnrollment(@SerializedName("feature_enrollment"), defaultfalse). The class is@PostHogInternal, andapiCheckpasses forposthogandposthog-server.posthog(the model), minor forposthog-server.Not included:
posthog-serverdoesn't evaluate today;mainis merged in after #996 (condition order andearly_exit).evaluateConditiontakes the person's properties, andisConditionMatchis gone: nothing has called it since #996.💚 How did you test it?
New
FeatureEnrollmentTest, following the@serverscenarios inacceptance/private/local-feature-flag-enrollment.feature:MISSING_CONTEXT;false,nullor absent marker keeps ordinary targeting;definitionUnresolvedReason;Through
PostHogFeatureFlagswith a mock server:/flags;evaluateFlags, missing enrollment leaves only the flag and its dependents unresolved;MISSING_CONTEXTwithout a load-time warning;17 tests. Without the second commit, 3 of them fail: the two dependency tests and the continuity one. I also removed or altered the enrollment value check, the definition check, the group-flag check and the passing of the person's properties to dependencies, one at a time, and a test failed every time.
After merging
main, I also broke the passing of the person's properties through the mergedevaluateCondition, theearly_exitstop and thefeature_enrollmentJSON name, one at a time, and a test failed every time.:posthog:test: 1337 tests, 0 failures.:posthog-server:test: 715 tests, 1 failure, the samePostHogServerWireSnapshotTestexception-event snapshot that fails on a cleanmaincheckout on this Windows machine.spotlessCheckandapiCheckpass.📝 Checklist
If releasing new changes
pnpm changesetto generate a changeset file🤖 Agent context
Autonomy: Human-driven (agent-assisted)
82d1edd.🤖 Generated with Claude Code