Need to remove from pendingTasks not only when there is a non-empty set of tasks associated with the stage being removed, but also when the associated set is empty.  The non-empty case indicates that something went wrong elsewhere, but the empty case is normal operation.