Try doing
(Or b).Code:fastboot --set-active=a
There is a boot slot bug currently that exists in TWRP with Treble.
That's the only way I could imagine it causing it.
You can tell if you are effected by this bug by trying to change slot in TWRP, seeing it's changed, then rebooting recovery and noticing it's still stuck on the first slot.
The fastboot command will solve that.
If that's not the problem, then it's not the partitions to blame. OpenGapps sounds buggy and could be reporting wrong version when a ROM isn't even detected at all (because of slot bug).
But you said you even flashed stock ROM in MiFlash, and it still happens.
If you made a backup of your ROM with my Low-level Backup Tool, like I strongly suggested, you will get back a 100% clean stock style partition when you restore it. And if it still happens then, then it's obviously not a problem with the partitions.
The other way to get back a 100% clean stock system with partitions is with MiFlash in EDL mode, but this will wipe your MAC's and IMEI. So you should of made a Low-level backup either way.
Thanks for help, but I get this error when trying to use the command.