Skip to content

fix: in-app messages not displaying when app returns from background with SSE enabled #663

Merged
Shahroz16 merged 3 commits intomainfrom
mbl-1580
Feb 24, 2026
Merged

fix: in-app messages not displaying when app returns from background with SSE enabled #663
Shahroz16 merged 3 commits intomainfrom
mbl-1580

Conversation

@Shahroz16
Copy link
Contributor

@Shahroz16 Shahroz16 commented Feb 23, 2026

Reproducible

  • App in foreground → message displays immediately ✓
  • App closed, then opened → message displays on launch ✓
  • App in background, then foregrounded → message does NOT display until force-close and reopen ✗

Root Cause

When SSE support was introduced (#636, merged Jan 13), a guard was added to fetchInAppMessages() that skips the HTTP fetch entirely when SSE is active (shouldUseSse = true). This was correct for skipping recurring polling, but it
also removed the one-time catch-up fetch that previously ran on every onActivityResumed().

The sequence of events:

  1. App goes to background → SSE disconnects, polling stops
  2. Server sends an in-app message → nobody is listening
  3. App returns to foreground → onActivityResumed() calls fetchInAppMessages()
  4. fetchInAppMessages() sees SSE is active → returns immediately without fetching
  5. SSE reconnects but only delivers new real-time events, not missed messages
  6. The message is never retrieved

On a cold start this doesn't happen because SSE hasn't been enabled yet (the flag comes from server response headers), so the first HTTP fetch runs before SSE is activated.

Fix

Added a forceFetch parameter to fetchInAppMessages(). When the app resumes from background, onActivityResumed() passes forceFetch = true, which performs a one-time HTTP fetch even when SSE is active — catching up on any messages missed while the SSE connection was disconnected. All other callers default to forceFetch = false and behave exactly as before.


Note

Medium Risk
Changes foreground lifecycle behavior to add an extra network fetch, which could impact message duplication/timing and API load if triggered unexpectedly; scope is limited to SSE-enabled, identified-user paths and is covered by unit tests.

Overview
Fixes missed in-app messages when returning from background with SSE enabled by performing a one-time gistQueue.fetchUserMessages() before starting the SSE connection on app foreground.

Updates DI to inject GistQueue into SseLifecycleManager, and expands SseLifecycleManagerTest with new coverage ensuring the catch-up fetch runs only for identified users using SSE (and not for polling/anonymous flows), including background→foreground scenarios.

Written by Cursor Bugbot for commit 7171ac3. This will update automatically on new commits. Configure here.

@Shahroz16 Shahroz16 requested a review from a team as a code owner February 23, 2026 17:34
@github-actions
Copy link

github-actions bot commented Feb 23, 2026

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.


private fun onActivityResumed() {
logger.debug("GistSdk Activity resumed")
fetchInAppMessages(state.pollInterval)
fetchInAppMessages(state.pollInterval, forceFetch = true)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Won't this be called from all activities not just background -> foreground transition? If you test this with settings activity or inline activity, you will see polling forced multiple times

@github-actions
Copy link

  • kotlin_compose: mbl-1580 (1771868172)

@github-actions
Copy link

Build available to test
Version: mbl-1580-SNAPSHOT
Repository: https://central.sonatype.com/repository/maven-snapshots/

@github-actions
Copy link

  • java_layout: mbl-1580 (1771868157)

@github-actions
Copy link

github-actions bot commented Feb 23, 2026

📏 SDK Binary Size Comparison Report

Module Last Recorded Size Current Size Change in Size
core 29.88 KB 29.88 KB ✅ No Change
datapipelines 39.12 KB 39.12 KB ✅ No Change
messagingpush 30.25 KB 30.25 KB ✅ No Change
messaginginapp 122.08 KB 122.30 KB ⬆️ +0.22KB
tracking-migration 22.89 KB 22.89 KB ✅ No Change

@mahmoud-elmorabea mahmoud-elmorabea requested a review from a team February 23, 2026 17:48
@github-actions
Copy link

  • java_layout: mbl-1580 (1771869921)

@github-actions
Copy link

  • kotlin_compose: mbl-1580 (1771869916)

@mahmoud-elmorabea mahmoud-elmorabea requested a review from a team February 23, 2026 18:50
@codecov
Copy link

codecov bot commented Feb 23, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 69.02%. Comparing base (b5cf24d) to head (7171ac3).
⚠️ Report is 3 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff              @@
##               main     #663      +/-   ##
============================================
- Coverage     69.07%   69.02%   -0.05%     
  Complexity      838      838              
============================================
  Files           149      149              
  Lines          4601     4604       +3     
  Branches        628      628              
============================================
  Hits           3178     3178              
  Misses         1189     1189              
- Partials        234      237       +3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

private val processLifecycleOwner = mockk<LifecycleOwner>(relaxed = true)
private val lifecycle = mockk<Lifecycle>(relaxed = true)
private val mainThreadPoster = mockk<MainThreadPoster>(relaxed = true)
private val gistQueue = mockk<GistQueue>(relaxed = true)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we actually add a test to verify the new behavior?

@github-actions
Copy link

  • java_layout: mbl-1580 (1771932938)

@github-actions
Copy link

  • kotlin_compose: mbl-1580 (1771932933)

@Shahroz16 Shahroz16 merged commit 9fb8156 into main Feb 24, 2026
37 checks passed
@Shahroz16 Shahroz16 deleted the mbl-1580 branch February 24, 2026 11:51
github-actions bot pushed a commit that referenced this pull request Feb 24, 2026
## [4.16.1](4.16.0...4.16.1) (2026-02-24)

### Bug Fixes

* in-app messages not displaying when app returns from background with SSE enabled  ([#663](#663)) ([9fb8156](9fb8156))
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.

3 participants