UPDATE tasks SET state = 'finished' WHERE state = 'idle' AND stage_output != '';