This is a good question. It’s been a long, long time since I’ve looked at this code. The intent should be to preserve the input order of nodes, per your question.
It’s not obvious where the bug is. Wonder if it relates to the implementation of union_find for collapsing clusters, and the implementation of build_ranks called from expand_cluster. I’ll look at this a little further. There are a lot of latent semantics in the way lists are built that could have been made more explicit.