Skip to content

fix: run Course Optimizer extended-analysis export/upload as a background task - #466

Merged
djoseph-apphelix merged 4 commits into
release-ulmofrom
nsprenkle/course-optimizer-async-analysis
Sep 16, 2026
Merged

djoseph-apphelix merged 4 commits into
release-ulmofrom
nsprenkle/course-optimizer-async-analysis

Conversation

@nsprenkle

@nsprenkle nsprenkle commented Sep 9, 2026

Copy link
Copy Markdown
Member

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 existing export_olx / LinkCheckView pattern already used elsewhere in this module for exactly this shape of problem (expensive course-scoped work + client polling for status). CourseAnalysisReportView.post now just enqueues the task and returns 202 {"status": "pending"} immediately.

CourseAnalysisReportStatusView is unaffected by this change -- it already polls xpert-ai-workflows by 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 runId field 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

  1. Enable the contentstore.enable_course_optimizer_extended_checks waffle flag for a test course.
  2. Trigger a POST to /api/contentstore/v1/course_optimizer/analysis/{course_id} (e.g. via the frontend's "Start analysis" button) -- it should return 202 immediately rather than waiting for the export/upload to complete.
  3. Confirm a Celery worker log shows submit_course_analysis_report running and POSTing to xpert-ai-workflows.
  4. pytest cms/djangoapps/contentstore/rest_api/v1/views/tests/test_course_optimizer.py cms/djangoapps/contentstore/tests/test_tasks.py should pass.

…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
nsprenkle force-pushed the nsprenkle/course-optimizer-async-analysis branch from 8b6038d to bb2a5e1 Compare September 11, 2026 15:08
@nsprenkle
nsprenkle requested review from djoseph-apphelix and a lite review from Copilot September 11, 2026 15:08

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 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 Pending immediately 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.

Comment thread cms/djangoapps/contentstore/rest_api/v1/views/course_optimizer.py Outdated
Comment thread cms/djangoapps/contentstore/tasks.py Outdated
Comment thread cms/djangoapps/contentstore/tasks.py Outdated
nsprenkle and others added 2 commits September 11, 2026 11:25
…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>
Comment thread cms/djangoapps/contentstore/rest_api/v1/views/course_optimizer.py Outdated
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
djoseph-apphelix self-requested a review September 16, 2026 13:08
@djoseph-apphelix
djoseph-apphelix merged commit ebf3c36 into release-ulmo Sep 16, 2026
64 checks passed
@djoseph-apphelix
djoseph-apphelix deleted the nsprenkle/course-optimizer-async-analysis branch September 16, 2026 13:12
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