Skip to content

feat(flags): add $feature_flag_has_experiment to $feature_flag_called events - #621

Merged
haacked merged 2 commits into
mainfrom
haacked/feature-flag-has-experiment
Jul 15, 2026
Merged

haacked merged 2 commits into
mainfrom
haacked/feature-flag-has-experiment

Conversation

@haacked

@haacked haacked commented Jul 15, 2026 •

Copy link
Copy Markdown
Contributor

💡 Motivation and Context

Part of a cross-SDK effort to shrink $feature_flag_called events. This first phase adds a $feature_flag_has_experiment boolean property to every $feature_flag_called event, reflecting the server's has_experiment signal: metadata.has_experiment in the /flags?v=2 response and has_experiment on /api/feature_flag/local_evaluation flag definitions. When the server does not report the field (older deployments, bootstrapped flags), the property is omitted, so it is tri-state: true, false, or absent (unknown).

This lets ingestion distinguish experiment-linked flag events (which need the full property set for exposure analysis) from the rest, and lets us measure the split before a later phase strips the expensive properties ($feature/<key>, $feature_flag_payload, per-event system metadata) from non-experiment flag events. This PR intentionally minimizes nothing: no properties are removed, no config options are added, and dedupe behavior is unchanged.

Changes

  • FeatureFlagMetadata.hasExperiment (@SerializedName("has_experiment"), default false) parsed from /flags?v=2 metadata and round-tripping through both flag caches; the same field on FlagDefinition for /local_evaluation, threaded into buildFeatureFlagFromResult.
  • All send paths set the property: PostHog.sendFeatureFlagCalled, PostHogStateless.sendFeatureFlagCalled, PostHogFeatureFlagEvaluations.recordAccess, and the compliance adapter's hand-built capture, defaulting to false when details are unavailable (null details, unknown flags, bootstrap/cache-degraded flags).
  • posthog.api regenerated; minor changeset for posthog and posthog-server.

Known pre-existing gap (not introduced here): the server SDK's single-flag local-evaluation fast path (resolveFeatureFlag) doesn't populate flag details, so events from that path report false even for experiment flags, same as the existing $feature_flag_id/$feature_flag_version behavior there. The evaluateFlags snapshot path reports it correctly. This must be fixed before any event-minimization phase.

💚 How did you test it?

./gradlew :posthog:test :posthog-server:test :posthog:apiCheck :posthog-server:apiCheck spotlessCheck: BUILD SUCCESSFUL. New tests cover true / explicit-false / absent across the client, stateless, snapshot, Gson-parse, and local-evaluation paths. The :posthog-android module is untouched (and requires an Android SDK not present locally); the change lives in the pure-JVM posthog and posthog-server modules. The compliance adapter compiles (:sdk_compliance_adapter:compileKotlin).

📝 Checklist

  • 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

@github-actions

github-actions Bot commented Jul 15, 2026 •

Copy link
Copy Markdown
Contributor

posthog-android Compliance Report

Date: 2026-07-15 23:31:22 UTC
Duration: 118534ms

✅ All Tests Passed!

46/46 tests passed


Capture Tests

✅ 29/29 tests passed

