Skip to content

Conversation

@marslanabdulrauf
Copy link
Contributor

@marslanabdulrauf marslanabdulrauf commented Aug 20, 2025

Related Ticket

https://github.com/mitodl/hq/issues/8050

Important 💥

For all courses (with already cached block structure) we need to refetch and update the block structure using a management command:

./manage.py cms simulate_publish --receivers  openedx.core.djangoapps.content.block_structure.signals.update_block_structure_on_course_publish

Description

We are storing the cache for course outline from CMS and using the same cache in LMS and there were some problems.

  1. Imported a course with unpublished component
  2. CMS will cache the block_structure
  3. This Cache also contain unpublished component
  4. When learner go through that section (with unpublished unit) its never marked as complete on home page because it gets the course_outline from cache (which CMS set) and it include unpublished component whose completion will always be 0.0
  5. When that cache expires and LMS side fetches the course_outline, it does not store unpublished component and at that point progress is marked completed on home page -- However if something changes on CMS side and it overrides the cache we will again see not completed issue

This PR:

  1. Adds published_on field for xblock in BlockCompletionTransformer
  2. Excludes any unpublished component

Testing instructions

  1. Stay on master branch
  2. Create a course -- Add minimum number of component to complete
  3. Complete that course as learner
  4. Go to home page and check that the section is marked as complete (all green)
  5. Add two text components with any dummy data
  6. Delete one of them -- deleting component refreshes cache immediately
  7. Now refresh the learner home page -- Completed section should be greyed out now (not completed)
  8. Switch branch to this one marslan/8050-skip-unpublished-from-completion-stats
  9. Make sure it restarted and refresh the page, it should be fixed now.

NOTES:
Make sure to test user progress page, grading and instructor dashboard as well to see if they are working as expected

@openedx-webhooks openedx-webhooks added the open-source-contribution PR author is not from Axim or 2U label Aug 20, 2025
@openedx-webhooks
Copy link

Thanks for the pull request, @marslanabdulrauf!

This repository is currently maintained by @openedx/wg-maintenance-edx-platform.

Once you've gone through the following steps feel free to tag them in a comment and let them know that your changes are ready for engineering review.

🔘 Get product approval

If you haven't already, check this list to see if your contribution needs to go through the product review process.

  • If it does, you'll need to submit a product proposal for your contribution, and have it reviewed by the Product Working Group.
    • This process (including the steps you'll need to take) is documented here.
  • If it doesn't, simply proceed with the next step.
🔘 Provide context

To help your reviewers and other members of the community understand the purpose and larger context of your changes, feel free to add as much of the following information to the PR description as you can:

  • Dependencies

    This PR must be merged before / after / at the same time as ...

  • Blockers

    This PR is waiting for OEP-1234 to be accepted.

  • Timeline information

    This PR must be merged by XX date because ...

  • Partner information

    This is for a course on edx.org.

  • Supporting documentation
  • Relevant Open edX discussion forum threads
🔘 Get a green build

If one or more checks are failing, continue working on your changes until this is no longer the case and your build turns green.

Details
Where can I find more information?

If you'd like to get more details on all aspects of the review process for open source pull requests (OSPRs), check out the following resources:

When can I expect my changes to be merged?

Our goal is to get community contributions seen and reviewed as efficiently as possible.

However, the amount of time that it takes to review and merge a PR can vary significantly based on factors such as:

  • The size and impact of the changes that it introduces
  • The need for product review
  • Maintenance status of the parent repository

💡 As a result it may take up to several weeks or months to complete a review and merge your PR.

@github-project-automation github-project-automation bot moved this to Needs Triage in Contributions Aug 20, 2025
@mphilbrick211 mphilbrick211 moved this from Needs Triage to Ready for Review in Contributions Aug 21, 2025
@mphilbrick211 mphilbrick211 added the needs reviewer assigned PR needs to be (re-)assigned a new reviewer label Aug 21, 2025
@pdpinch
Copy link
Contributor

pdpinch commented Aug 21, 2025

Can you add a test for this?

Can @asadali145 or @Anas12091101 do a more thorough review?

@marslanabdulrauf marslanabdulrauf force-pushed the marslan/8050-skip-unpublished-from-completion-stats branch from 9f6bb16 to 83a754e Compare August 22, 2025 09:20
@arslanashraf7
Copy link
Contributor

arslanashraf7 commented Aug 25, 2025

I would let Asad/Anas review this but I had one thing in mind, How would it work in case of existing courses that have existing cache?

@marslanabdulrauf
Copy link
Contributor Author

Thanks @arslanashraf7 for pointing this out.

We need to re-create/update cache for all courses once we merge this using management command:
./manage.py cms simulate_publish --receivers openedx.core.djangoapps.content.block_structure.signals.update_block_structure_on_course_publish

@pdpinch
Copy link
Contributor

pdpinch commented Aug 25, 2025

@bradenmacdonald would you be willing to take a look at this bug fix for completion? Let us know if it needs further description, since the linked issue isn't public, and relies on courses that aren't public.

@bradenmacdonald
Copy link
Contributor

bradenmacdonald commented Sep 3, 2025

@pdpinch Sorry for the delay. Sure, I'll try to review this week.

Update: @ormsbee will review.

@ormsbee ormsbee self-requested a review September 3, 2025 18:30
@ormsbee
Copy link
Contributor

ormsbee commented Sep 3, 2025

I'm a bit confused here... shouldn't the block structures be generated exclusively from the published branch of the modulestore (and if they're not already, shouldn't they be fixed to be)? I don't understand why we would ever be building course blocks from the draft branch.

@ormsbee
Copy link
Contributor

ormsbee commented Sep 3, 2025

If the fundamental problem is that this is evaluating user completion of a content state that they're not seeing (because it's draft), then even this fix will have gaps in it. For instance, what happens when you've moved a component from one place to another in the draft but haven't published it? It will aggregate into the wrong containers for that user.

