Repository navigation
fix(flags): decode payloads cached by 3.x from the cached flag details - #935
Conversation
… fix/v4-cached-3x-payloads
… fix/v4-cached-3x-payloads Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
|
||
| If you read a payload as plain text, such as a payload saved as `hello` rather than `"hello"`, update it in PostHog to valid JSON before you upgrade, or your code gets `null`. | ||
|
|
||
| A malformed payload cached by 3.x can still read as the raw string after the upgrade, until the app's first `/flags` response replaces it. |
There was a problem hiding this comment.
Apps upgrading from 3.13 or older didn't cache flag details, so a malformed payload can still read as the raw string until the first /flags response. Could we keep a shorter version of the removed note for that case?
There was a problem hiding this comment.
🤖 An AI agent wrote this on behalf of @ioannisj.
+1, withPayloadsFromCachedFlags returns cachedPayloads untouched when there are no flag details, so those apps still get the raw string until the first /flags response.
There was a problem hiding this comment.
Added back a narrower note in f518a50, scoped to apps upgrading from 3.13 or older. There's no clean code fix for that case: 3.13 cached payloads already decoded, so a valid string payload like "hello" is stored as hello, the same shape as a malformed raw string. Without the flag details we can't tell them apart, and decoding or dropping them would break valid payloads for that first launch.
… fix/v4-cached-3x-payloads Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ioannisj
left a comment
There was a problem hiding this comment.
🤖 An AI agent wrote this on behalf of @ioannisj.
No new findings: FLAGS and the payload cache stay in step through partial /flags merges, so decoding from the flag details is safe. Just a +1 on the open migration guide thread.
|
|
||
| If you read a payload as plain text, such as a payload saved as `hello` rather than `"hello"`, update it in PostHog to valid JSON before you upgrade, or your code gets `null`. | ||
|
|
||
| A malformed payload cached by 3.x can still read as the raw string after the upgrade, until the app's first `/flags` response replaces it. |
There was a problem hiding this comment.
🤖 An AI agent wrote this on behalf of @ioannisj.
+1, withPayloadsFromCachedFlags returns cachedPayloads untouched when there are no flag details, so those apps still get the raw string until the first /flags response.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
💡 Motivation and Context
4.0 decodes payloads strictly, so a malformed payload reads as
null. But 3.x kept a malformed payload as its raw string in the payload cache. After the upgrade, 4.0 loaded that cache unchanged, sogetFeatureFlagResult(key)?.payloadreturned the raw string until the first/flagsresponse replaced it, or for as long as the app stayed offline. The migration guide called this out as a known gap.The cached flag details (
FLAGS) keep each payload exactly as the server serialized it. On cache load, 4.0 now decodes payloads from those details with the same strict decoder it uses on a/flagsresponse, so cached and fresh payloads behave the same. It handles both the in-memoryFeatureFlagobjects and the maps thatSharedPreferencesgives back. Caches without flag details (from legacy v1 responses) keep their payload cache unchanged.The migration guide's note about the gap is removed. No changeset is needed: the 4.0 changeset already describes strict payload decoding, and this fix makes cached payloads follow it.
💚 How did you test it?
hellopayload and a valid sibling payload. After the upgrade,checkoutreadsnullwith its variant intact, and the sibling still decodes. It fails without the fix (expected null, but was: hello).PostHogRemoteConfigTestpasses (124 tests), andspotlessCheckpasses.mainmerged together: a payload cached by 3.75.3 decoded to{plan=premium, seats=5}on the first 4.0 launch while offline.Build Jobpasses. The compliance workflow doesn't run for PRs intochore/v4-*until feat!: send events through capture v1 and add captureAi #881 merges its workflow change.Merge note
This PR and #881 both edit
docs/migration-3.x-to-4.0.mdnext to each other, so whichever merges second conflicts there. Keep both: drop the "A malformed payload cached by 3.x…" sentence and keep #881's$localeand$app_languagesection.📝 Checklist
🤖 Agent context
Autonomy: Human-driven (agent-assisted)
Claude Code found this while checking the 4.0 flag API against PostHog/sdk-specs (
feature-flag-cache: malformed payloads must not be exposed as raw strings). Versioning the payload cache or dropping it on upgrade were rejected because both lose cached payloads on an offline first launch. Rebuilding from the cached flag details loses nothing.🤖 Generated with Claude Code