In grade_grade::notify_changed there is a bit of code to prevent it from being executed during restore. This check no longer works as I think the restore_ui (or similar) class was refactored.
Not entirely sure how the old code worked before, but moving forward, the solution should not depend on restore_ui class since one can easily restore a course in the code by using the restore_controller and therefore, never use restore_ui or create a $restore global.
A suggested solution would be to create a class that is capable of being auto-loaded. Have a static property on the class to keep track if restore is running. Toggle that flag on/off in the restore_controller::execute_plan(). Check that property in the grade_grade::notify_changed() to prevent notification during restores. The reason for the autoloading is to reduce the overhead of having to include something like backup/util/includes/restore_includes.php to safely check against the restore_controller directly. We need reduced overhead since this will constantly be checked whenever a grade has changed.