Maybe it's an artifact of the fact that the collect phase of block structures used to happen only in LMS workers, and so we didn't explicitly specify the published branch when doing content data collection?

@marslanabdulrauf
Copy link
Contributor Author

Maybe it's an artifact of the fact that the collect phase of block structures used to happen only in LMS workers, and so we didn't explicitly specify the published branch when doing content data collection?

I checked and found that we have ALTERNATE_ENV_TASKS for block_structure and they are supposed to cache the block structure in LMS env which means they shouldn't be caching from draft branch 🤔

We have celery_route defined for both apps so when we get this task in CMS we want LMS worker/queue to run it in LMS however as we are still in CMS env will this code chunk get the CELERY_QUEUES matching .lms. ?

I haven't tested this part yet.

@marslanabdulrauf
Copy link
Contributor Author

We have celery_route defined for both apps so when we get this task in CMS we want LMS worker/queue to run it in LMS however as we are still in CMS env will this code chunk get the CELERY_QUEUES matching .lms. ?

Verified => We have ALTERNATE_WORKER_QUEUE defined and I verified that the update_course_in_cache are being run in LMS workers with modulestore branch published-only

Looking into any possibility where we might be caching the content using draft-preferred branch.

@ormsbee
Copy link
Contributor

ormsbee commented Sep 8, 2025

Is it possible that it's some sort of race condition where it's reading the older published state from one of the other MongoDB instances in the replica set before the writes have a chance to propagate?

@marslanabdulrauf
Copy link
Contributor Author

Is it possible that it's some sort of race condition where it's reading the older published state from one of the other MongoDB instances in the replica set before the writes have a chance to propagate?

Could be, but still LMS should only get published-only content even from outdated state. My assumption at the moment was CMS is caching the content before LMS, not from update_course_in_cache because these are supposed to be run in LMS env, and LMS is using that cache.

@marslanabdulrauf
Copy link
Contributor Author

There has been some development, I am unable to reproduce it locally now with proper celery setup.

I went through the tasks and there is no task on CMS side to cache the blocks except the one which we have mapped to run in lms environment.

If for any reason this task gets executed in CMS then we get draft branch block structure which caused this issue.

We can mark this PR as draft/stale till we figure out if its related to edX core.

@ormsbee
Copy link
Contributor

ormsbee commented Sep 8, 2025

Could you please create a PR to explicitly read from the published branch so that we always get the right version regardless of which process reads it?

@marslanabdulrauf
Copy link
Contributor Author

Could you please create a PR to explicitly read from the published branch so that we always get the right version regardless of which process reads it?

Yeah sure.

@marslanabdulrauf
Copy link
Contributor Author

Hi @ormsbee, thank you for your time and input on this issue.
I have created another PR as you suggested to update manager to only get block structure from published-only branch.

@mphilbrick211
Copy link

Hi @ormsbee, thank you for your time and input on this issue. I have created another PR as you suggested to update manager to only get block structure from published-only branch.

Bumping for you, @ormsbee

@mphilbrick211 mphilbrick211 removed the needs reviewer assigned PR needs to be (re-)assigned a new reviewer label Sep 24, 2025
@mphilbrick211 mphilbrick211 moved this from Ready for Review to In Eng Review in Contributions Sep 24, 2025
@pdpinch
Copy link
Contributor

pdpinch commented Sep 30, 2025

@marslanabdulrauf this can be closed, right?

@marslanabdulrauf
Copy link
Contributor Author

yes

@marslanabdulrauf
Copy link
Contributor Author

Closing this PR as the underlying issue is fixed in another PR

@github-project-automation github-project-automation bot moved this from In Eng Review to Done in Contributions Oct 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

open-source-contribution PR author is not from Axim or 2U

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

7 participants