Skip to content

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

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

feat(flags): add $feature_flag_has_experiment to $feature_flag_called events#219
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 parses has_experiment from /flags?v=2 metadata (boolean-coerced, default false).
  • Poller get_feature_flag returns has_experiment sourced from the stored /flags/definitions definition on local eval and from response metadata on remote fallback; get_all_flags_and_payloads carries parsed flag objects through an internal key (stripped from the public return) to reach metadata on the bulk remote path.
  • client.rb adds the property on the single-flag path and threads it into EvaluatedFlagRecords; snapshot-path events include it (missing flags omit the property).
  • Public API snapshot regenerated; minor changeset.

💚 How did you test it?

bundle exec rspec: 614 examples, 0 failures, with new coverage for remote true/false/absent/missing-flag, local-definition true/absent, single-flag local and remote v4/v3 paths, and metadata parsing; five existing exact-hash assertions updated. rubocop clean.

📝 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

Parse the server-reported has_experiment field from /flags v2 metadata and
/flags/definitions flag definitions, defaulting to false when the server does
not send it (older deployments), and include it as a boolean property on every
$feature_flag_called event across the single-flag, snapshot (evaluate_flags),
local, and remote evaluation paths.
@github-actions

github-actions Bot commented Jul 15, 2026

Copy link
Copy Markdown

posthog-ruby Compliance Report

Date: 2026-07-15 23:27:12 UTC
Duration: 98350ms

✅ All Tests Passed!

46/46 tests passed


Capture Tests

29/29 tests passed

View Details
Test Status Duration
Format Validation.Event Has Required Fields 9ms
Format Validation.Event Has Uuid 105ms
Format Validation.Event Has Lib Properties 108ms
Format Validation.Distinct Id Is String 106ms
Format Validation.Token Is Present 106ms
Format Validation.Custom Properties Preserved 106ms
Format Validation.Event Has Timestamp 107ms
Retry Behavior.Retries On 503 5413ms
Retry Behavior.Does Not Retry On 400 2108ms
Retry Behavior.Does Not Retry On 401 2109ms
Retry Behavior.Respects Retry After Header 8115ms
Retry Behavior.Implements Backoff 15622ms
Retry Behavior.Retries On 500 5213ms
Retry Behavior.Retries On 502 5211ms
Retry Behavior.Retries On 504 5212ms
Retry Behavior.Max Retries Respected 15623ms
Deduplication.Generates Unique Uuids 111ms
Deduplication.Preserves Uuid On Retry 5212ms
Deduplication.Preserves Uuid And Timestamp On Retry 10318ms
Deduplication.Preserves Uuid And Timestamp On Batch Retry 5214ms
Deduplication.No Duplicate Events In Batch 111ms
Deduplication.Different Events Have Different Uuids 107ms
Compression.Sends Gzip When Enabled 105ms
Batch Format.Uses Proper Batch Structure 106ms
Batch Format.Flush With No Events Sends Nothing 4ms
Batch Format.Multiple Events Batched Together 110ms
Error Handling.Does Not Retry On 403 2107ms
Error Handling.Does Not Retry On 413 2109ms
Error Handling.Retries On 408 5211ms

Feature_Flags Tests

17/17 tests passed

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

@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

@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! Every read is nil-safe (&. chains / short-circuits), the internal flagDetails key is stripped before the public return, and true/false/absent are covered on the metadata, single-flag local/remote, and snapshot paths.

@haacked
haacked merged commit 15fa092 into main Jul 15, 2026
20 checks passed
@haacked
haacked deleted the haacked/feature-flag-has-experiment branch July 15, 2026 23:38
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