Perseverate - "repeat or prolong an action, thought, or utterance after the stimulus that prompted it has ceased"
It helped me - a lot - to realize I was doing this - here's my journey.
I have to actively work against perseverating. A mentor told me, "Why do you let things live rent free in your head?" I realized that what I considered "idle time" for my mind was actually valuable and I shouldn't waste it.
I spent entire bike rides to/from work - or woke up in the middle of the night - replaying conversations - redoing arguments. It made me irritable and sad and defensive. I realized life is too short - of all the possible things I could be doing this was not a priority!
It wasn't an immediate change and the work is ongoing but I've tried to build habits to manage it. Initially I would distract myself when I realized I was starting, I would pinch myself. Gradually I was able to very deliberately try to start a different train of thought.
I try to think about a puzzle or riddle or mathematical challenge. I also preempt by listening to audio books, or at night reading about an interesting topic (thanks Wikipedia/astronomy!)