fix: drain pre-init buffer after modules subscribe; preserve setter ordering#701
Closed
mahmoud-elmorabea wants to merge 2 commits into
Closed
fix: drain pre-init buffer after modules subscribe; preserve setter ordering#701mahmoud-elmorabea wants to merge 2 commits into
mahmoud-elmorabea wants to merge 2 commits into
Conversation
…rdering Addresses PR #700 review comments. - `CustomerIO.finishInitialization()` now publishes the initial `UserChangedEvent` and drains the pre-init buffer **after** every module has run its `initialize()`. This means MessagingInApp (and any other late-subscribing module) attaches before the identity event is published, so a screen-heavy pre-init buffer can no longer evict it from the SharedFlow replay window. - `isReady` now sources from `preInitBuffer.isReady` instead of the old `componentsReady` flag, so the readiness signal flips atomically with the drain completing. Public setters that don't synchronize via `DataPipelineInstance` (`setProfileAttributes`, `setDeviceAttributes`) therefore route through the buffer for the entire pre-init and drain window, preserving FIFO order with earlier buffered calls. - Buffered closures now invoke private `*Internal` methods (identifyInternal, trackInternal, screenInternal, …) that contain the bodies without the readiness gate, avoiding recursive re-enqueue during replay. The double- init guard moved to a separate `initStarted` flag latched at the start of `initializeComponents()`. - `PreInitEventBuffer.enqueue` now enforces capacity + drop accounting in the `Draining` state as well as `Buffering`. Mirrors the iOS fix; covered by a new `drainingStateEnforcesCapacity` unit test. - New `FinishInitializationOrderTest` verifies that a late-subscribing module's `subscribe(UserChangedEvent)` happens before the initial publish, and that buffered screen events drain after subscription. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Sample app builds 📱Below you will find the list of the latest versions of the sample apps. It's recommended to always download the latest builds of the sample apps to accurately test the pull request. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## pre-init-event-buffer #701 +/- ##
===========================================================
+ Coverage 67.70% 67.86% +0.15%
- Complexity 876 889 +13
===========================================================
Files 156 156
Lines 4803 4832 +29
Branches 669 670 +1
===========================================================
+ Hits 3252 3279 +27
+ Misses 1287 1286 -1
- Partials 264 267 +3 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
|
📏 SDK Binary Size Comparison Report
|
|
Build available to test |
…mpleApplication Mirrors the iOS APN-UIKit AppDelegate scenarios. Toggle PRE_INIT_SCENARIO to S1..S7 to exercise a specific case while running the sample app, then watch logcat for `PreInitEventBuffer` entries and check server arrival via the workspace's Activity Log. Default is OFF, leaving normal app behavior unchanged. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
|
Contributor
Author
|
Rolled into the original PR #700 as commit |
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.
Summary
Addresses both P2 review comments on #700.
CustomerIO.finishInitialization()publishes the initialUserChangedEventand drains the pre-init buffer after every module has run itsinitialize(). Late-subscribing modules (e.g.MessagingInApp) attach before the identity event is published, so a screen-heavy buffer can no longer evict it from the SharedFlow replay window.isReadynow sources frompreInitBuffer.isReadyinstead of a separatecomponentsReadyflag. The readiness signal flips atomically with the drain completing, sosetProfileAttributes/setDeviceAttributes(which don't synchronize viaDataPipelineInstance) route through the buffer for the entire pre-init and drain window, preserving FIFO order with earlier buffered calls.*Internalmethods that contain the bodies without the readiness gate, so replay against the real impl doesn't re-enterenqueue. The companion-level double-init guard moved to a separateinitStartedflag latched at the start ofinitializeComponents().PreInitEventBuffer.enqueuenow enforces capacity + drop accounting in theDrainingstate as well asBuffering, mirroring the iOS sister fix.Aligned with
customerio-ios-tng(no deliberate divergence): module wiring, identity broadcast, and event-stream drain occur in that order.Test plan
./gradlew :datapipelines:testDebugUnitTest— full suite green, including:PreInitEventBufferTest.drainingStateEnforcesCapacity— reentrant enqueues during drain hit the cap.FinishInitializationOrderTest.givenScreenHeavyPreInitBuffer_*— late-subscribing module receives the initialUserChangedEventeven when 101 pre-init screens are queued; buffered screens publish after subscription../gradlew :messaginginapp:testDebugUnitTest— green../gradlew :datapipelines:lintDebug— green../ktlint --androidon changed files — clean.🤖 Generated with Claude Code