Update job state after task not found on agent

This used to be done as part of an event handler triggered whenever the
task's state was updated, but it no longer is, because of a race
condition, so now we need to do it manually.