Repository navigation
feat(flags): honor experiment holdouts in local flag evaluation - #301
Conversation
A flag definition carrying `filters.holdout` was evaluated locally as though the holdout did not exist, so every identity inside the holdout got a variant that disagreed with the server. Check the holdout before release conditions, using the flag-level bucketing identity, and resolve a held-out identifier to the synthetic `holdout-<id>` variant. Membership hashes `holdout-<bucketing value>` rather than reusing the dot-separated flag hash, which selects a different population. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Generated-By: PostHog Desktop Task-Id: 4c71ea2a-1fb6-45d3-ace5-a6acc28b9676
posthog-ruby-async Compliance ReportDate: 2026-10-12T06:09:17.483614+00:00
|
| Test | Status | Duration |
|---|---|---|
| Format Validation.Event Has Required Fields | ✅ | 108ms |
| Format Validation.Event Has Uuid | ✅ | 106ms |
| Format Validation.Event Has Lib Properties | ✅ | 108ms |
| Format Validation.Distinct Id Is String | ✅ | 106ms |
| Format Validation.Token Is Present | ✅ | 107ms |
| Format Validation.Custom Properties Preserved | ✅ | 106ms |
| Format Validation.Event Has Timestamp | ✅ | 106ms |
| Format Validation.Non Utc Event Timestamp Is Converted To Utc | ✅ | 9ms |
| Retry Behavior.Retries On 503 | ✅ | 5311ms |
| 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 | ✅ | 15522ms |
| Retry Behavior.Retries On 500 | ✅ | 5212ms |
| Retry Behavior.Retries On 502 | ✅ | 5212ms |
| Retry Behavior.Retries On 504 | ✅ | 5212ms |
| Retry Behavior.Max Retries Respected | ✅ | 15722ms |
| Deduplication.Generates Unique Uuids | ✅ | 111ms |
| Deduplication.Preserves Uuid On Retry | ✅ | 5211ms |
| Deduplication.Preserves Uuid And Timestamp On Retry | ✅ | 10317ms |
| Deduplication.Preserves Uuid And Timestamp On Batch Retry | ✅ | 5214ms |
| Deduplication.No Duplicate Events In Batch | ✅ | 112ms |
| Deduplication.Different Events Have Different Uuids | ✅ | 108ms |
| Compression.Sends Gzip When Enabled | ✅ | 106ms |
| Batch Format.Uses Proper Batch Structure | ✅ | 106ms |
| Batch Format.Flush With No Events Sends Nothing | ✅ | 5ms |
| Batch Format.Multiple Events Batched Together | ✅ | 110ms |
| Error Handling.Does Not Retry On 403 | ✅ | 2108ms |
| Error Handling.Does Not Retry On 413 | ✅ | 2108ms |
| Error Handling.Retries On 408 | ✅ | 5212ms |
Feature_Flags Tests
View Details
| Test | Status | Duration |
|---|---|---|
| Request Payload.Request With Person Properties Device Id | ✅ | 107ms |
| Request Payload.Flags Request Uses V2 Query Param | ✅ | 106ms |
| Request Payload.Flags Request Hits Flags Path Not Decide | ✅ | 106ms |
| 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 | ✅ | 106ms |
| Request Payload.Disable Geoip Omitted Defaults To False | ❌ | 106ms |
| Request Payload.Flag Keys To Evaluate Contains Only Requested Key | ✅ | 107ms |
| Request Lifecycle.No Flags Request On Init Alone | ✅ | 3ms |
| Request Lifecycle.No Flags Request On Normal Capture | ✅ | 105ms |
| Request Lifecycle.Two Flag Calls Produce Two Remote Requests | ✅ | 111ms |
| Request Lifecycle.Mock Response Value Is Returned To Caller | ✅ | 106ms |
| Retry Behavior.Retries Flags On 502 | ✅ | 248ms |
| Retry Behavior.Retries Flags On 504 | ✅ | 209ms |
| Side Effect Events.Get Feature Flag Captures Feature Flag Called Event | ✅ | 108ms |
Failures
request_payload.disable_geoip_omitted_defaults_to_false
Field 'geoip_disable' not found in /flags request body at path 'geoip_disable'. Available keys: ['distinct_id', 'groups', 'person_properties', 'group_properties', 'flag_keys_to_evaluate', 'token']
posthog-ruby-sync Compliance ReportDate: 2026-10-12T06:09:30.363740+00:00
|
| Test | Status | Duration |
|---|---|---|
| Format Validation.Event Has Required Fields | ✅ | 7ms |
| Format Validation.Event Has Uuid | ✅ | 4ms |
| Format Validation.Event Has Lib Properties | ✅ | 4ms |
| Format Validation.Distinct Id Is String | ✅ | 7ms |
| Format Validation.Token Is Present | ✅ | 5ms |
| Format Validation.Custom Properties Preserved | ✅ | 5ms |
| Format Validation.Event Has Timestamp | ✅ | 6ms |
| Format Validation.Non Utc Event Timestamp Is Converted To Utc | ✅ | 5ms |
| Retry Behavior.Retries On 503 | ✅ | 5224ms |
| Retry Behavior.Does Not Retry On 400 | ✅ | 2009ms |
| Retry Behavior.Does Not Retry On 401 | ✅ | 2008ms |
| Retry Behavior.Respects Retry After Header | ✅ | 8010ms |
| Retry Behavior.Implements Backoff | ✅ | 15364ms |
| Retry Behavior.Retries On 500 | ✅ | 5114ms |
| Retry Behavior.Retries On 502 | ✅ | 5146ms |
| Retry Behavior.Retries On 504 | ✅ | 5114ms |
| Retry Behavior.Max Retries Respected | ✅ | 15457ms |
| Deduplication.Generates Unique Uuids | ✅ | 18ms |
| Deduplication.Preserves Uuid On Retry | ✅ | 5159ms |
| Deduplication.Preserves Uuid And Timestamp On Retry | ✅ | 10255ms |
| Deduplication.Preserves Uuid And Timestamp On Batch Retry | ✅ | 5153ms |
| Deduplication.No Duplicate Events In Batch | ✅ | 13ms |
| Deduplication.Different Events Have Different Uuids | ✅ | 6ms |
| Compression.Sends Gzip When Enabled | ✅ | 6ms |
| Batch Format.Uses Proper Batch Structure | ✅ | 4ms |
| Batch Format.Flush With No Events Sends Nothing | ✅ | 2ms |
| Batch Format.Multiple Events Batched Together | ❌ | 12ms |
| Error Handling.Does Not Retry On 403 | ✅ | 2006ms |
| Error Handling.Does Not Retry On 413 | ✅ | 2009ms |
| Error Handling.Retries On 408 | ✅ | 5139ms |
Failures
batch_format.multiple_events_batched_together
Expected 1 requests, got 5
Feature_Flags Tests
View Details
| Test | Status | Duration |
|---|---|---|
| Request Payload.Request With Person Properties Device Id | ✅ | 8ms |
| Request Payload.Flags Request Uses V2 Query Param | ✅ | 7ms |
| Request Payload.Flags Request Hits Flags Path Not Decide | ✅ | 6ms |
| Request Payload.Flags Request Omits Authorization Header | ✅ | 5ms |
| Request Payload.Token In Flags Body Matches Init | ✅ | 4ms |
| Request Payload.Groups Round Trip | ✅ | 5ms |
| Request Payload.Groups Default To Empty Object | ✅ | 4ms |
| Request Payload.Disable Geoip False Propagates As Geoip Disable False | ✅ | 5ms |
| Request Payload.Disable Geoip Omitted Defaults To False | ❌ | 4ms |
| Request Payload.Flag Keys To Evaluate Contains Only Requested Key | ✅ | 5ms |
| Request Lifecycle.No Flags Request On Init Alone | ✅ | 1ms |
| Request Lifecycle.No Flags Request On Normal Capture | ✅ | 5ms |
| Request Lifecycle.Two Flag Calls Produce Two Remote Requests | ✅ | 7ms |
| Request Lifecycle.Mock Response Value Is Returned To Caller | ✅ | 5ms |
| Retry Behavior.Retries Flags On 502 | ✅ | 107ms |
| Retry Behavior.Retries Flags On 504 | ✅ | 155ms |
| Side Effect Events.Get Feature Flag Captures Feature Flag Called Event | ✅ | 5ms |
Failures
request_payload.disable_geoip_omitted_defaults_to_false
Field 'geoip_disable' not found in /flags request body at path 'geoip_disable'. Available keys: ['distinct_id', 'groups', 'person_properties', 'group_properties', 'flag_keys_to_evaluate', 'token']
ioannisj
left a comment
There was a problem hiding this comment.
🤖 An AI agent wrote this on behalf of @ioannisj.
This matches the flags service and posthog-node. The hash input is the same (holdout-<value>, no salt), the check is inclusive, the percentage is clamped to 0-100 and 100 skips the hash, and the gate runs after the inactive check and before release conditions. That means single, bulk and dependency evaluation all go through it. Nothing to fix here.
Two older issues are worth tracking separately. Both predate this PR and also affect rollout hashing:
- a dependency flag is bucketed by the parent's identity even when its aggregation differs
- the group-key rendering requirement from sdk-specs#89 isn't in Ruby yet
💡 Motivation and Context
Why: The cross-SDK compliance matrix in PostHog/sdk-specs marks this SDK's Local Feature Flag Evaluator row 🟡 Partial, with experiment holdouts as the only open gap —
grep -rn 'holdout' lib/returned zero matches. A flag configured with an experiment holdout was evaluated locally as if the holdout did not exist, so every identity inside the holdout silently got an answer that disagreed with the backend. That is a correctness divergence between local and remote evaluation, not a missing convenience.Contract:
Local Feature Flag Evaluator— Experiment holdouts precede release conditions and its companion requirement Holdout membership uses backend-compatible bucketing.Matrix note (
compliance/posthog-ruby.md, n15):What changed
match_feature_flag_propertiesconsultsfilters.holdoutbefore iterating release conditions. A held-out identifier resolves to the synthetic variantholdout-<id>, which does not need to appear infilters.multivariate.variants. The inactive-flag check still runs first, so an inactive flag staysfalse.holdout_variant_forskips a holdout whoseidorexclusion_percentageis missing or null, leaving ordinary evaluation unchanged. The percentage is clamped to 0–100 without truncating fractions, compared inclusively, and100holds everyone out without computing a hash._holdout_hashhashesholdout-<bucketing value>— no flag key, holdout id or salt. The existing dot-separated_hashselects a different population and is deliberately not reused.The same gap is being closed in posthog-go#360 and posthog-php#254; this change keeps Ruby's semantics and hash vectors aligned with those.
Backwards compatibility
Backwards-compatible. No public API changes —
bundle exec rake public_api:checkreports no snapshot diff, and both new methods are internal toFeatureFlagsPoller. Definitions already round-tripfilters.holdoutuntouched because the loader stores wholefiltershashes, so no loader or cache change was needed. Evaluated values change only for flags that actually carry a holdout, where today's local answer is wrong and the new one matches the server. Flags without a holdout are byte-for-byte unaffected.💚 How did you test it?
New
spec/posthog/feature_flags_holdouts_spec.rb(16 examples) covering each scenario in the spec: the two server hash vectors (user-1→ ~0.178056,user-5→ ~0.656381), holdout precedence over an unmatchable property filter / 0% rollout / condition variant override, inactive flags stayingfalse, no-holdout and incomplete-holdout definitions assigning normally, inclusive and clamped percentage boundaries (12.5 / 12.4 / 0 / -10 / 100 / 150), the flag-level group key winning over the distinct id, and a bulk pass where a dependent flag compares againstholdout-727. Verified the suite fails (9 of 16) with the implementation reverted.Full CI-aligned checks run locally:
bundle exec rspec(1277 examples, 0 failures, 2 pending — the OTel-bundle integration tests),bundle exec rubocop(clean),bundle exec rake public_api:check(no diff).Follow-up
exclusion_percentageis present but non-numeric is skipped. The spec only defines missing/null; skipping is the conservative reading.📝 Checklist
If releasing new changes
pnpm changesetto generate a changeset file🤖 Agent context
Autonomy: Fully autonomous
Written by Claude Opus 5 running as an unattended PostHog workflow that reads the
compliance/matrices inPostHog/sdk-specsand implements one open, backwards-compatible gap per run. This gap was chosen over the other open Ruby items because it is a silent correctness divergence on a widely-used surface, it is additive, and it is the only one of the three server SDKs sharing it without a PR already in flight.Two implementation decisions worth a reviewer's attention: the holdout gate sits at the top of
match_feature_flag_propertiesrather than in_compute_flag_locally, so it runs after the inactive-flag check and uses the bucketing identity the caller already resolved for both the person and group paths; and_holdout_hashis a separate function rather than a parameter on_hash, because the separator and the absence of a salt are what select the holdout population and inlining them into the flag hash would make that easy to lose.Created with PostHog Desktop
🤖 Generated with Claude Code