Skip to content

fix(inappmessaging): stop dropping cached clearcut records on uploader init - #16827

Open
paulb777 wants to merge 2 commits into
mainfrom
pb-fiam-keep-cached-clearcut-records
Open

paulb777 wants to merge 2 commits into
mainfrom
pb-fiam-keep-cached-clearcut-records

Conversation

@paulb777

@paulb777 paulb777 commented Oct 2, 2026

Copy link
Copy Markdown
Member

Problem

FIRIAMClearcutUploader's initializer called popStillValidRecordsForUpTo: only to check
whether the log storage had records. It then threw away the returned array. That call
removes the records from FIRIAMClearcutLogStorage. So on every SDK start, up to one batch
(50 in production) of Clearcut records restored from the cache file was lost: the scheduled
upload popped the next batch, and the next cache save overwrote the file without the
dropped records.

The production upload strategy waits 5 min to 12 h between uploads. Records logged shortly
before the app is terminated are exactly the ones that end up in the cache, and there are
usually fewer than 50. So in practice most cached engagement logs (impressions, clicks,
dismissals) were dropped instead of uploaded.

Change

  • Add a non-consuming hasStillValidRecords to FIRIAMClearcutLogStorage (internal
    header). It uses the same expiry rule and lock as popStillValidRecordsForUpTo:.
  • Use it in the uploader's initializer to decide whether to schedule an upload. The cached
    records now stay in storage until the scheduled attemptUploading pops and sends them.

Records are still popped once per upload attempt and only pushed back on retryable
failures, so this doesn't introduce double sends.

Testing

Generated the CocoaPods unit test project, then ran it on an iOS 26.5 simulator (iPhone 17):

bundle exec pod gen FirebaseInAppMessaging.podspec --local-sources=./ --platforms=ios
xcodebuild test -workspace gen/FirebaseInAppMessaging/FirebaseInAppMessaging.xcworkspace \
  -scheme FirebaseInAppMessaging-Unit-unit -destination 'platform=iOS Simulator,name=iPhone 17'
  • New FIRIAMClearcutUploaderTests/testUploadsRecordsAlreadyInStorageWhenCreated:
    • Without the uploader change it fails: the cached record is never sent, the expectation
      times out, and sentLogs.count is 0.
    • With the change it passes.
  • New FIRIAMClearcutLogStorageTests/testHasStillValidRecordsDoesNotRemoveRecords passes.
  • Full FirebaseInAppMessaging-Unit-unit target: 123 tests, 0 failures.

Fixes #16803

…r init

FIRIAMClearcutUploader's initializer called the consuming
popStillValidRecordsForUpTo: only to check whether the log storage had
records, and discarded the returned array. On every SDK start this removed
up to one batch (50 in production) of Clearcut records restored from the
cache file: the scheduled upload then popped the next batch, and the next
cache save overwrote the file without them.

Add a non-consuming hasStillValidRecords check to FIRIAMClearcutLogStorage
and use it to decide whether to schedule an upload, so the cached records
stay in storage until the scheduled upload pops and sends them. Records are
still popped once per upload attempt and only pushed back on retryable
failures, so this does not introduce double sends.

Fixes #16803
@paulb777 paulb777 added the api: inappmessaging Firebase In App Messaging label Oct 2, 2026
@gemini-code-assist

Copy link
Copy Markdown
Contributor
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

@paulb777

paulb777 commented Oct 2, 2026

Copy link
Copy Markdown
Member Author

[paulb777-bot] Requesting an automated review, as on the other PRs from this batch.

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request fixes an issue where cached In-App Messaging engagement logs from a previous app session could be dropped instead of uploaded when the SDK started. It introduces a new method 'hasStillValidRecords' in 'FIRIAMClearcutLogStorage' to check for existing unexpired records without removing them, and updates 'FIRIAMClearcutUploader' to use this method during initialization. Unit tests have been added to verify the new behavior. There are no review comments to address, and I have no additional feedback to provide.

@paulb777 paulb777 assigned paulb777 and ncooke3 and unassigned paulb777 Oct 2, 2026
@paulb777 paulb777 added this to the 13.1.0 - M188 milestone Oct 2, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api: inappmessaging Firebase In App Messaging

Projects

None yet

Development

Successfully merging this pull request may close these issues.

In-App Messaging drops cached Clearcut records when uploader initializes

3 participants