I had this a lot in my 20s, but I notice in my 30s that an interrupt won't derail me as much.
It's not that my brain is better at caching states, I think it's to do with being a better coder: meaningful comments, better proficiency in using the IDE, knowing when to not implement something from scratch,