feat(flags): accept a caller default in FeatureFlagEvaluations#enabled? - #285
Draft
posthog[bot] wants to merge 1 commit into
Draft
posthog[bot] wants to merge 1 commit into
posthog[bot] wants to merge 1 commit into
Conversation
The is-feature-enabled contract requires the SDK to accept a caller-supplied boolean default and return it whenever the flag has no value. `enabled?` collapsed every miss to a hardcoded `false`, leaving callers no way to make an unknown flag resolve to `true`. Add an optional `default_value:` keyword, returned only when the key is absent from the snapshot. A flag that has a value, including `false` and variant strings, still wins. Omitting the keyword keeps today's `false` result. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Generated-By: PostHog Desktop Task-Id: 2fdafc3d-62a5-4644-b74a-650fbca5dc05
posthog-ruby-sync Compliance ReportDate: 2026-09-30T06:08:10.197599+00:00
|
| Test | Status | Duration |
|---|---|---|
| Format Validation.Event Has Required Fields | ✅ | 10ms |
| Format Validation.Event Has Uuid | ✅ | 7ms |
| Format Validation.Event Has Lib Properties | ✅ | 7ms |
| Format Validation.Distinct Id Is String | ✅ | 10ms |
| Format Validation.Token Is Present | ✅ | 8ms |
| Format Validation.Custom Properties Preserved | ✅ | 7ms |
| Format Validation.Event Has Timestamp | ✅ | 7ms |
| Format Validation.Non Utc Event Timestamp Is Converted To Utc | ✅ | 8ms |
| Retry Behavior.Retries On 503 | ✅ | 5273ms |
| Retry Behavior.Does Not Retry On 400 | ✅ | 2010ms |
| Retry Behavior.Does Not Retry On 401 | ✅ | 2012ms |
| Retry Behavior.Respects Retry After Header | ✅ | 8014ms |
| Retry Behavior.Implements Backoff | ✅ | 15365ms |
| Retry Behavior.Retries On 500 | ✅ | 5115ms |
| Retry Behavior.Retries On 502 | ✅ | 5116ms |
| Retry Behavior.Retries On 504 | ✅ | 5163ms |
| Retry Behavior.Max Retries Respected | ✅ | 15526ms |
| Deduplication.Generates Unique Uuids | ✅ | 22ms |
| Deduplication.Preserves Uuid On Retry | ✅ | 5162ms |
| Deduplication.Preserves Uuid And Timestamp On Retry | ✅ | 10371ms |
| Deduplication.Preserves Uuid And Timestamp On Batch Retry | ✅ | 5163ms |
| Deduplication.No Duplicate Events In Batch | ✅ | 19ms |
| Deduplication.Different Events Have Different Uuids | ✅ | 9ms |
| Compression.Sends Gzip When Enabled | ✅ | 6ms |
| Batch Format.Uses Proper Batch Structure | ✅ | 7ms |
| Batch Format.Flush With No Events Sends Nothing | ✅ | 3ms |
| Batch Format.Multiple Events Batched Together | ❌ | 18ms |
| Error Handling.Does Not Retry On 403 | ✅ | 2009ms |
| Error Handling.Does Not Retry On 413 | ✅ | 2008ms |
| Error Handling.Retries On 408 | ✅ | 5156ms |
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 | ✅ | 9ms |
| Request Payload.Flags Request Uses V2 Query Param | ✅ | 7ms |
| Request Payload.Flags Request Hits Flags Path Not Decide | ✅ | 7ms |
| Request Payload.Flags Request Omits Authorization Header | ✅ | 8ms |
| Request Payload.Token In Flags Body Matches Init | ✅ | 9ms |
| Request Payload.Groups Round Trip | ✅ | 8ms |
| Request Payload.Groups Default To Empty Object | ✅ | 7ms |
| Request Payload.Disable Geoip False Propagates As Geoip Disable False | ✅ | 7ms |
| Request Payload.Disable Geoip Omitted Defaults To False | ❌ | 6ms |
| Request Payload.Flag Keys To Evaluate Contains Only Requested Key | ✅ | 7ms |
| Request Lifecycle.No Flags Request On Init Alone | ✅ | 3ms |
| Request Lifecycle.No Flags Request On Normal Capture | ✅ | 6ms |
| Request Lifecycle.Two Flag Calls Produce Two Remote Requests | ✅ | 9ms |
| Request Lifecycle.Mock Response Value Is Returned To Caller | ✅ | 6ms |
| Retry Behavior.Retries Flags On 502 | ✅ | 109ms |
| Retry Behavior.Retries Flags On 504 | ✅ | 157ms |
| Side Effect Events.Get Feature Flag Captures Feature Flag Called Event | ✅ | 8ms |
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-async Compliance ReportDate: 2026-09-30T06:08:20.856153+00:00
|
| Test | Status | Duration |
|---|---|---|
| Format Validation.Event Has Required Fields | ✅ | 109ms |
| Format Validation.Event Has Uuid | ✅ | 105ms |
| Format Validation.Event Has Lib Properties | ✅ | 108ms |
| Format Validation.Distinct Id Is String | ✅ | 105ms |
| 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 | ✅ | 5310ms |
| Retry Behavior.Does Not Retry On 400 | ✅ | 2109ms |
| Retry Behavior.Does Not Retry On 401 | ✅ | 2108ms |
| Retry Behavior.Respects Retry After Header | ✅ | 8115ms |
| Retry Behavior.Implements Backoff | ✅ | 15723ms |
| Retry Behavior.Retries On 500 | ✅ | 5212ms |
| Retry Behavior.Retries On 502 | ✅ | 5211ms |
| Retry Behavior.Retries On 504 | ✅ | 5212ms |
| Retry Behavior.Max Retries Respected | ✅ | 15713ms |
| Deduplication.Generates Unique Uuids | ✅ | 112ms |
| Deduplication.Preserves Uuid On Retry | ✅ | 5212ms |
| Deduplication.Preserves Uuid And Timestamp On Retry | ✅ | 10313ms |
| 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 | ✅ | 2109ms |
| Error Handling.Does Not Retry On 413 | ✅ | 2107ms |
| Error Handling.Retries On 408 | ✅ | 5212ms |
Feature_Flags Tests
View Details
| Test | Status | Duration |
|---|---|---|
| Request Payload.Request With Person Properties Device Id | ✅ | 108ms |
| Request Payload.Flags Request Uses V2 Query Param | ✅ | 107ms |
| Request Payload.Flags Request Hits Flags Path Not Decide | ✅ | 109ms |
| Request Payload.Flags Request Omits Authorization Header | ✅ | 109ms |
| Request Payload.Token In Flags Body Matches Init | ✅ | 107ms |
| Request Payload.Groups Round Trip | ✅ | 108ms |
| 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 | ❌ | 107ms |
| Request Payload.Flag Keys To Evaluate Contains Only Requested Key | ✅ | 108ms |
| 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 | ✅ | 112ms |
| Request Lifecycle.Mock Response Value Is Returned To Caller | ✅ | 106ms |
| Retry Behavior.Retries Flags On 502 | ✅ | 210ms |
| Retry Behavior.Retries Flags On 504 | ✅ | 210ms |
| Side Effect Events.Get Feature Flag Captures Feature Flag Called Event | ✅ | 109ms |
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']
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
💡 Motivation and Context
The cross-SDK
is-feature-enabledspec states a hard requirement with no server-SDK carve-out:The compliance matrix records this as a ❌ Fail for posthog-ruby:
Today a caller cannot tell "the flag is off" apart from "we never got an answer", and cannot choose to fail open when flag data is unavailable (empty snapshot, failed
/flagsrequest, quota-limited response).Explanation of the change
PostHog::FeatureFlagEvaluations#enabled?gains an optionaldefault_value:keyword:The default is returned only when the key is absent from the snapshot. Any flag that has a value —
true,false, or a variant string — still wins over it, andnil(the parameter's own default) preserves the historicalfalseresult for a missing flag.$feature_flag_calledreporting is deliberately untouched: the event still carries the real evaluated response (nilplus$feature_flag_error: flag_missingfor a miss), not the caller's default, so exposure data keeps reflecting what the server actually said.Scope is limited to this one contract. The deprecated
Client#is_feature_enabledhas the same gap but is not changed here — it already warns callers to move toevaluate_flags(...).enabled?, which is now the compliant surface. The matrix's other open gaps for this SDK are left alone.Why this is backwards-compatible
Purely additive.
default_value:defaults tonil, and the miss path is only diverted when a caller explicitly passes a non-nil value, so every existing call site behaves exactly as before.public_api_snapshot.txtis regenerated to record the new optional keyword.💚 How did you test it?
Four new specs in
spec/posthog/feature_flag_evaluations_spec.rb, mapping onto the spec's acceptance scenarios (acceptance/public/is-feature-enabled.feature):trueandfalse)falsewhen no default is given$feature_flag_calledstill reports the evaluated response andflag_missing, not the defaultLocally, on Ruby 3.2:
bundle exec rspec— 1252 examples, 0 failures (2 pending, the OTel-gemfile integration tests)bundle exec rubocop— 129 files, no offensesbundle exec rake public_api:check— clean after regenerating the snapshotFollow-up work
evaluate_flagscould mention the new keyword.📝 Checklist
If releasing new changes
pnpm changesetto generate a changeset file🤖 Agent context
Autonomy: Fully autonomous
Opened by the scheduled SDK-compliance agent, which reads the compliance matrices in
PostHog/sdk-specsand implements one open, backwards-compatible gap per run. This gap was picked over the alternatives because it is a hardSHALLwith a one-method, additive remediation on a non-deprecated surface, and because no existing PR or branch in this repo touched it.Deliberate decisions: only the canonical
evaluate_flags(...).enabled?path was changed (the legacyis_feature_enabledis deprecated, so extending it would add API surface we are steering callers away from);$feature_flag_calledproperties were left reporting the true evaluated response rather than the substituted default, so the default cannot distort exposure analytics.No manual/end-to-end testing beyond the automated checks listed above.
Created with PostHog Desktop
🤖 Generated with Claude Code