I should elaborate - I made the assumption that the change was obvious.

if (pendingTasks.contains(stage)) {
  if (!pendingTasks(stage).isEmpty) logDebug ...
   pendingTasks -= stage
}

Update pendingTasks only if it is known to contain the stage.
I am not sure how common it is for pendingTasks not to have the stage - but I would assume it is fairly common : so avoid unnecessary re-search