Skip to content

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

Open
haacked wants to merge 2 commits into
mainfrom
haacked/minimal-flag-called-events
Open

feat(flags): minimize $feature_flag_called events for non-experiment flags in the compliance adapter#482
haacked wants to merge 2 commits 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

github-actions Bot commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

posthog-flutter Compliance Report

Date: 2026-07-18 04:27:32 UTC
Duration: 96866ms

✅ All Tests Passed!

45/45 tests passed


Capture Tests

29/29 tests passed

View Details
Test Status Duration
Format Validation.Event Has Required Fields 141ms
Format Validation.Event Has Uuid 118ms
Format Validation.Event Has Lib Properties 117ms
Format Validation.Distinct Id Is String 116ms
Format Validation.Token Is Present 116ms
Format Validation.Custom Properties Preserved 118ms
Format Validation.Event Has Timestamp 118ms
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 8122ms
Retry Behavior.Implements Backoff 15448ms
Retry Behavior.Retries On 500 5226ms
Retry Behavior.Retries On 502 5227ms
Retry Behavior.Retries On 504 5226ms
Retry Behavior.Max Retries Respected 15446ms
Deduplication.Generates Unique Uuids 125ms
Deduplication.Preserves Uuid On Retry 5225ms
Deduplication.Preserves Uuid And Timestamp On Retry 10336ms
Deduplication.Preserves Uuid And Timestamp On Batch Retry 5232ms
Deduplication.No Duplicate Events In Batch 126ms
Deduplication.Different Events Have Different Uuids 117ms
Compression.Sends Gzip When Enabled 117ms
Batch Format.Uses Proper Batch Structure 115ms
Batch Format.Flush With No Events Sends Nothing 109ms
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 14ms
Request Payload.Flags Request Uses V2 Query Param 10ms
Request Payload.Flags Request Hits Flags Path Not Decide 10ms
Request Payload.Flags Request Omits Authorization Header 10ms
Request Payload.Token In Flags Body Matches Init 10ms
Request Payload.Groups Round Trip 10ms
Request Payload.Groups Default To Empty Object 9ms
Request Payload.Person Properties Distinct Id Auto Populated When Caller Omits It 10ms
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 113ms
Request Lifecycle.Two Flag Calls Produce Two Remote Requests 18ms
Request Lifecycle.Mock Response Value Is Returned To Caller 10ms
Side Effect Events.Get Feature Flag Captures Feature Flag Called Event 116ms

Add a test case for a gated flag with malformed (non-boolean)
has_experiment metadata, closing a gap where that fallback path was
untested. Add explicit token/distinct_id value assertions to the
minimal-event test.
@haacked
haacked marked this pull request as ready for review July 18, 2026 04:42
@haacked
haacked requested a review from a team as a code owner July 18, 2026 04:42
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