Repository navigation
fix(flags): read an empty variant as disabled in getFeatureFlagResult and onFeatureFlags - #1037
Merged
turnipdabeets merged 3 commits intoNov 9, 2026
Conversation
… and onFeatureFlags
turnipdabeets
marked this pull request as ready for review
November 6, 2026 20:18
This was referenced Nov 6, 2026
Contributor
posthog-ios Compliance ReportDate: 2026-11-08T19:47:36.879920+00:00 ✅ All Tests Passed!234/234 tests passed Capture_V1 Tests✅ 106/106 tests passed View Details
Capture_Ai_V1 Tests✅ 111/111 tests passed View Details
Feature_Flags Tests✅ 17/17 tests passed View Details
|
This was referenced Nov 6, 2026
…_flags $feature/<key> still carries the raw "" value, matching posthog-js.
marandaneto
approved these changes
Nov 9, 2026
marandaneto
left a comment
Member
There was a problem hiding this comment.
The code looks good; no qualifying findings. Verdict: correct. Approved at the user's explicit request after confirming the reviewed patch is unchanged. Focused before/after regression tests, 191 relevant existing tests, lint and the SwiftPM build passed; the full cross-platform build matrix was not run.
5 of 15 tasks
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
#1001 made
isFeatureEnabledreturnfalsefor a flag whose variant is the empty string"", butgetFeatureFlagResult(_:).enabledstayedtrueandPostHogFeatureFlagsLoadedstill listed the flag, so the same flag read as enabled and disabled depending on the call (review thread). This makes""read as disabled everywhere, matching posthog-js (browser), which is already consistent.getFeatureFlagResult(_:)andgetAllFeatureFlags()returnenabled: false, withvariantstill"".PostHogFeatureFlagsLoadedleaves the flag out offlagsandvariants.isFeatureEnabled(alreadyfalse, with or withoutdefaultValue),getFeatureFlag(still returns""), and the$feature_flag_calledevent (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.The changeset's "Fix" line becomes a Breaking entry covering all three APIs, and
MIGRATION.mdlists them and notes thatvariantstill returns"".$active_feature_flags;$feature/<key>still carries the raw"", as in posthog-js (browser), whosefilterActiveFeatureFlagsskips falsy values while$feature/<key>copies the raw value.Parity with other SDKs
Target for every SDK: a
""variant givesisFeatureEnabled→false,getFeatureFlagResult().enabled→false,variant→"", and it's left out of the flags-loaded list.falseeverywhereisFeatureEnabledfalse(#1001),.enabledtrue, listed in flags-loadedenabled, soisFeatureEnabled(defaultValue:)returnedtrueon iOS/Androidtrue, Android/JVMfalse, JS/Wasm.enabledtrueisFeatureEnabledfalse,.enabledtruetrueeverywhere""rule in PostHog/sdk-specs#193So after this PR and its siblings, every mobile SDK matches posthog-js (browser) and the spec. The JS core and the server SDKs are the remaining gap.
💚 How did you test it?
PostHogSDKTest"an empty variant reads as disabled" (with and withoutdefaultValue) to assertgetFeatureFlagResult(_:).enabled == false,variant == "", and that the reload callback'sPostHogFeatureFlagsLoadedleaves the flag out.enabled,flagsandvariants; passes with the fix.PostHogSDKTest"captured events leave a flag with an empty variant out of $active_feature_flags": fails before the fix (["empty-variant", "on"]), passes after.swift test --filter "PostHogSDKTests|PostHogFeatureFlags|PostHogEventSnapshot": 189 tests in 26 suites passed.swift test --no-parallel -Xswiftc -DTESTING --filter "emptyVariantIsDisabled|PostHogFeatureFlagsTest|FeatureFlagsLoaded": 83 tests in 15 suites passed.📝 Checklist
If releasing new changes
pnpm changesetto 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 result builder and one in
PostHogFeatureFlagsLoaded;isFeatureEnabledwas left as is since it already returnsfalse.🤖 Generated with Claude Code