Genius! Thank you so much for this, genuinely. Whatever this bug is has been preventing me from upgrading for months. I'd check updates once in a while and then just regress and go back to running 25.04. As soon as I hit ENTER key on the last line of the script, everything settled down immediately.
I think you can tell at what time the script was entered lol.