Correctly determin the last run of the command scheduler (see #5278)