Repository navigation
fix: replay onFeatureFlags to a late listener without waiting for the flags request - #948
Merged
turnipdabeets merged 4 commits intoNov 9, 2026
Conversation
… flags request The catch-up replay for a listener registered after setup() hopped onto the remote config thread first, so it queued behind an in-flight /config or /flags request. With bootstrap flags and a slow network, the listener never saw the bootstrapped values. Post the replay straight to the listener executor (the main thread on Android) instead; delivery still reads the latest value at run time and skips one already delivered, so a load landing right after is delivered once, after the replay.
Contributor
posthog-android Compliance ReportDate: 2026-11-08T20:11:09.284656+00:00 ✅ All Tests Passed!232/232 tests passed Capture_V1 Tests✅ 105/105 tests passed View Details
Capture_Ai_V1 Tests✅ 110/110 tests passed View Details
Feature_Flags Tests✅ 17/17 tests passed View Details
|
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.
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
Fixes an unreleased 4.0 bug in
onFeatureFlags(part of #871).A listener registered after
setup()gets a catch-up replay of the last delivered flags. That replay was queued on the remote config thread first, so it waited behind setup's in-flight/config+/flagsrequest. With bootstrap flags and a slow network, the late listener got nothing until the request finished and then only the network result, so it never saw the bootstrapped values. Theon-feature-flagsspec says Android 4.0 calls the callback with the current values once flags are already loaded, and iOS 4.0 replays immediately on the main thread.The replay now goes straight to the listener executor (the main thread on Android). Delivery still reads the latest value when it runs and skips a value it already delivered, so a load that lands right after is delivered once, after the replay, with no duplicate or stale value. Listener exceptions are still caught in
deliverFeatureFlags.On the plain JVM (no listener executor), listeners are documented to run on the remote config thread, so the replay still queues there and can still wait for an in-flight request. Fixing that needs a dedicated listener thread on the JVM, which is left out of this change.
No changeset:
onFeatureFlags()is new in 4.0 and already covered by the 4.0 changeset.💚 How did you test it?
onFeatureFlags replays bootstrapped flags to a late listener while setup's load is in flightuses a mock server that holds/configand/flags. It fails on the base branch (no delivery within 2 s) and passes with the fix. It replaces the old test, which used an unreachable host that fails instantly and so hid the bug.onFeatureFlags delivers a load that lands before a late listener's replay runs oncecovers ordering: the listener gets only the network values, once../gradlew spotlessCheck :posthog:apiCheck :posthog:test: all 1250 tests pass.📝 Checklist
🤖 Agent context
Autonomy: Human-driven (agent-assisted)
Claude Code found the bug while reviewing 4.0's flag caching. A throwaway test confirmed it, and Claude Code then fixed it. I considered delivering the replay synchronously on the caller's thread for the JVM too, but turned it down: it would need a per-listener lock held across user callbacks (a deadlock risk) and would contradict the documented JVM thread.
🤖 Generated with Claude Code