This is why I love plan mode and switch to it as soon as I see the agent starting to deviate from the plan because it hit a wall. Gotta get back to aligning on design decisions, approach, reverting any debug code, etc. before progressing. (Damn, I have more instructions to add to AGENTS.md lol)
Although this was more of an issue when using opusplan as Sonnet loves to do this. I only use Opus now if using Claude.