Ensures that dependencies have at least as high priority as dependents

This recursively passes priorities down to dependents so if task A depends on task B, task B must have at least as high a priority as A. This avoids situations where extremely high priority tasks only end up running after all the low-priority tasks have finished because it depends on the one that runs last.
You're right that there are cases where update_priority has n^2 complexity. This could be fixed by doing the updates all at once in topological sort order so that by the time you get to a node you've already updated its priority from all of its dependents. This could be done entirely in the worker if we do the topological sort thing I mentioned earlier, or entirely in the scheduler after the worker is done scheduling and asks for its first task. With the second method, we wouldn't need to do a topological sort in the worker during scheduling (not yet, at least).