for those unaware: if you send an unfollow and refollow too closely to each other, the unfollow might fail due to desync issues, then get retried after the follow is successfully processed... which destroys the *new* follow.
from my experience, akkoma makes 5 attempts, with retry intervals of about 15 minutes, so you should wait at least 1 hour and possibly a bit more depending on processing time for other activities (in case the server is under any amount of load and isn't processing activities ~instantly).
servers making use of exponential backoff strategies might take even longer, although i haven't personally observed any.
here's a snapshot of the results of what people thought before this post was made.
i'm not aware of any fedi software that warns about this, and arguably there are things that can mitigate this -- say for example fedi servers were required to store and compare specific ids of Follow activities, so that you can Undo them unambiguously. that does create an issue of what to do if you no longer have the follow id anymore... maybe a safety valve property that signals "undo any existing follow before this timestamp". but this requires agreement and updates to existing servers...
on multiple occasions, i've had people unable to follow me because they sent a Follow that got dropped, then tried to unfollow-and-refollow after whatever issue got fixed. i'm not sure at what point we get to say "hey, maybe the fedi Follow State Machine model is broken". this isn't the only issue with follows desyncing. desyncs happen more than most people realize. maybe that person you're "following" hasn't been sending you their posts. maybe you've got "followers" who aren't seeing yours.