Skip to content

feat(flags): minimize $feature_flag_called events for non-experiment flags in the compliance adapter#482

Draft
haacked wants to merge 1 commit into
mainfrom
haacked/minimal-flag-called-events
Draft

feat(flags): minimize $feature_flag_called events for non-experiment flags in the compliance adapter#482
haacked wants to merge 1 commit into
mainfrom
haacked/minimal-flag-called-events

Conversation

@haacked

@haacked haacked commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

💡 Motivation and Context

The Flutter SDK never captures $feature_flag_called in Dart: on iOS and Android the native posthog-ios / posthog-android SDKs capture it over the method channel, and on web it delegates to posthog-js. Flutter apps will therefore get minimal events via the native SDK releases, and this repo's production code needs no change.

This PR implements the minimal-event contract in sdk_compliance_adapter — the only capture path this repo owns, and the same place the $feature_flag_has_experiment support landed in #475 — so the cross-SDK compliance harness can validate the behavior:

  • Emit a minimal $feature_flag_called event iff the v2 /flags response carries top-level minimalFlagCalledEvents == true and the evaluated flag's has_experiment == false.
  • Any missing signal (field absent, legacy response shape, has_experiment unreported) → full event, exactly as today.
  • The minimal shape is a strict allowlist built from scratch; for this adapter that keeps $feature_flag, $feature_flag_response, $feature_flag_has_experiment, $lib, and $lib_version, and drops the $feature/<key> enumeration. distinct_id/token remain as transport fields of the adapter's batch protocol.

The motivation is trimming non-experiment $feature_flag_called events down to a strict allowlist of useful properties. The gate is server-controlled, so nothing changes for any team until it is enabled. Experiment-linked flags always keep the full envelope since experiment exposure analysis reads it.

Part of a cross-SDK rollout; reference implementation and fuller context: PostHog/posthog-python#748

💚 How did you test it?

  • flutter test in sdk_compliance_adapter (unit test files): 11/11 passed, including 5 new tests — gated + no experiment → exactly the allowlist key set; gated + experiment → full; ungated → full; gated + unreported has_experiment → full; the gate tracks the latest flags response.
  • flutter test in posthog_flutter: 193/193 passed (unchanged).
  • dart analyze .: no issues.
  • dart format --set-exit-if-changed sdk_compliance_adapter: clean.

No CHANGELOG entry, matching adapter-only precedent (#475).

📝 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

Created with PostHog Code

When the /flags?v=2 response carries top-level
minimalFlagCalledEvents == true and the evaluated flag reports
has_experiment == false, the compliance adapter sends only the
cross-SDK minimal allowlist on $feature_flag_called (dropping the
$feature/<key> enumeration). Any missing signal, including legacy
response shapes and unreported has_experiment, falls back to the
full event.

Generated-By: PostHog Code
Task-Id: ffe402fd-d75c-4043-8e5d-d2fe513cac6f
@haacked haacked self-assigned this Jul 16, 2026
@github-actions

Copy link
Copy Markdown
Contributor

posthog-flutter Compliance Report

Date: 2026-07-16 20:26:50 UTC
Duration: 96801ms

✅ All Tests Passed!

45/45 tests passed


Capture Tests

29/29 tests passed

View Details
Test Status Duration
Format Validation.Event Has Required Fields 140ms
Format Validation.Event Has Uuid 119ms
Format Validation.Event Has Lib Properties 115ms
Format Validation.Distinct Id Is String 114ms
Format Validation.Token Is Present 114ms
Format Validation.Custom Properties Preserved 118ms
Format Validation.Event Has Timestamp 116ms
Retry Behavior.Retries On 503 5331ms
Retry Behavior.Does Not Retry On 400 2117ms
Retry Behavior.Does Not Retry On 401 2118ms
Retry Behavior.Respects Retry After Header 8121ms
Retry Behavior.Implements Backoff 15445ms
Retry Behavior.Retries On 500 5226ms
Retry Behavior.Retries On 502 5223ms
Retry Behavior.Retries On 504 5224ms
Retry Behavior.Max Retries Respected 15432ms
Deduplication.Generates Unique Uuids 124ms
Deduplication.Preserves Uuid On Retry 5220ms
Deduplication.Preserves Uuid And Timestamp On Retry 10333ms
Deduplication.Preserves Uuid And Timestamp On Batch Retry 5229ms
Deduplication.No Duplicate Events In Batch 124ms
Deduplication.Different Events Have Different Uuids 116ms
Compression.Sends Gzip When Enabled 117ms
Batch Format.Uses Proper Batch Structure 113ms
Batch Format.Flush With No Events Sends Nothing 108ms
Batch Format.Multiple Events Batched Together 125ms
Error Handling.Does Not Retry On 403 2115ms
Error Handling.Does Not Retry On 413 2117ms
Error Handling.Retries On 408 5225ms

Feature_Flags Tests

16/16 tests passed

View Details
Test Status Duration
Request Payload.Request With Person Properties Device Id 13ms
Request Payload.Flags Request Uses V2 Query Param 10ms
Request Payload.Flags Request Hits Flags Path Not Decide 9ms
Request Payload.Flags Request Omits Authorization Header 10ms
Request Payload.Token In Flags Body Matches Init 9ms
Request Payload.Groups Round Trip 9ms
Request Payload.Groups Default To Empty Object 10ms
Request Payload.Person Properties Distinct Id Auto Populated When Caller Omits It 9ms
Request Payload.Disable Geoip False Propagates As Geoip Disable False 10ms
Request Payload.Disable Geoip Omitted Defaults To False 9ms
Request Payload.Flag Keys To Evaluate Contains Only Requested Key 10ms
Request Lifecycle.No Flags Request On Init Alone 4ms
Request Lifecycle.No Flags Request On Normal Capture 112ms
Request Lifecycle.Two Flag Calls Produce Two Remote Requests 15ms
Request Lifecycle.Mock Response Value Is Returned To Caller 9ms
Side Effect Events.Get Feature Flag Captures Feature Flag Called Event 115ms

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.

1 participant