Skip to content

Fix cold starts incorrectly using the previous firstSessionId #7047

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 19, 2025

Conversation

mrober
Copy link
Contributor

@mrober mrober commented Jun 19, 2025

Fix cold starts incorrectly using the previous firstSessionId and sessionIndex

This came up during the dogfooding session

When a cold start happens, we must always create a new session. Before this fix, it would preserve the current session's firstSesisonId and sessionIndex when that session hadn't expired. But a cold start is regardless of the current session expiring

@mrober mrober requested review from tejasd and themiswang June 19, 2025 15:56
Copy link
Contributor

Firebase AI Mock Responses Check ⚠️

A newer major version of the mock responses for Firebase AI unit tests is available. update_responses.sh should be updated to clone the latest version of the responses: v14.1

Copy link

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

Choose a reason for hiding this comment

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

Summary of Changes

Hello @mrober, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses a critical bug where cold starts were not consistently creating new sessions, leading to incorrect session tracking by reusing firstSessionId and sessionIndex from previous sessions. The changes ensure that every cold start correctly initiates a brand new session, improving the accuracy and reliability of session data.

Highlights

  • Session Generation Logic: The core logic for generating new sessions in SharedSessionRepository.kt has been updated. Previously, during a cold start, the system might incorrectly reuse the firstSessionId and sessionIndex from a prior session if it hadn't technically expired. This change ensures that when a cold start is detected, a completely new session is always generated by explicitly passing null as the previous session details to the sessionGenerator.generateNewSession method.
  • Test Case Alignment: A test case in SharedSessionRepositoryTest.kt was modified to reflect the correct expected firstSessionId and sessionIndex for a newly generated session after a cold start. This confirms that the fix behaves as intended, with the new session correctly starting with its own ID as firstSessionId and a sessionIndex of 0.
  • Minor Code Cleanup: A TODO comment related to session time validation was removed from SharedSessionRepository.kt.
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 in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

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 issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize 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 is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@google-oss-bot
Copy link
Contributor

1 Warning
⚠️ Did you forget to add a changelog entry? (Add the 'no-changelog' label to the PR to silence this warning.)

Generated by 🚫 Danger

Copy link

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

Choose a reason for hiding this comment

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

Code Review

The pull request correctly addresses the issue of cold starts improperly reusing firstSessionId and sessionIndex. The logic changes in SharedSessionRepository.kt ensure that a new session with a reset firstSessionId and sessionIndex is created during a cold start. The test updates in SharedSessionRepositoryTest.kt align with this corrected behavior. The main actionable feedback is to remove a debugging println statement.

@google-oss-bot
Copy link
Contributor

google-oss-bot commented Jun 19, 2025

Coverage Report 1

Affected Products

  • firebase-sessions

    Overall coverage changed from ? (21215eb) to 81.70% (97c9058) by ?.

    47 individual files with coverage change

    FilenameBase (21215eb)Merge (97c9058)Diff
    ApplicationInfo.kt?100.00%?
    AutoSessionEventEncoder.java?100.00%?
    DaggerFirebaseSessionsComponent.java?94.23%?
    EventGDTLogger.kt?70.00%?
    EventGDTLogger_Factory.java?0.00%?
    FirebaseSessions.kt?53.57%?
    FirebaseSessionsComponent.kt?65.79%?
    FirebaseSessionsComponent_MainModule_Companion_ApplicationInfoFactory.java?0.00%?
    FirebaseSessionsComponent_MainModule_Companion_SessionConfigsDataStoreFactory.java?0.00%?
    FirebaseSessionsComponent_MainModule_Companion_SessionDataStoreFactory.java?0.00%?
    FirebaseSessionsComponent_MainModule_Companion_TimeProviderFactory.java?100.00%?
    FirebaseSessionsComponent_MainModule_Companion_UuidGeneratorFactory.java?100.00%?
    FirebaseSessionsDependencies.kt?92.00%?
    FirebaseSessionsRegistrar.kt?90.91%?
    FirebaseSessions_Factory.java?0.00%?
    InstallationId.kt?100.00%?
    LocalOverrideSettings.kt?100.00%?
    LocalOverrideSettings_Factory.java?0.00%?
    ProcessDataManager.kt?71.43%?
    ProcessDataManagerImpl_Factory.java?0.00%?
    ProcessDetailsProvider.kt?76.00%?
    RemoteSettings.kt?88.41%?
    RemoteSettingsFetcher.kt?10.00%?
    RemoteSettingsFetcher_Factory.java?0.00%?
    RemoteSettings_Factory.java?0.00%?
    SessionConfigs.kt?95.45%?
    SessionData.kt?58.82%?
    SessionDataSerializer_Factory.java?0.00%?
    SessionDetails.kt?85.71%?
    SessionEvent.kt?100.00%?
    SessionEvents.kt?98.00%?
    SessionFirelogPublisher.kt?83.33%?
    SessionFirelogPublisherImpl_Factory.java?0.00%?
    SessionGenerator.kt?100.00%?
    SessionGenerator_Factory.java?0.00%?
    SessionsActivityLifecycleCallbacks.kt?18.75%?
    SessionsActivityLifecycleCallbacks_Factory.java?0.00%?
    SessionsSettings.kt?93.75%?
    SessionsSettings_Factory.java?0.00%?
    SessionSubscriber.kt?75.00%?
    SettingsCache.kt?80.56%?
    SettingsCacheImpl_Factory.java?0.00%?
    SettingsProvider.kt?50.00%?
    SharedSessionRepository.kt?80.31%?
    SharedSessionRepositoryImpl_Factory.java?0.00%?
    TimeProvider.kt?75.00%?
    UuidGenerator.kt?100.00%?

Test Logs

  1. https://storage.googleapis.com/firebase-sdk-metric-reports/pvrs8xvHQi.html

Copy link
Contributor

Test Results

 38 files   -  1 020   38 suites   - 1 020   47s ⏱️ - 35m 15s
 87 tests  -  5 891   87 ✅  -  5 869  0 💤  - 22  0 ❌ ±0 
174 runs   - 11 845  174 ✅  - 11 801  0 💤  - 44  0 ❌ ±0 

Results for commit 342eb44. ± Comparison against base commit 21215eb.

@google-oss-bot
Copy link
Contributor

Size Report 1

Affected Products

  • base

    TypeBase (21215eb)Merge (97c9058)Diff
    apk (aggressive)?8.80 kB? (?)
    apk (release)?9.77 kB? (?)
  • firebase-sessions

    TypeBase (21215eb)Merge (97c9058)Diff
    aar?216 kB? (?)
    apk (aggressive)?539 kB? (?)
    apk (release)?5.79 MB? (?)

Test Logs

  1. https://storage.googleapis.com/firebase-sdk-metric-reports/oSM95YUyJc.html

@mrober mrober merged commit 0aae9f1 into sessions-sharedrepo Jun 19, 2025
32 checks passed
@mrober mrober deleted the mrober/fixColdStart branch June 19, 2025 17:40
mrober added a commit that referenced this pull request Jun 20, 2025
Fix cold starts incorrectly using the previous firstSessionId and
sessionIndex

This came up during the dogfooding session

When a cold start happens, we must always create a new session. Before
this fix, it would preserve the current session's firstSesisonId and
sessionIndex when that session hadn't expired. But a cold start is
regardless of the current session expiring
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.

4 participants