View Details
Test Status Duration
Format Validation.Event Has Required Fields ✅ 406ms
Format Validation.Event Has Uuid ✅ 38ms
Format Validation.Event Has Lib Properties ✅ 31ms
Format Validation.Distinct Id Is String ✅ 29ms
Format Validation.Token Is Present ✅ 28ms
Format Validation.Custom Properties Preserved ✅ 25ms
Format Validation.Event Has Timestamp ✅ 30ms
Retry Behavior.Retries On 503 ✅ 7027ms
Retry Behavior.Does Not Retry On 400 ✅ 4026ms
Retry Behavior.Does Not Retry On 401 ✅ 4026ms
Retry Behavior.Respects Retry After Header ✅ 7026ms
Retry Behavior.Implements Backoff ✅ 17032ms
Retry Behavior.Retries On 500 ✅ 7019ms
Retry Behavior.Retries On 502 ✅ 7021ms
Retry Behavior.Retries On 504 ✅ 7018ms
Retry Behavior.Max Retries Respected ✅ 17023ms
Deduplication.Generates Unique Uuids ✅ 45ms
Deduplication.Preserves Uuid On Retry ✅ 7016ms
Deduplication.Preserves Uuid And Timestamp On Retry ✅ 12034ms
Deduplication.Preserves Uuid And Timestamp On Batch Retry ✅ 7019ms
Deduplication.No Duplicate Events In Batch ✅ 37ms
Deduplication.Different Events Have Different Uuids ✅ 29ms
Compression.Sends Gzip When Enabled ✅ 23ms
Batch Format.Uses Proper Batch Structure ✅ 23ms
Batch Format.Flush With No Events Sends Nothing ✅ 15ms
Batch Format.Multiple Events Batched Together ✅ 35ms
Error Handling.Does Not Retry On 403 ✅ 4024ms
Error Handling.Does Not Retry On 413 ✅ 4022ms
Error Handling.Retries On 408 ✅ 5034ms

Feature_Flags Tests

✅ 17/17 tests passed

View Details
Test Status Duration
Request Payload.Request With Person Properties Device Id ✅ 36ms
Request Payload.Flags Request Uses V2 Query Param ✅ 25ms
Request Payload.Flags Request Hits Flags Path Not Decide ✅ 24ms
Request Payload.Flags Request Omits Authorization Header ✅ 29ms
Request Payload.Token In Flags Body Matches Init ✅ 23ms
Request Payload.Groups Round Trip ✅ 26ms
Request Payload.Groups Default To Empty Object ✅ 29ms
Request Payload.Disable Geoip False Propagates As Geoip Disable False ✅ 25ms
Request Payload.Disable Geoip Omitted Defaults To False ✅ 26ms
Request Payload.Flag Keys To Evaluate Contains Only Requested Key ✅ 25ms
Request Lifecycle.No Flags Request On Init Alone ✅ 9ms
Request Lifecycle.No Flags Request On Normal Capture ✅ 25ms
Request Lifecycle.Two Flag Calls Produce Two Remote Requests ✅ 38ms
Request Lifecycle.Mock Response Value Is Returned To Caller ✅ 27ms
Retry Behavior.Retries Flags On 502 ✅ 327ms
Retry Behavior.Retries Flags On 504 ✅ 334ms
Side Effect Events.Get Feature Flag Captures Feature Flag Called Event ✅ 26ms

@haacked haacked changed the title Add $feature_flag_has_experiment to $feature_flag_called events feat(flags): add $feature_flag_has_experiment to $feature_flag_called events Jul 15, 2026
@haacked
haacked marked this pull request as ready for review July 15, 2026 18:29
@haacked
haacked requested a review from a team as a code owner July 15, 2026 18:29
@greptile-apps

greptile-apps Bot commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Reviews (1): Last reviewed commit: "Add $feature_flag_has_experiment to $fea..." | Re-trigger Greptile

Comment thread posthog/src/main/java/com/posthog/internal/FeatureFlagMetadata.kt Outdated
Comment thread posthog/src/main/java/com/posthog/internal/PostHogLocalEvaluationModels.kt Outdated

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

LGTM! All four send paths read the metadata null-safely, the Gson absent-field default is pinned by tests, and true/false/absent are covered on every layer. The greptile binary-compat P1s look dismissible to me since both classes are @PostHogInternal and posthog/posthog-server release in lockstep — same precedent as ensureExperienceContinuity.

@haacked
haacked merged commit 2cdc0d7 into main Jul 15, 2026
17 checks passed
@haacked
haacked deleted the haacked/feature-flag-has-experiment branch July 15, 2026 23:37
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.

2 participants