Skip to content

fix(flags): resolve payloads during local evaluation - #243

Merged
marandaneto merged 2 commits into
PostHog:mainfrom
okremer84:fix/local-evaluation-payloads
Sep 14, 2026
Merged

marandaneto merged 2 commits into
PostHog:mainfrom
okremer84:fix/local-evaluation-payloads

Conversation

@okremer84

Copy link
Copy Markdown
Contributor

Problem

Local flag definitions from /flags/definitions already include filters.payloads, but locally evaluated flags never expose them: evaluateFlags() builds each EvaluatedFlagRecord with payload: null on the local path, and the single-flag path (getFeatureFlagResult() / getFeatureFlagPayload()) leaves $payload null whenever the flag was computed locally. getFlagPayload() therefore only works after a remote /flags request, which defeats local evaluation for any flag whose payload is the point (config-as-flag, per-variant experiment parameters).

Fix

Read the payload from the definition's filters.payloads map, keyed by the variant for a multivariate flag or by "true" for a boolean flag that is on, and decode it the same way the remote path does (JSON string, or accept a pre-decoded value). A flag that is off yields no payload. One private helper, used by both local paths. No public API change.

Tests

testLocalEvaluationResolvesPayloads covers a boolean flag with a JSON payload, a multivariate flag whose winning variant carries a pre-decoded payload, an inactive flag with a payload, and asserts no /flags request is made.

Full suite: the only failures are the four ExceptionCaptureTest cases that also fail on master in my environment (error-handler/exit behaviour under PHPUnit), unrelated to this change.

@okremer84
okremer84 requested a review from a team as a code owner September 14, 2026 01:01
@marandaneto

Copy link
Copy Markdown
Member

thanks @okremer84

Local flag definitions already carry filters.payloads, but both
evaluateFlags() and the single-flag path recorded payload: null for a
locally computed value, so getFlagPayload() only ever worked after a
remote /flags request. Read the payload from the definition, keyed by
the variant or "true" for a boolean flag, mirroring the remote path's
handling of pre-decoded values.
@marandaneto
marandaneto force-pushed the fix/local-evaluation-payloads branch from 2e7f928 to cf7edfb Compare September 14, 2026 06:08
@marandaneto

Copy link
Copy Markdown
Member

fixed cf7edfb (this PR)

@marandaneto
marandaneto enabled auto-merge (squash) September 14, 2026 06:09
@marandaneto
marandaneto merged commit 2a7d099 into PostHog:main Sep 14, 2026
23 checks passed
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.

2 participants