I ran into the same problems you did, any variable leads to an exponentially large state. Other than, "scoping" as you put (or branch merging as I put it), the most space-efficient way I found to keep state was to ask the player to remember a passcode. So the player can keep track of the state, but I don't have to (ie. exponential space savings!). Even when entering the password, you can keep the space small (n*2 rather than 2^n) see [0]. Players used to retro PC games will remember entering passwords found in their instruction manual, so it's an added nostalgic appeal.
Let me know when your error dialogs game is done. If you want to collaborate on some games, hit me up, I too love games where they shouldn't be.
0: https://github.com/mmulet/code-relay/blob/main/markdown/how/...