Skip to content

Conversation

@OrangeAndGreen
Copy link
Contributor

https://dimagi.atlassian.net/browse/CCCT-950
cross-request: dimagi/commcare-core#1455

Product Description

Fixes a bug where the app would sometimes crash during registration.

Technical Summary

Fixed handling for received remote passphrase to properly rekey when necessary, and then store the local passphrase.
Added analytics event when database is rekeyed with new passphrase.
More notes about the crash that caused this here

Feature Flag

ConnectID

Safety Assurance

Safety story

Tested several scenarios locally.
QA plan should make sure to include the testing described below.

Automated test coverage

None

QA Plan

Tests that need to be performed around this, all should not crash:

  • Register an account
  • Recover an account
  • Reg/recover on published beta (build 472000), then update to latest and run again
  • LEGACY: Reg/recover account on build <467187 (June 18, 2024), then update to latest and run again

Added analytics event when database is rekeyed with new passphrase.
@coderabbitai
Copy link

coderabbitai bot commented Apr 16, 2025

📝 Walkthrough

Walkthrough

The changes introduce conditional logic to the database rekeying process in ConnectDatabaseHelper. Now, the database is rekeyed only if it is currently open and the received remote passphrase is different from the locally stored passphrase. After a successful rekey operation, the event is reported to Firebase Analytics, and the new passphrase is stored. Additionally, a log statement was added to the getHandle method in the anonymous AndroidDbHelper subclass to indicate when the legacy byte array passphrase method is used, specifying whether the passphrase is encrypted or unencrypted.

A new analytics event constant, CCC_REKEYED_DB, was added to the CCAnalyticsEvent class. Correspondingly, a new public static method, reportRekeyedDatabase(), was introduced in FirebaseAnalyticsUtil to report this event. No changes were made to the signatures of existing public methods or classes.

Sequence Diagram(s)

sequenceDiagram
    participant Remote as Remote Source
    participant ConnectDatabaseHelper
    participant Database
    participant FirebaseAnalyticsUtil

    Remote->>ConnectDatabaseHelper: handleReceivedDbPassphrase(remotePassphrase)
    alt Database is open AND remotePassphrase != localPassphrase
        ConnectDatabaseHelper->>Database: Rekey with remotePassphrase
        ConnectDatabaseHelper->>FirebaseAnalyticsUtil: reportRekeyedDatabase()
        ConnectDatabaseHelper->>ConnectDatabaseHelper: Store remotePassphrase as local
    else Database not open or passphrase unchanged
        ConnectDatabaseHelper-->>Remote: No action
    end
Loading

Suggested reviewers

  • pm-dimagi
  • shubham1g5

Tip

⚡💬 Agentic Chat (Pro Plan, General Availability)
  • We're introducing multi-step agentic chat in review comments and issue comments, within and outside of PR's. This feature enhances review and issue discussions with the CodeRabbit agentic chat by enabling advanced interactions, including the ability to create pull requests directly from comments and add commits to existing pull requests.

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0e1553a and 0d22f69.

📒 Files selected for processing (3)
  • app/src/org/commcare/connect/database/ConnectDatabaseHelper.java (3 hunks)
  • app/src/org/commcare/google/services/analytics/CCAnalyticsEvent.java (1 hunks)
  • app/src/org/commcare/google/services/analytics/FirebaseAnalyticsUtil.java (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
app/src/org/commcare/google/services/analytics/FirebaseAnalyticsUtil.java (1)
app/src/org/commcare/google/services/analytics/CCAnalyticsEvent.java (1)
  • CCAnalyticsEvent (7-55)
🔇 Additional comments (5)
app/src/org/commcare/google/services/analytics/CCAnalyticsEvent.java (1)

53-53: Appropriate analytics event naming for database rekeying.

The new CCC_REKEYED_DB constant follows the established naming pattern for Connect-related analytics events (prefixed with CCC_). This allows tracking database rekeying events, which is useful for monitoring and debugging database operations.

app/src/org/commcare/google/services/analytics/FirebaseAnalyticsUtil.java (1)

515-517: Analytics method follows established patterns.

The reportRekeyedDatabase() method properly uses the new constant from CCAnalyticsEvent and follows the existing pattern for simple event reporting in this class. This will help track when database rekeying operations occur.

app/src/org/commcare/connect/database/ConnectDatabaseHelper.java (3)

36-41: Critical fix to prevent unnecessary database rekeying.

The improved conditional logic now only rekeys the database when necessary (when passphrases differ), which:

  1. Prevents potential crashes during user registration
  2. Improves performance by avoiding unnecessary rekeying operations
  3. Adds analytics tracking for monitoring rekeying events

This directly addresses the bug mentioned in the PR description where crashes occurred during user registration.


43-44: Clearly separated passphrase storage logic with helpful comment.

Moving the passphrase storage outside the conditional block ensures it always occurs, and the added comment clarifies the purpose of this operation. This improves code maintainability.


77-79: Enhanced logging for legacy database access.

The added logging helps identify when the legacy byte array passphrase method is used and whether the passphrase is encrypted or unencrypted. This is valuable for debugging and security auditing.

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@OrangeAndGreen
Copy link
Contributor Author

@damagatchi retest this please

@OrangeAndGreen OrangeAndGreen merged commit 443a1ec into connect_qa Apr 17, 2025
1 of 2 checks passed
@OrangeAndGreen OrangeAndGreen deleted the dv/db_passphrase_fix branch April 17, 2025 14:21
@coderabbitai coderabbitai bot mentioned this pull request May 8, 2025
4 tasks
@coderabbitai coderabbitai bot mentioned this pull request Jul 21, 2025
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants