Fix: check if task.id is not null.

In run method, only change the history state if a task has been loaded.