Skip to content

Conversation

@OrangeAndGreen
Copy link
Contributor

No ticket, fixing a quick bug for Jon.

Product Description

Fixes a special case where the user has transitioned to learning but hasn't completed a learn module yet. This ensures that the status stays in "learning" and doesn't revert to "available".

Technical Summary

The underlying issue is that the server doesn't send a status along with each job when we retrieve the jobs. So when parsing and storing the job data, we use a couple checks to determine the current status. Unfortunately, the check to determine whether we're in learning state is whether the user has >0 learn completion (i.e. they've completed at least one learn module).

When the user starts learning, the mobile code changes the status for the job locally to learning, but when the job gets downloaded again we calculate the status fresh from the payload, resulting in "available" status again. This is handled by taking whichever status is later in the workflow when comparing newly received jobs to what's already in storage. So if local knows we're in learning, we'll override available to learning before storing the job in the DB.

Feature Flag

Connect

Safety Assurance

Safety story

Small change to enforce expected behavior

Automated test coverage

None

QA Plan

Not required

Labels and Review

  • Do we need to enhance the manual QA test coverage ? If yes, the "QA Note" label is set correctly
  • Does the PR introduce any major changes worth communicating ? If yes, the "Release Note" label is set and a "Release Note" is specified in PR description.
  • Risk label is set correctly
  • The set of people pinged as reviewers is appropriate for the level of risk of the change

…status is farther than remote.

Handles a special case when transitioning to learning.
@coderabbitai
Copy link

coderabbitai bot commented Mar 14, 2025

📝 Walkthrough

Walkthrough

This pull request introduces an additional conditional block within the storeJobs method of the ConnectDatabaseHelper class. The updated logic compares the status of an existing job with an incoming job. If the status of the existing job is greater, the incoming job's status is updated to match the existing one. This change helps manage cases where the application has progressed to a learning phase while the server-side job status remains outdated. The modification is integrated into the pre-existing loop that processes incoming job records, ensuring consistent job management without altering the method's overall control flow.

Sequence Diagram(s)

sequenceDiagram
    participant DBHelper as ConnectDatabaseHelper.storeJobs
    participant Existing as ExistingJobRecord
    participant Incoming as IncomingJobRecord

    DBHelper->>Existing: Retrieve current status
    DBHelper->>Incoming: Retrieve new job status
    alt Existing.status > Incoming.status
        DBHelper->>Incoming: Update incoming status to existing status
    else
        DBHelper->>Incoming: Retain incoming status
    end
    DBHelper->>DBHelper: Persist job record
Loading

Suggested reviewers

  • shubham1g5

Tip

⚡🧪 Multi-step agentic review comment chat (experimental)
  • We're introducing multi-step agentic chat in review comments. This experimental feature enhances review discussions with the CodeRabbit agentic chat by enabling advanced interactions, including the ability to create pull requests directly from comments.
    - To enable this feature, set early_access to true under in the settings.

📜 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 489b81a and 39c62d2.

📒 Files selected for processing (1)
  • app/src/org/commcare/connect/ConnectDatabaseHelper.java (1 hunks)
🔇 Additional comments (1)
app/src/org/commcare/connect/ConnectDatabaseHelper.java (1)

344-349: Approve change to preserve the local learning status.

This change correctly addresses the issue described in the PR objective. The new conditional block ensures that when a local job has progressed to "learning" state, but the server still has it marked as "available", the local state is preserved. This prevents users from losing their learning progress status when job data is retrieved from the server.

The implementation is well-placed within the existing loop that processes job records and includes a clear comment explaining the purpose of the check.

✨ 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 OrangeAndGreen requested a review from avazirna March 14, 2025 15:13
Comment on lines +346 to +348
if(existing.getStatus() > incoming.getStatus()) {
incoming.setStatus(existing.getStatus());
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Can status ever change on server side ? I wonder if it can cause server changes to get overwritten in some cases ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not really since the server doesn't actually send a status for each job, just data that mobile uses to determine the status. Status changes do occur this way though, but only in the "forward" direction (i.e. increasing integer values), i.e. Available >> Learning >> Delivering.

That's why the check here only overrides the value when existing status is greater than incoming status.

Copy link
Contributor

@shubham1g5 shubham1g5 Mar 14, 2025

Choose a reason for hiding this comment

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

can we always do incoming.setStatus(existing.getStatus()); in that case to simplify the reasoning here to respect mobile statuses over server always. (Assuming that the final status will be same either way)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm, yeah, that could probably work. I was thinking there could be cases where a server-side change is the impetus for moving to a new state, but currently that's not ever the case.

But for example, if we were to add a special state for "assessment", i.e. the user completed all learn modules but hasn't passed the assessment yet. In a case like that, the user would submit an assessment form, and then sometime later mobile would learn (via the jobs API call) that the user had passed the assessment and progressed to delivery state.

So it seemed to me that allowing the server to move us forward in state could logically make sense, if not now then in the future. But nothing should ever move the user backward in the workflow, at least not as we've designed it so far.

Your thoughts?

Copy link
Contributor

Choose a reason for hiding this comment

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

Sounds good to me to keep it as it is based on your reasoning here.

Copy link
Contributor

@shubham1g5 shubham1g5 left a comment

Choose a reason for hiding this comment

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

Approving with an optional suggestion

@OrangeAndGreen OrangeAndGreen merged commit 934d93f into connect_qa Mar 15, 2025
1 of 2 checks passed
@OrangeAndGreen OrangeAndGreen deleted the dv/job_status_fix branch March 15, 2025 13:12
@coderabbitai coderabbitai bot mentioned this pull request Oct 8, 2025
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