Fix cwd race conditions