When working on complex tasks, it’s easy to get sucked into it and not see the wood for the trees. One of the best solutions is to talk it through with someone. Often, as you are explaining it, you will realise that it’s not doing what you just said, but something different. You also sometimes realise that your solid logic is far less logical than it seemed, inside your own head.
Critically, none of these actually require the knowledge or interaction of the person you are talking to. Rather than explaining it to a colleague, and wasting their time, some people use an inanimate object. A rubber duck has become a common method. It’s small, easy to source, and can sit on top of a monitor etc, with a face to talk too. Other personified toys also work just as well, as do pets, babies, or life partners etc.
Basically, it’s a method of breaking a bad cycle, by getting out of your own head, and so realise where you keep f*****g up.
Tiny rubber ducks are actually dirt cheap from china. Keep a few in your pocket/desk, and hand them out when it happens.