Fix race in agent login