Skip to content

fix(server): don't match person_metadata filters against person properties - #998

Merged
marandaneto merged 5 commits into
PostHog:mainfrom
srednoff888-art:fix/server-person-metadata-filters
Nov 25, 2026
Merged

marandaneto merged 5 commits into
PostHog:mainfrom
srednoff888-art:fix/server-person-metadata-filters

Conversation

@srednoff888-art

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

Copy link
Copy Markdown
Contributor

💡 Motivation and Context

Part of PostHog/posthog#137503, for posthog-server.

PropertyType.fromString mapped every unknown filter type to PERSON, including person_metadata (Person metadata > First seen). Local evaluation then matched it against a caller's created_at person property, which can disagree with /flags, since /flags reads the persons table.

  • New PropertyType.UNSUPPORTED for unknown types, an empty string included. "person" and "group" still map to PERSON. The class is @PostHogInternal, and apiCheck passes for posthog and posthog-server.
  • FlagEvaluator rejects UNSUPPORTED filters with unsupported_definition, both in the load-time definition check and during matching. That covers flag conditions and cohort criteria, and the flag falls back to /flags.

The same change for the other SDKs: PostHog/posthog-js#5840, PostHog/posthog-python#1288, PostHog/posthog-go#465, PostHog/posthog-rs#397.

💚 How did you test it?

New PersonMetadataFilterTest:

  • type parsing;
  • a condition filter is unsupported;
  • a person filter on created_at still matches;
  • the definition check reports the flag as unsupported;
  • a cohort filter falls back to /flags through PostHogFeatureFlags with a mock server;
  • PostHog.evaluateFlags reports a condition, a cohort and a negated cohort leaf as unsupported, with and without created_at;
  • the definition check reports a cohort filter as unsupported;
  • UNSUPPORTED survives a Gson round trip.

PostHogLocalEvaluationModelsTest.testPropertyTypeFromString expects the new mapping.

  • After the last, test-only commit: spotlessCheck and PersonMetadataFilterTest (8 tests) pass. The numbers below are from the commit before it.
  • :posthog:test: 1315 tests, 0 failures.
  • :posthog-server:test: 699 tests, 1 failure, the PostHogServerWireSnapshotTest exception snapshot, which also fails on clean main here (Windows).
  • spotlessCheck and apiCheck pass.

📝 Checklist

  • All commits are signed
  • I reviewed the submitted code.
  • I added tests to verify the changes.
  • No breaking change or entry added to the changelog.
  • 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 one. The owner has reviewed the full diff at 364a698.

🤖 Generated with Claude Code

…rties

PropertyType.fromString mapped every unknown filter type, including
person_metadata (Person metadata > First seen), to PERSON, so local
evaluation matched it against a caller's created_at person property and
could disagree with /flags, which reads the persons table.

Unknown types now parse to a new PropertyType.UNSUPPORTED ("person" and
"group" still map to PERSON). posthog-server rejects UNSUPPORTED filters
as unsupported_definition at load and during evaluation, so the flag
falls back to /flags.

Part of PostHog/posthog#137503 (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:14

@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.

The production change in PropertyType and FlagEvaluator looks directionally right for stopping unknown filter types like person_metadata from matching caller person properties. A few items need attention before approval (details inline):

  • Breaking: Updating PropertyType.fromString breaks an existing :posthog:test assertion (PostHogLocalEvaluationModelsTest.testPropertyTypeFromString:389).
  • Concern: Key changed paths—absent-property evaluation (UNSUPPORTED_DEFINITION vs MISSING_CONTEXT), public evaluateFlags(..., onlyEvaluateLocally = true) / unresolvedFlags with cohort negation: true, and GsonPropertyTypeAdapter serialization—lack regression tests.
  • Suggestion: Consider excluding explicit empty string "" from PropertyType.PERSON to match the PostHog backend and posthog-dotnet.

Follow-up (outside this PR): Track specifying unknown filter types in PostHog/sdk-specs (local-feature-flag-evaluator/spec.md) and applying matching fixes to remaining server SDKs (posthog-python, posthog-js/packages/node) under PostHog/posthog#137503.

AI-assisted review.

Update the type parsing test for the unsupported type, treat an empty type
as unsupported like /flags does, and cover evaluateFlags with nothing
passed, cohorts and negation, the definition check and the cache.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@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.

Thanks for the quick follow-up in 1113f193! All three earlier review items (PostHogLocalEvaluationModelsTest.testPropertyTypeFromString, excluding "" from PropertyType.PERSON, and expanding PersonMetadataFilterTest) are addressed, and the production changes look solid.

One remaining test-reliability concern inline: the new evaluateFlags test uses createMockHttp(jsonResponse(definitions)) (my earlier sketch used that too), which races the background LocalEvaluationPoller against a single-response QueueDispatcher.

AI-assisted review.

@dustinbyrne
dustinbyrne requested a review from a team November 23, 2026 22:33
The poller can load the definitions a second time. Route the responses by path
and count the /flags calls instead.

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 reopened this Nov 25, 2026
@marandaneto
marandaneto enabled auto-merge (squash) November 25, 2026 16:30
@marandaneto
marandaneto merged commit 2a17048 into PostHog:main Nov 25, 2026
16 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