Fix stateful retry bugs