fix: run Course Optimizer extended-analysis export/upload as a background task - #466
Merged
djoseph-apphelix merged 4 commits intoSep 16, 2026
Merged
Conversation
…ound task CourseAnalysisReportView.post previously exported and compressed the course, then uploaded it to xpert-ai-workflows, synchronously inside the request thread -- large courses could tie up a Studio web worker long enough to hit a proxy/gateway timeout. Moves that work into a new Celery task (submit_course_analysis_report, mirroring export_olx/LinkCheckView's existing pattern in this module) so the view returns 202 immediately. CourseAnalysisReportStatusView is unaffected -- it already polls xpert-ai-workflows by course id, not run id, so no run-tracking state needed to be added on the Studio side to support this. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
nsprenkle
force-pushed
the
nsprenkle/course-optimizer-async-analysis
branch
from
September 11, 2026 15:08
8b6038d to
bb2a5e1
Compare
nsprenkle
requested review from
djoseph-apphelix
and
a lite review from Copilot
September 11, 2026 15:08
There was a problem hiding this comment.
🟡 Changes recommended
Run visibility, failure reporting, and task time limits remain unresolved.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
This pull request moves Course Optimizer export and upload processing into a background Celery task.
Changes:
- Adds
submit_course_analysis_report. - Returns
202 Pendingimmediately from the POST endpoint. - Updates task and API tests.
Unresolved findings include critical run visibility and task time-limit issues, plus a moderate failure-reporting issue.
File summaries
| File | Summary |
|---|---|
cms/djangoapps/contentstore/tests/test_tasks.py |
Tests background task behavior. |
cms/djangoapps/contentstore/tasks.py |
Adds the export/upload Celery task. |
cms/djangoapps/contentstore/rest_api/v1/views/tests/test_course_optimizer.py |
Tests asynchronous API behavior. |
cms/djangoapps/contentstore/rest_api/v1/views/course_optimizer.py |
Queues analysis work and returns immediately. |
Review details
- Files reviewed: 4/4 changed files
- Comments generated: 3
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
…alysis export Address Copilot review feedback on the async course-analysis export task: - CourseAnalysisReportView now marks the run pending in cache before queuing submit_course_analysis_report. The status endpoint checks that marker first, so a course with an older completed run doesn't look done again the moment a new run is requested -- previously the status proxy had nothing but a stale/absent xpert-ai-workflows run to report during that window, and the new run could never be observed. - submit_course_analysis_report now records export/upload failures (including hitting its own time limit) as a terminal 'failed' status in that same cache entry, instead of leaving the status endpoint to poll a stale 404 forever after a transient error. - The task gets explicit soft/hard Celery time limits, configurable via settings, so a pathological or very large course export can't occupy a worker indefinitely. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
The pending/failed cache entry CourseAnalysisReportView/ submit_course_analysis_report use to bridge the async export gap (ea9a0d0) used lowercase 'pending'/'failed', but every other status this endpoint ever returns -- proxied straight from xpert-ai-workflows -- is uppercase ('PENDING', 'RUNNING', 'COMPLETE', 'FAILED'). The frontend's PipelineStatus type and active-status check only recognize the uppercase form, so the lowercase marker would have been treated as an unrecognized/inactive status -- silently breaking polling during exactly the window this was meant to cover. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
If submit_course_analysis_report.delay() raises because the broker is unavailable, the PENDING marker written just before it would otherwise stay cached for COURSE_ANALYSIS_REPORT_CACHE_TIMEOUT_SECONDS even though no task was ever queued, leaving the status endpoint reporting pending for a run that will never start. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
djoseph-apphelix
self-requested a review
September 16, 2026 13:08
djoseph-apphelix
approved these changes
Sep 16, 2026
djoseph-apphelix
deleted the
nsprenkle/course-optimizer-async-analysis
branch
September 16, 2026 13:12
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Follow-up to #426, switch export and compression of course content to asynchronous task, avoiding a possibility that large courses could tie up a web worker long enough to hit a proxy/gateway timeout.
This moves that work into a new Celery task,
submit_course_analysis_report, mirroring the existingexport_olx/LinkCheckViewpattern already used elsewhere in this module for exactly this shape of problem (expensive course-scoped work + client polling for status).CourseAnalysisReportView.postnow just enqueues the task and returns202 {"status": "pending"}immediately.CourseAnalysisReportStatusViewis unaffected by this change -- it already pollsxpert-ai-workflowsby course id (GET /courses/{course_id}/runs/latest), not by run id, so no Studio-side run-tracking state needed to be added to support the async POST.Supporting information
Companion PR (same change on the frontend side): edx/frontend-app-authoring#114. Beyond removing the now-unused
runIdfield from the POST response, that PR also fixes the frontend's status-polling hook, which previously treated "no run yet" (a null/404 result) the same as an actively-pending run and polled every 2s indefinitely -- that's now fixed to only poll while a run is genuinely in progress, so the gap between "POST accepted" and the background task reaching xpert-ai-workflows is covered by the frontend's own invalidation on a successful start, not by speculative polling.Testing instructions
contentstore.enable_course_optimizer_extended_checkswaffle flag for a test course./api/contentstore/v1/course_optimizer/analysis/{course_id}(e.g. via the frontend's "Start analysis" button) -- it should return202immediately rather than waiting for the export/upload to complete.submit_course_analysis_reportrunning and POSTing toxpert-ai-workflows.pytest cms/djangoapps/contentstore/rest_api/v1/views/tests/test_course_optimizer.py cms/djangoapps/contentstore/tests/test_tasks.pyshould pass.