Skip to content

feat(flags): accept a caller default in FeatureFlagEvaluations.IsEnabled - #349

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

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

Conversation

@posthog

@posthog posthog Bot commented Oct 2, 2026

Copy link
Copy Markdown
Contributor

💡 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-go:

The canonical path, FeatureFlagEvaluations.IsEnabled(key string) bool, takes only a key argument and hardcodes return false for an unknown flag — no default-value parameter. Both collapse "known false" and "unknown/missing" to the identical false result with no caller-supplied override.

Remediation: Add an equivalent optional default parameter to FeatureFlagEvaluations.IsEnabled.

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

FeatureFlagEvaluations.IsEnabled gains an optional variadic defaultValue, Go's idiomatic spelling of an optional parameter:

flags, _ := client.EvaluateFlags(posthog.EvaluateFlagsPayload{DistinctId: "user-1"})
if flags.IsEnabled("new-checkout", true) { // fail open when we have no answer
    // ...
}

The default is returned only when the key is absent from the snapshot, or when the snapshot pointer itself is nil (the IsEnabled receiver is already nil-safe, which is how "flags were never loaded" surfaces in Go). Any flag that has a value — true, false, or a variant string — still wins over it, and omitting the argument preserves the historical false result for an unknown 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.IsFeatureEnabled/Client.GetFeatureFlag legacy path has the same gap and is not changed here — both already point callers at EvaluateFlags, 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. A variadic parameter keeps every existing IsEnabled(key) call site compiling and behaving identically, and the miss path is only diverted when a caller explicitly passes a value. api/public-api.txt is regenerated to record the new optional argument. The one source-level caveat worth noting: a method value previously typed func(string) bool is now func(string, ...bool) bool, which is vanishingly rare in practice but is why this ships as a minor, not a patch.

💚 How did you test it?

Four new tests in feature_flag_evaluations_test.go, mapping onto the spec's acceptance scenarios (acceptance/public/is-feature-enabled.feature):

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

Locally, on Go 1.23:

  • go vet ./... — clean
  • gofmt -l . — clean
  • go test -race -count=1 ./... — all packages pass
  • make api-update — snapshot regenerated, so make api-diff is clean

No manual testing against a live project.

Follow-up work

  • The same default-value gap is recorded for posthog-node, posthog-php and posthog-dotnet; posthog-ruby has PR #285 open for its equivalent.
  • The spec's own "Surface variants" table has no Go row, and the SDK compliance adapter (sdk_compliance_adapter) exposes no is_feature_enabled route, so the harness cannot exercise these scenarios end-to-end yet.
  • The legacy FeatureFlagPayload path could gain a DefaultValue *bool field for parity, if maintainers want the deprecated surface brought along too.

📝 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 a scheduled PostHog agent run that reads the PostHog/sdk-specs compliance matrices and implements one safe, well-scoped gap per run. This gap was picked over the other open ❌ rows because it is a core, user-facing flag contract, the remediation is concrete, the backwards-compatibility verdict is additive, and no PR was already open for it in this repo.

Decisions along the way: a variadic defaultValue was chosen over a separate IsEnabledWithDefault method (one way to do a thing, and the spec asks for "parameter placement per platform idiom") and over touching the deprecated FeatureFlagPayload path (out of scope for a single-contract change). The nil-receiver case was included because Go's nil-safe snapshot is how the spec's "flags not loaded yet / failed flags request" states actually reach IsEnabled.

Per AGENTS.md, the published sdk-spec is the public-API agreement, so no separate issue was opened.


Created with PostHog Desktop

🤖 Generated with Claude Code

The cross-SDK is-feature-enabled spec requires the boolean check to accept a
caller-supplied default and return it whenever the flag has no value. IsEnabled
hardcoded false for an unknown flag, so callers could not tell "the flag is off"
from "we never got an answer", nor choose to fail open.

IsEnabled now takes an optional variadic defaultValue, used only when the key is
absent from the snapshot or the snapshot itself is nil. A flag with a value,
including false and variant strings, still wins. $feature_flag_called keeps
reporting the evaluated response and flag_missing, not the caller's default.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

Generated-By: PostHog Desktop
Task-Id: 009e935f-fc26-4bc4-b2e4-c362ddb2de44
@github-actions

github-actions Bot commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

posthog-go Compliance Report

Date: 2026-10-02 06:10:43 UTC
Duration: 168946ms

✅ All Tests Passed!

111/111 tests passed


Capture_V1 Tests

✅ 94/94 tests passed

