loop with old memory overwriting updates

I’m having a problem with the AI ​​that’s gotten into a loop with the memory of an old version of the code, and every update attempt overwrites it without taking effect. The AI ​​can read the current code, knows where the error is, and how to fix it, but when it comes time to apply the fix, it applies code from two previous versions. Has anyone experienced this and managed to resolve it?
I tried several methods, but the one that worked best was the step-by-step process, but the last step returns the error as if nothing had been done.
Thanks!