Skip to content

feat(flags): accept a caller default in FeatureFlagEvaluations#enabled? - #285

Draft
posthog[bot] wants to merge 1 commit into
mainfrom
posthog/flag-evaluations-enabled-default-value
Draft

posthog[bot] wants to merge 1 commit into
mainfrom
posthog/flag-evaluations-enabled-default-value

Conversation

@posthog

@posthog posthog Bot commented Sep 30, 2026

Copy link
Copy Markdown

💡 Motivation and Context

The cross-SDK is-feature-enabled spec states a hard requirement with no server-SDK carve-out:

The SDK SHALL accept a caller-supplied boolean default (defaultValue; parameter placement per platform idiom) and SHALL return it whenever the flag has no value: flags not loaded yet, a failed flags request, or no flag with that key in the loaded flags. A flag that has a value — including false and variant strings — always wins over the caller-supplied default.

The compliance matrix records this as a ❌ Fail for posthog-ruby:

FeatureFlagEvaluations#enabled? has no default_value parameter: def enabled?(key) ... flag&.enabled ? true : false end — it collapses every miss to a hardcoded false rather than accepting a caller override.

Remediation: Add a default_value: keyword to FeatureFlagEvaluations#enabled?, distinguishing "no default supplied" (current false behavior) from an explicit caller-supplied default.

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 /flags request, quota-limited response).

Explanation of the change

PostHog::FeatureFlagEvaluations#enabled? gains an optional default_value: keyword:

flags = posthog.evaluate_flags(distinct_id)
flags.enabled?('new-checkout', default_value: true)

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, and nil (the parameter's own default) preserves the historical false result for a missing flag.

$feature_flag_called reporting is deliberately untouched: the event still carries the real evaluated response (nil plus $feature_flag_error: flag_missing for 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_enabled has the same gap but is not changed here — it already warns callers to move to evaluate_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 to nil, 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.txt is 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):

  • a missing flag resolves to the caller default (true and false)
  • an existing value wins over the default (disabled flag, variant flag, boolean flag)
  • an empty snapshot uses the default, and still returns false when no default is given
  • $feature_flag_called still reports the evaluated response and flag_missing, not the default

Locally, on Ruby 3.2:

  • bundle exec rspec — 1252 examples, 0 failures (2 pending, the OTel-gemfile integration tests)
  • bundle exec rubocop — 129 files, no offenses
  • bundle exec rake public_api:check — clean after regenerating the snapshot

Follow-up work

  • The same default-value gap is recorded for posthog-node, posthog-php, posthog-go and posthog-dotnet; posthog-java is the existing reference implementation.
  • The spec's own "Surface variants" table shows a stale Ruby signature without a default parameter, and the docs for evaluate_flags could mention the new keyword.

📝 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

🤖 Agent context

Autonomy: Fully autonomous

Opened by the scheduled SDK-compliance agent, which reads the compliance matrices in PostHog/sdk-specs and implements one open, backwards-compatible gap per run. This gap was picked over the alternatives because it is a hard SHALL with 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 legacy is_feature_enabled is deprecated, so extending it would add API surface we are steering callers away from); $feature_flag_called properties 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

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
@github-actions

Copy link
Copy Markdown

posthog-ruby-sync Compliance Report

Date: 2026-09-30T06:08:10.197599+00:00
Duration: 94306ms

⚠️ Some Tests Failed

45/47 tests passed, 2 failed


Capture Tests

⚠️ 29/30 tests passed, 1 failed

View Details
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

⚠️ 16/17 tests passed, 1 failed

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']

@github-actions

Copy link
Copy Markdown

posthog-ruby-async Compliance Report

Date: 2026-09-30T06:08:20.856153+00:00
Duration: 98535ms

⚠️ Some Tests Failed

46/47 tests passed, 1 failed


Capture Tests

✅ 30/30 tests passed

View Details
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

⚠️ 16/17 tests passed, 1 failed

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

No deployments
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.

0 participants