better logic to deal with missing agent.sh or dead agent process