[Core] Fix unstable sort for unordered atoms.