fix(flags): fix failed flag overwrite on individual evaluation error#104
Merged
matheus-vb merged 1 commit intomasterfrom Feb 6, 2026
Merged
fix(flags): fix failed flag overwrite on individual evaluation error#104matheus-vb merged 1 commit intomasterfrom
matheus-vb merged 1 commit intomasterfrom
Conversation
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.
Problem
When the
/flagsendpoint fails to evaluate a specific flag due to a transient error (e.g. DB timeout), the server returns that flag withenabled: falseand a newfailed: truefield. The SDK then includes this failed result when transforming the v4 response, which can overwrite a previously valid value. IngetAllFlags(),array_mergeoverwrites a locally evaluatedtruewith the server's erroneousfalse.See PostHog/posthog#46204.
Changes
lib/Client.phpnormalizeFeatureFlags(): skip flags withfailed: trueduring the v4-to-v3 response transformation. Failed flags are excluded fromfeatureFlagsandfeatureFlagPayloads, so they cannot overwrite cached or locally evaluated values.getFeatureFlagResult(): exclude failed flags fromflagDetaillookup. This prevents a null access warning when reading$flagDetail['reason']['description']for flags whose reason may be null, and avoids attaching invalid metadata to analytics events.test/FeatureFlagErrorTest.phptestFailedFlagIsFilteredOutByFailedField: verifies that thefailedfield drives the filtering. Uses three flags —failed=true,enabled=false+failed=false(legitimately disabled), andenabled=true+failed=false— to prove that onlyfailed=trueis filtered, not all disabled flags.testGetAllFlagsDoesNotOverwriteLocalResultWithFailedServerFlag: reproduces the actual overwrite scenario. A flag evaluates locally astrue, the server returns it withfailed=true, and the test asserts the local value is preserved afterarray_merge.Tests
All 155 tests pass, no new PHP warnings introduced.