I'm not 100% sure what I'd do to detect this for shells specifically, maybe prompt the user, but my toy harness scolds refuses to re-read files because the previous iteration of GLM was room-looping on that. Clearly something that they need to work on.
It feels like all these models are missing a long horizon orchestrator of some kind. Humans don't think in a single thread, they have thoughts that appear, pause and disappear.
The reason humans don't go into a doom loop is because of this ability of other thoughts to interject and say, no this is stupid.