View Details
Test Status Duration
Endpoint And Method.Targets V1 Endpoint ✅ 16ms
Endpoint And Method.Does Not Use Legacy Endpoints ✅ 5ms
Required Headers.Has Authorization Bearer Header ✅ 6ms
Required Headers.Has Content Type Json ✅ 4ms
Required Headers.Has Posthog Sdk Info Format ✅ 5ms
Required Headers.Has Posthog Attempt Header ✅ 4ms
Required Headers.Has Posthog Request Id ✅ 5ms
Required Headers.Has Posthog Request Timestamp ✅ 4ms
Required Headers.Has User Agent ✅ 5ms
Body Format.Body Has Created At And Batch ✅ 4ms
Body Format.No Api Key In Body ✅ 5ms
Body Format.No Sent At In Body ✅ 5ms
Event Format.Event Has Required Root Fields ✅ 4ms
Event Format.Event Uuid Is Valid ✅ 5ms
Event Format.Event Timestamp Is Rfc3339 ✅ 4ms
Event Format.Distinct Id Is String ✅ 5ms
Event Format.Distinct Id At Root Not Properties ✅ 4ms
Event Format.Custom Properties Preserved ✅ 5ms
Event Format.Set Properties Preserved ✅ 4ms
Event Format.Set Once Properties Preserved ✅ 5ms
Event Format.Groups Properties Preserved ✅ 5ms
Event Format.Sdk Generates Uuid If Not Provided ✅ 4ms
Event Format.Event Has Required Root Fields Batch ✅ 16ms
Event Format.Event Uuid Is Valid Batch ✅ 7ms
Event Format.Event Timestamp Is Rfc3339 Batch ✅ 7ms
Event Format.Distinct Id Is String Batch ✅ 6ms
Event Format.Distinct Id At Root Not Properties Batch ✅ 6ms
Event Format.Custom Properties Preserved Batch ✅ 7ms
Event Format.Set Properties Preserved Batch ✅ 6ms
Event Format.Set Once Properties Preserved Batch ✅ 7ms
Event Format.Groups Properties Preserved Batch ✅ 6ms
Event Format.Sdk Generates Uuid If Not Provided Batch ✅ 6ms
Batch Behavior.Multiple Events In Single Batch ✅ 28ms
Batch Behavior.Batch Envelope Smoke ✅ 8ms
Batch Behavior.Flush With No Events Sends Nothing ✅ 3ms
Batch Behavior.Flush At Triggers Batch ✅ 1006ms
Batch Behavior.Created At Reflects Batch Creation Time ✅ 5ms
Deduplication.Generates Unique Uuids ✅ 11ms
Deduplication.Different Events Same Content Different Uuids ✅ 6ms
Deduplication.Preserves Uuid On Retry ✅ 5132ms
Deduplication.Preserves Timestamp On Retry ✅ 5133ms
Deduplication.Preserves Uuid And Timestamp On Batch Retry ✅ 5135ms
Deduplication.No Duplicate Events In Batch ✅ 29ms
Header Behavior On Retry.Attempt Header Starts At One ✅ 15ms
Header Behavior On Retry.Attempt Header Increments On Retry ✅ 10140ms
Header Behavior On Retry.Request Id Preserved On Retry ✅ 5134ms
Header Behavior On Retry.Different Requests Have Different Request Ids ✅ 2011ms
Header Behavior On Retry.Request Timestamp Changes On Retry ✅ 5135ms
Response Format Validation.Success Response Has Uuid Keyed Results ✅ 6ms
Response Format Validation.Success Response Has Ok For Each Event ✅ 26ms
Response Format Validation.Success No Retry After When All Ok ✅ 26ms
Response Format Validation.Success Retry After Present When Retry Events ✅ 128ms
Response Format Validation.Success No Retry After When Drop Only ✅ 26ms
Response Format Validation.Response Echoes Request Id ✅ 5ms
Retry Behavior.Retries On 408 ✅ 5133ms
Retry Behavior.Retries On 500 ✅ 5133ms
Retry Behavior.Retries On 503 ✅ 5135ms
Retry Behavior.Retries On 504 ✅ 5134ms
Retry Behavior.Retryable Errors Have Retry After ✅ 2131ms
Retry Behavior.Respects Retry After On Retryable Error ✅ 8131ms
Retry Behavior.Does Not Retry On 400 ✅ 2131ms
Retry Behavior.Does Not Retry On 401 ✅ 2131ms
Retry Behavior.Does Not Retry On 402 ✅ 2132ms
Retry Behavior.Does Not Retry On 413 ✅ 2132ms
Retry Behavior.Does Not Retry On 415 ✅ 2131ms
Retry Behavior.Non Retryable Errors Have No Retry After ✅ 2132ms
Retry Behavior.Implements Backoff ✅ 15133ms
Retry Behavior.Max Retries Respected ✅ 15142ms
Partial Batch Handling.Handles 200 Full Success ✅ 2008ms
Partial Batch Handling.Handles 200 With All Ok ✅ 3028ms
Partial Batch Handling.Does Not Retry Dropped Events ✅ 3027ms
Partial Batch Handling.Does Not Retry Limited Events ✅ 3030ms
Partial Batch Handling.Prunes Ok Events On Partial Retry ✅ 5133ms
Partial Batch Handling.Prunes Dropped Events On Partial Retry ✅ 5134ms
Partial Batch Handling.Retries Only Retry Events From Partial ✅ 5134ms
Partial Batch Handling.Partial Retry Preserves Uuids ✅ 5133ms
Partial Batch Handling.Partial Retry Attempt Header Increments ✅ 5133ms
Partial Batch Handling.Partial Retry Request Id Preserved ✅ 5133ms
Partial Batch Handling.Respects Retry After On Partial ✅ 5136ms
Partial Batch Handling.Unknown Result Treated As Terminal ✅ 3029ms
Partial Batch Handling.Mixed Ok Drop Limited No Retry ✅ 3033ms
Compression.Sends Gzip Content Encoding ✅ 15ms
Compression.No Content Encoding When Disabled ✅ 5ms
Compression.Compressed Body Is Decompressible ✅ 15ms
Error Handling.Does Not Retry On Unknown 4Xx ✅ 2130ms
Event Options.Cookieless Mode Override ✅ 6ms
Event Options.Disable Skew Correction Override ✅ 4ms
Event Options.Process Person Profile Override ✅ 5ms
Event Options.Product Tour Id Override ✅ 4ms
Event Options.Unset Options Omitted ✅ 5ms
Event Options.Options Override In Batch ✅ 7ms
Geoip And Historical Migration.Geoip Disable Injected Into Properties ✅ 4ms
Geoip And Historical Migration.Historical Migration Set In Body ✅ 4ms
Geoip And Historical Migration.Historical Migration Absent By Default ✅ 5ms

Feature_Flags Tests

✅ 17/17 tests passed

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

@marandaneto
marandaneto requested a review from a team October 6, 2026 07:18

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

Status: In Progress

Development

Successfully merging this pull request may close these issues.

0 participants