ARTICLE AD BOX
I'm experiencing a persistent gradebook issue on our Moodle site and have exhausted most standard fixes. Hoping someone here has encountered this before.
Environment
Moodle version: 4.1.2
PHP: 8.2
Database: MySQL
Hosting: cPanel
Site: Canberra Business and Technology College
The Problem
The gradebook for one specific course is permanently stuck on the "Recalculating grades" screen. It never resolves and the report never loads.
What We've Already Tried
PHP & Cron Fix
Identified cron was running on wrong PHP version (7.4 instead of 8.2)
Updated cron path to use correct PHP 8.2 binary
Cron is now running successfully with no PHP errors
Database Fixes
Reset all grade item flags: UPDATE mdlf0_grade_items SET needsupdate = 0 WHERE courseid = 156
Cleared grade values: UPDATE mdlf0_grade_grades SET finalgrade = NULL, rawgrade = NULL
Deleted stuck adhoc tasks: DELETE FROM mdlf0_task_adhoc WHERE classname LIKE '%grade%' AND customdata LIKE '%156%'
Cleared gradebook cache flags: DELETE FROM mdlf0_cache_flags WHERE flagtype = 'gradebook'
Bumped course cacherev: UPDATE mdlf0_course SET cacherev = cacherev + 1 WHERE id = 156
Reset scheduled task fail delays and next run times
Cache & Session Cleanup
Purged all Moodle caches via Admin UI
Truncated mdlf0_sessions table
Restarted server (no impact)
Current State After All Fixes
✅ Cron running successfully
✅ No PHP errors
✅ All grade items show needsupdate = 0 and locked = 0
✅ Grade categories show no obvious corruption
❌ Gradebook still stuck on "Recalculating grades"
❌ Scheduled tasks repeatedly show "ASAP" (looping)
❌ Grade cron runs but makes no writes
What I've Checked
mdlf0_grade_items for course 156: all items have needsupdate = 0, locked = 0
mdlf0_grade_categories for course 156: no locked column exists in our schema
No broken calculation formulas found
No missing grade items
Questions
What else could cause the gradebook to remain in "Recalculating" state when needsupdate = 0 for all items?
Is there another table or flag that controls this recalculating state that I may have missed?
Has anyone seen the grade cron loop repeatedly without writing any data?
Is a course backup and restore the only remaining option at this point?
