add ipc.Logout to close_work
simplify agent close defer func