Repository navigation
chore!: pass the load result to the feature flags callback - #877
Conversation
There was a problem hiding this comment.
PostHog Review · Standard · reviewed 90beca5: 2 Should fix.
See this review and its findings in PostHog Review. Comment @posthog review --deep for a Deep review. A Deep review takes longer and looks deeper than a Standard review.
2f486a0 to
a41d9b9
Compare
6d389ab to
4469ad4
Compare
a41d9b9 to
caf64bd
Compare
e9eb0db to
46fca5a
Compare
PostHogConfig.onFeatureFlags and reloadFeatureFlags() now take a PostHogFeatureFlagsCallback, whose loaded() receives a PostHogFeatureFlagsLoaded with the enabled flags, their values, and errorsLoading, matching posthog-ios 4.0. Every path that invoked the callback passes an accurate result, including failures, a disabled SDK, and bootstrap. PostHogOnFeatureFlags moves to posthog-server under the same name, so the server's API is unchanged and it can drop the type in its own major.
posthog-server calls its own PostHogOnFeatureFlags directly, and the core stateless client never calls config.onFeatureFlags. Bump posthog-server to minor since it now depends on core 7.0, and document that a bootstrapped onFeatureFlags runs on the setup() thread.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
3f4acd8 to
5dcba77
Compare
dustinbyrne
left a comment
There was a problem hiding this comment.
AI-assisted review. The readable-cache and bootstrap fixes are verified. One Direct Boot cache-availability regression remains; details and executed base/head evidence are inline.
A failed load now hydrates the flag cache before the callback. Under Direct Boot that read returned empty values and latched, so persisted flags stayed hidden after unlock. Only latch once the preferences are readable. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
PostHog Review · Standard · reviewed 8aaa5a4: 1 Must fix, 1 Should fix.
This is review round 3 on this pull request. When findings keep coming back in the same code, the approach is usually the problem. Before the next fix, check whether a different design would remove the whole class of findings.
Every flag getter retried hydration under Direct Boot and re-read each cached key, each read failing against locked preferences. Check availability once and skip the reads until storage is readable. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Hydration reads the cache off the flags lock, so a reset() landing between the read and the commit had the previous identity's flags restored. clear() now bumps a generation and hydration drops a commit from an older one. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
dustinbyrne
left a comment
There was a problem hiding this comment.
AI-assisted review. Verified reset invalidation, Direct Boot recovery, and retained cached values on failed loads. No remaining findings in the reviewed changes.
Note
Stacked on the 4.0 integration PR #871. Merges into
chore/v4-remove-deprecated, notmain.💡 Motivation and Context
Addresses #563: the callback now receives the loaded flags and whether loading failed.
Brings the Android flags callback to parity with posthog-ios 4.0 (
PostHogFeatureFlagsLoaded) and Flutter 6.PostHogConfig.onFeatureFlagsandreloadFeatureFlags()now take a newPostHogFeatureFlagsCallback. Itsloaded()receives aPostHogFeatureFlagsLoadedwith:flags: the keys of the enabled flagsvariants: their values (trueor the variant string)errorsLoading: whether the latest load failed (the values are then the last known ones)Every path that invoked the old callback now passes an accurate result, including failed requests, a disabled SDK, and bootstrap.
Why a new type instead of changing
PostHogOnFeatureFlags: core's public types are also part ofposthog-server's API. ChangingPostHogOnFeatureFlags.loaded()would force a server major for a callback the server can only fill with empty data (it evaluates flags per call). So:PostHogOnFeatureFlagsmoves from core intoposthog-server, same package and shape, so server users' source and binaries keep working. Android no longer sees it.posthog-servergets a minor bump, since it now depends on core 7.0.The other core types the server exposes (
FeatureFlagResult,PostHogBeforeSend,PostHogEncryption,PostHogIntegration) are unchanged.For reviewers: a blank
distinctIdreportserrorsLoading = true, since no request is made.💚 How did you test it?
./gradlew spotlessCheck apiCheck :posthog:test :posthog-server:test :posthog-android:testDebugUnitTestpass, and the Android sample compiles.PostHogRemoteConfigTestandPostHogBootstrapTestassert the result passed on success, failure, and bootstrap.asCoreConfigno longer setting the core callback.posthog-server.apionly gainsPostHogOnFeatureFlags(moved in, unchanged).📝 Checklist
If releasing new changes
pnpm changesetto generate a changeset file🤖 Agent context
Autonomy: Human-driven (agent-assisted)
Claude Code (Claude Opus 5.5) implemented the change after a cross-SDK flags API review (iOS, Android, Flutter, React Native). A first version changed
PostHogOnFeatureFlagsin place and bumped the server to a major; it was reworked to move the old type intoposthog-serverso the server stays untouched until its own major.🤖 Generated with Claude Code