Skip to content

feat(server): evaluate early-access feature enrollment locally - #997

Merged
marandaneto merged 4 commits into
PostHog:mainfrom
srednoff888-art:feat/server-local-feature-enrollment
Nov 25, 2026
Merged

marandaneto merged 4 commits into
PostHog:mainfrom
srednoff888-art:feat/server-local-feature-enrollment

Conversation

@srednoff888-art

@srednoff888-art srednoff888-art commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

💡 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-server ignored it and went straight to the release conditions, so:

  1. an opted-out person (false) who matched a release condition got true locally while /flags returned false;
  2. without the enrollment property, the flag was evaluated from its release conditions instead of falling back to /flags.

Following the local-feature-flag-evaluator spec (PostHog/sdk-specs#178) and the posthog-python implementation (PostHog/posthog-python#1176):

  • FlagEvaluator.matchFeatureEnrollment:
    • true or "true" is enrolled;
    • any other value that was passed, null included, is opted out;
    • a missing property throws InconclusiveMatchException with MISSING_CONTEXT.
  • matchFeatureFlagProperties calls 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.
  • computeFlagLocally checks experience continuity before it resolves a group. Any group flag with it is now reported as EXPERIENCE_CONTINUITY when its group is missing, where it used to return false. That matches the load-time check.
  • PostHogFeatureFlags.computeFlagLocally handles 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.
  • definitionUnresolvedReason returns null for 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"), default false). The class is @PostHogInternal, and apiCheck passes for posthog and posthog-server.
  • Changeset: patch for posthog (the model), minor for posthog-server.

Not included:

main is merged in after #996 (condition order and early_exit). evaluateCondition takes the person's properties, and isConditionMatch is gone: nothing has called it since #996.

💚 How did you test it?

New FeatureEnrollmentTest, following the @server scenarios in acceptance/private/local-feature-flag-enrollment.feature:

  • every listed value, against release conditions that give the opposite answer;
  • missing enrollment is MISSING_CONTEXT;
  • experience continuity wins whatever the enrollment;
  • a false, null or absent marker keeps ordinary targeting;
  • an unsupported static cohort in release conditions is skipped, including in definitionUnresolvedReason;
  • a dependent flag uses the enrollment.

Through PostHogFeatureFlags with a mock server:

  • a group flag reads the person's enrollment without group context;
  • group properties can't override a person's opt-out;
  • missing enrollment falls back to /flags;
  • a group flag that depends on an enrollment flag, directly and through a cohort, reads the person's enrollment;
  • a group enrollment flag with experience continuity stays unresolved without groups;
  • in evaluateFlags, missing enrollment leaves only the flag and its dependents unresolved;
  • group properties don't stand in for a missing enrollment;
  • an enrollment flag with a static cohort reports MISSING_CONTEXT without a load-time warning;
  • an inactive flag is off;
  • an enrolled flag has its payload, and an opted-out one has none.

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 merged evaluateCondition, the early_exit stop and the feature_enrollment JSON 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 same PostHogServerWireSnapshotTest exception-event snapshot that fails on a clean main checkout on this Windows machine.
  • spotlessCheck and apiCheck pass.

📝 Checklist

  • All commits are signed (see Commit signing)
  • I reviewed the submitted code.
  • I added tests to verify the changes.
  • I updated the docs if needed.
  • No breaking change or entry added to the changelog.

If releasing new changes

  • Ran pnpm changeset to generate a changeset file

🤖 Agent context

Autonomy: Human-driven (agent-assisted)

  • Written with Claude Code. The account owner asked for fixes to open PostHog SDK issues, and the agent picked this item from #138580's "SDKs to update" list. The owner has reviewed the full diff at 82d1edd.

🤖 Generated with Claude Code

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>
@srednoff888-art
srednoff888-art requested a review from a team as a code owner November 21, 2026 11:02

@dustinbyrne dustinbyrne left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.matchFeatureFlagProperties reads groupProperties instead of personProperties.
  • Concern: On a group-aggregated enrollment flag with ensure_experience_continuity: true, omitting groups falls through to return false locally instead of reporting EXPERIENCE_CONTINUITY.
  • Concern: FeatureEnrollmentTest does not yet exercise the primary evaluateFlags() / unresolvedFlags entry path or several sdk-specs edge 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.)

@dustinbyrne
dustinbyrne requested a review from a team November 23, 2026 19:02
srednoff888-art and others added 3 commits November 23, 2026 23:37
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 marandaneto left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code looks good; no qualifying findings. Verdict: correct.

Thank you for your contribution!

@marandaneto
marandaneto merged commit 2df862f into PostHog:main Nov 25, 2026
16 of 18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants