Skip to content

fix(flags): read an empty variant as disabled in getFeatureFlagResult and onFeatureFlags - #949

Merged
turnipdabeets merged 5 commits into
chore/v4-remove-deprecatedfrom
fix/v4-empty-variant-disabled
Nov 9, 2026
Merged

turnipdabeets merged 5 commits into
chore/v4-remove-deprecatedfrom
fix/v4-empty-variant-disabled

Conversation

@turnipdabeets

@turnipdabeets turnipdabeets commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

💡 Motivation and Context

A flag whose variant is the empty string "" already reads as disabled from isFeatureEnabled() (since 3.x), but getFeatureFlagResult().enabled was true and PostHogFeatureFlagsLoaded listed the flag, so the same flag read as enabled and disabled depending on the call. posthog-ios had the same split after posthog-ios#1001 (review thread); posthog-js (browser) is already consistent. This makes "" read as disabled everywhere.

  • getFeatureFlagResult() and getAllFeatureFlags() return enabled = false, with variant still "".
  • PostHogFeatureFlagsLoaded leaves the flag out of flags and variants.
  • Captured events (PostHog and PostHogStateless, only when sendFeatureFlagEvent is on, as before) leave the flag out of $active_feature_flags; $feature/<key> still carries the raw "", as in posthog-js (browser). posthog-server builds these properties itself and already left "" out, so it's unchanged.
  • Unchanged: isFeatureEnabled() (already false, with or without defaultValue), getFeatureFlag() (still returns "", since FeatureFlagResult.value is variant ?: enabled), and $feature_flag_called (still reports $feature_flag_response: "").

Blast radius is small: since PostHog/posthog#118803 (2026-10-16) PostHog rejects new "" variant keys, so only flags created earlier through the API, MCP or Terraform can hit this.

Added a Breaking entry to the 4.0 changeset and an "Empty variants read as disabled" section to docs/migration-3.x-to-4.0.md.

Not changed here: posthog-server has the same split (PostHogFeatureFlags.getFeatureFlagResult returns enabled = true for "", while isFeatureEnabled returns false); it's left for a follow-up.

Sibling PRs:

💚 How did you test it?

  • Added PostHogFeatureFlagsTest "an empty variant reads as disabled": isFeatureEnabled with and without defaultValue, getFeatureFlagResult enabled/variant, and the reload callback's PostHogFeatureFlagsLoaded.flags. It fails on the pre-fix source (result.enabled) and passes with the fix.
  • Added PostHogTest "captured events leave a flag with an empty variant out of active_feature_flags" and an empty-variant flag in PostHogStatelessTest "captureStateless handles feature flags when enabled": both fail on the pre-fix source (the "" flag is listed) and pass with the fix.
  • ./gradlew spotlessCheck :posthog:test apiCheck --no-daemon --no-configuration-cache: 1251 tests, 0 failures; spotless and apiCheck pass.

📝 Checklist

  • All commits are signed (see Commit signing)
  • 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 (edited the existing 4.0 changeset)

🤖 Agent context

Autonomy: Human-driven (agent-assisted)

Claude Code made the change across iOS, Android, Flutter and sdk-specs at Anna's direction. The fix is one condition in the client result builder and one in PostHogFeatureFlagsLoaded.

🤖 Generated with Claude Code

@github-actions

github-actions Bot commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

posthog-android Compliance Report

Date: 2026-11-08T20:10:04.686966+00:00
Duration: 475256ms

✅ All Tests Passed!

232/232 tests passed


Capture_V1 Tests

✅ 105/105 tests passed

View Details
Test Status Duration
Endpoint And Method.Targets V1 Endpoint ✅ 305ms
Endpoint And Method.Does Not Use Legacy Endpoints ✅ 25ms
Required Headers.Has Authorization Bearer Header ✅ 23ms
Required Headers.Has Content Type Json ✅ 21ms
Required Headers.Has Posthog Sdk Info Format ✅ 21ms
Required Headers.Has Posthog Attempt Header ✅ 22ms
Required Headers.Has Posthog Request Id ✅ 21ms
Required Headers.Has Posthog Request Timestamp ✅ 20ms
Required Headers.Has User Agent ✅ 22ms
Body Format.Body Has Created At And Batch ✅ 21ms
Body Format.No Api Key In Body ✅ 22ms
Body Format.No Sent At In Body ✅ 22ms
Event Format.Event Has Required Root Fields ✅ 20ms
Event Format.Event Uuid Is Valid ✅ 18ms
Event Format.Event Timestamp Is Rfc3339 ✅ 18ms
Event Format.Non Utc Event Timestamp Is Converted To Utc ✅ 20ms
Event Format.Distinct Id Is String ✅ 21ms
Event Format.Distinct Id At Root Not Properties ✅ 18ms
Event Format.Custom Properties Preserved ✅ 20ms
Event Format.Set Properties Preserved ✅ 18ms
Event Format.Set Once Properties Preserved ✅ 17ms
Event Format.Groups Properties Preserved ✅ 17ms
Event Format.Sdk Generates Uuid If Not Provided ✅ 20ms
Event Format.Event Has Required Root Fields Batch ✅ 22ms
Event Format.Event Uuid Is Valid Batch ✅ 23ms
Event Format.Event Timestamp Is Rfc3339 Batch ✅ 20ms
Event Format.Distinct Id Is String Batch ✅ 21ms
Event Format.Distinct Id At Root Not Properties Batch ✅ 23ms
Event Format.Custom Properties Preserved Batch ✅ 20ms
Event Format.Set Properties Preserved Batch ✅ 22ms
Event Format.Set Once Properties Preserved Batch ✅ 22ms
Event Format.Groups Properties Preserved Batch ✅ 29ms
Event Format.Sdk Generates Uuid If Not Provided Batch ✅ 25ms
Batch Behavior.Multiple Events In Single Batch ✅ 23ms
Batch Behavior.Batch Envelope Smoke ✅ 25ms
Batch Behavior.Flush With No Events Sends Nothing ✅ 10ms
Batch Behavior.Flush At Triggers Batch ✅ 1024ms
Batch Behavior.Created At Reflects Batch Creation Time ✅ 15ms
Deduplication.Generates Unique Uuids ✅ 31ms
Deduplication.Different Events Same Content Different Uuids ✅ 18ms
Deduplication.Preserves Uuid On Retry ✅ 7014ms
Deduplication.Preserves Timestamp On Retry ✅ 7015ms
Deduplication.Preserves Uuid And Timestamp On Batch Retry ✅ 7020ms
Deduplication.No Duplicate Events In Batch ✅ 24ms
Header Behavior On Retry.Attempt Header Starts At One ✅ 11ms
Header Behavior On Retry.Attempt Header Increments On Retry ✅ 12018ms
Header Behavior On Retry.Request Id Preserved On Retry ✅ 7015ms
Header Behavior On Retry.Different Requests Have Different Request Ids ✅ 2022ms
Header Behavior On Retry.Request Timestamp Changes On Retry ✅ 7011ms
Response Format Validation.Success Response Has Uuid Keyed Results ✅ 15ms
Response Format Validation.Success Response Has Ok For Each Event ✅ 16ms
Response Format Validation.Success No Retry After When All Ok ✅ 17ms
Response Format Validation.Success Retry After Present When Retry Events ✅ 2008ms
Response Format Validation.Success No Retry After When Drop Only ✅ 15ms
Response Format Validation.Response Echoes Request Id ✅ 12ms
Retry Behavior.Retries On 408 ✅ 7013ms
Retry Behavior.Retries On 500 ✅ 7015ms
Retry Behavior.Retries On 503 ✅ 7021ms
Retry Behavior.Retries On 504 ✅ 7015ms
Retry Behavior.Retries On 404 ✅ 6010ms
Retry Behavior.Retries On 429 ✅ 7015ms
Retry Behavior.Retries On 502 ✅ 7015ms
Retry Behavior.Retryable Errors Have Retry After ✅ 4012ms
Retry Behavior.Respects Retry After On Retryable Error ✅ 10016ms
Retry Behavior.Does Not Retry On 400 ✅ 4017ms
Retry Behavior.Does Not Retry On 401 ✅ 4016ms
Retry Behavior.Does Not Retry On 402 ✅ 4016ms
Retry Behavior.Does Not Retry On 413 ✅ 4016ms
Retry Behavior.Does Not Retry On 415 ✅ 4020ms
Retry Behavior.Non Retryable Errors Have No Retry After ✅ 4015ms
Retry Behavior.Implements Backoff ✅ 14025ms
Partial Batch Handling.Handles 200 Full Success ✅ 2017ms
Partial Batch Handling.Handles 200 With All Ok ✅ 3020ms
Partial Batch Handling.Does Not Retry Dropped Events ✅ 3017ms
Partial Batch Handling.Does Not Retry Warning Events ✅ 3020ms
Partial Batch Handling.Prunes Ok Events On Partial Retry ✅ 7015ms
Partial Batch Handling.Prunes Dropped Events On Partial Retry ✅ 7012ms
Partial Batch Handling.Retries Only Retry Events From Partial ✅ 7015ms
Partial Batch Handling.Partial Retry Preserves Uuids ✅ 7015ms
Partial Batch Handling.Partial Retry Attempt Header Increments ✅ 7012ms
Partial Batch Handling.Partial Retry Request Id Preserved ✅ 7015ms
Partial Batch Handling.Respects Retry After On Partial ✅ 7023ms
Partial Batch Handling.Unknown Result Treated As Terminal ✅ 3018ms
Partial Batch Handling.Mixed Ok Drop Warning No Retry ✅ 3022ms
Compression.Sends Gzip Content Encoding ✅ 12ms
Compression.No Content Encoding When Disabled ✅ 12ms
Compression.Compressed Body Is Decompressible ✅ 10ms
Error Handling.Does Not Retry On Unknown 4Xx ✅ 4012ms
Event Options.Cookieless Mode Override ✅ 12ms
Event Options.Disable Skew Correction Override ✅ 11ms
Event Options.Process Person Profile Override ✅ 12ms
Event Options.Product Tour Id Override ✅ 15ms
Event Options.Unset Options Omitted ✅ 12ms
Event Options.Options Override In Batch ✅ 16ms
Event Options.Unknown Option Passes Through ✅ 11ms
Event Options.Option Value Is Not Converted ✅ 13ms
Event Options.Lenient Bool Option Values Are Not Converted ✅ 12ms
Event Options.Option Wins Over Legacy Property ✅ 10ms
Event Options.Legacy Property Fills Unset Option ✅ 12ms
Event Options.Null Option Falls Back To Legacy Property ✅ 12ms
Property Layers.Caller Property Beats Registered Property ✅ 13ms
Property Layers.Before Send Runs Last ✅ 16ms
Fail Open.Empty Api Key Sends Nothing ✅ 3012ms
Fail Open.Personal Api Key Sends Nothing ✅ 3011ms
Geoip And Historical Migration.Historical Migration Absent By Default ✅ 12ms

Capture_Ai_V1 Tests

✅ 110/110 tests passed

View Details
Test Status Duration
Endpoint And Method.Targets V1 Endpoint ✅ 13ms
Endpoint And Method.Does Not Use Legacy Endpoints ✅ 11ms
Endpoint And Method.Capture Does Not Reroute Ai Named Events ✅ 9ms
Endpoint And Method.Capture Ai Does Not Reroute Non Ai Events ✅ 12ms
Lane Isolation.Failing Ai Lane Does Not Delay Analytics ✅ 7020ms
Required Headers.Has Authorization Bearer Header ✅ 13ms
Required Headers.Has Content Type Json ✅ 13ms
Required Headers.Has Posthog Sdk Info Format ✅ 11ms
Required Headers.Has Posthog Attempt Header ✅ 12ms
Required Headers.Has Posthog Request Id ✅ 11ms
Required Headers.Has Posthog Request Timestamp ✅ 11ms
Required Headers.Has User Agent ✅ 12ms
Body Format.Body Has Created At And Batch ✅ 11ms
Body Format.No Api Key In Body ✅ 11ms
Body Format.No Sent At In Body ✅ 11ms
Event Format.Event Has Required Root Fields ✅ 11ms
Event Format.Event Uuid Is Valid ✅ 13ms
Event Format.Event Timestamp Is Rfc3339 ✅ 11ms
Event Format.Non Utc Event Timestamp Is Converted To Utc ✅ 12ms
Event Format.Distinct Id Is String ✅ 13ms
Event Format.Distinct Id At Root Not Properties ✅ 13ms
Event Format.Custom Properties Preserved ✅ 11ms
Event Format.Set Properties Preserved ✅ 12ms
Event Format.Set Once Properties Preserved ✅ 11ms
Event Format.Groups Properties Preserved ✅ 12ms
Event Format.Sdk Generates Uuid If Not Provided ✅ 13ms
Event Format.Event Has Required Root Fields Batch ✅ 15ms
Event Format.Event Uuid Is Valid Batch ✅ 13ms
Event Format.Event Timestamp Is Rfc3339 Batch ✅ 15ms
Event Format.Distinct Id Is String Batch ✅ 14ms
Event Format.Distinct Id At Root Not Properties Batch ✅ 16ms
Event Format.Custom Properties Preserved Batch ✅ 20ms
Event Format.Set Properties Preserved Batch ✅ 17ms
Event Format.Set Once Properties Preserved Batch ✅ 16ms
Event Format.Groups Properties Preserved Batch ✅ 20ms
Event Format.Sdk Generates Uuid If Not Provided Batch ✅ 15ms
Batch Behavior.Multiple Events In Single Batch ✅ 20ms
Batch Behavior.Batch Envelope Smoke ✅ 17ms
Batch Behavior.Flush At Triggers Batch ✅ 1011ms
Batch Behavior.Created At Reflects Batch Creation Time ✅ 13ms
Deduplication.Generates Unique Uuids ✅ 19ms
Deduplication.Different Events Same Content Different Uuids ✅ 13ms
Deduplication.Preserves Uuid On Retry ✅ 7013ms
Deduplication.Preserves Timestamp On Retry ✅ 7013ms
Deduplication.Preserves Uuid And Timestamp On Batch Retry ✅ 7010ms
Deduplication.No Duplicate Events In Batch ✅ 23ms
Header Behavior On Retry.Attempt Header Starts At One ✅ 13ms
Header Behavior On Retry.Attempt Header Increments On Retry ✅ 12016ms
Header Behavior On Retry.Request Id Preserved On Retry ✅ 7009ms
Header Behavior On Retry.Different Requests Have Different Request Ids ✅ 2018ms
Header Behavior On Retry.Request Timestamp Changes On Retry ✅ 7013ms
Response Format Validation.Success Response Has Uuid Keyed Results ✅ 13ms
Response Format Validation.Success Response Has Ok For Each Event ✅ 16ms
Response Format Validation.Success No Retry After When All Ok ✅ 14ms
Response Format Validation.Success Retry After Present When Retry Events ✅ 2007ms
Response Format Validation.Success No Retry After When Drop Only ✅ 15ms
Response Format Validation.Response Echoes Request Id ✅ 11ms
Retry Behavior.Retries On 408 ✅ 7010ms
Retry Behavior.Retries On 500 ✅ 7015ms
Retry Behavior.Retries On 503 ✅ 7018ms
Retry Behavior.Retries On 504 ✅ 7013ms
Retry Behavior.Retries On 404 ✅ 6015ms
Retry Behavior.Retries On 429 ✅ 7013ms
Retry Behavior.Retries On 502 ✅ 7013ms
Retry Behavior.Retryable Errors Have Retry After ✅ 4011ms
Retry Behavior.Respects Retry After On Retryable Error ✅ 10013ms
Retry Behavior.Does Not Retry On 400 ✅ 4014ms
Retry Behavior.Does Not Retry On 401 ✅ 4014ms
Retry Behavior.Does Not Retry On 402 ✅ 4013ms
Retry Behavior.Does Not Retry On 413 ✅ 4013ms
Retry Behavior.Does Not Retry On 415 ✅ 4014ms
Retry Behavior.Non Retryable Errors Have No Retry After ✅ 4015ms
Retry Behavior.Implements Backoff ✅ 14012ms
Partial Batch Handling.Handles 200 Full Success ✅ 2015ms
Partial Batch Handling.Handles 200 With All Ok ✅ 3018ms
Partial Batch Handling.Does Not Retry Dropped Events ✅ 3018ms
Partial Batch Handling.Does Not Retry Warning Events ✅ 3017ms
Partial Batch Handling.Prunes Ok Events On Partial Retry ✅ 7012ms
Partial Batch Handling.Prunes Dropped Events On Partial Retry ✅ 7012ms
Partial Batch Handling.Retries Only Retry Events From Partial ✅ 7014ms
Partial Batch Handling.Partial Retry Preserves Uuids ✅ 7013ms
Partial Batch Handling.Partial Retry Attempt Header Increments ✅ 7014ms
Partial Batch Handling.Partial Retry Request Id Preserved ✅ 7013ms
Partial Batch Handling.Respects Retry After On Partial ✅ 7018ms
Partial Batch Handling.Unknown Result Treated As Terminal ✅ 3018ms
Partial Batch Handling.Mixed Ok Drop Warning No Retry ✅ 3019ms
Compression.Sends Gzip Content Encoding ✅ 12ms
Compression.No Content Encoding When Disabled ✅ 12ms
Compression.Compressed Body Is Decompressible ✅ 13ms
Error Handling.Does Not Retry On Unknown 4Xx ✅ 4012ms
Event Options.Cookieless Mode Override ✅ 10ms
Event Options.Disable Skew Correction Override ✅ 10ms
Event Options.Process Person Profile Override ✅ 10ms
Event Options.Product Tour Id Override ✅ 12ms
Event Options.Unset Options Omitted ✅ 10ms
Event Options.Options Override In Batch ✅ 13ms
Event Options.Unknown Option Passes Through ✅ 13ms
Event Options.Option Value Is Not Converted ✅ 11ms
Event Options.Lenient Bool Option Values Are Not Converted ✅ 10ms
Event Options.Option Wins Over Legacy Property ✅ 9ms
Event Options.Legacy Property Fills Unset Option ✅ 9ms
Event Options.Null Option Falls Back To Legacy Property ✅ 11ms
Event Size.Event Over Ceiling Is Not Sent ✅ 3307ms
Event Size.Over Ceiling Drop Is Reported Or Logged Without Content ✅ 2041ms
Event Size.Batches Close Before Byte Target ✅ 6080ms
Geoip And Historical Migration.Historical Migration Absent By Default ✅ 12ms
Property Layers.Caller Property Beats Registered Property ✅ 10ms
Property Layers.Before Send Runs Last ✅ 10ms
Fail Open.Empty Api Key Sends Nothing ✅ 1007ms
Fail Open.Personal Api Key Sends Nothing ✅ 1008ms

Feature_Flags Tests

✅ 17/17 tests passed

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

…_flags

Applies to PostHog and PostHogStateless. $feature/<key> still carries the
raw "" value, matching posthog-js. posthog-server builds its own flag
properties and already left "" out.
@turnipdabeets
turnipdabeets merged commit f8ac747 into chore/v4-remove-deprecated Nov 9, 2026
12 checks passed
@turnipdabeets
turnipdabeets deleted the fix/v4-empty-variant-disabled branch November 9, 2026 14:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working feature/feature-flags

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants