Another example of unpredictable automation behaviour, I can post a project file if needs be, but it's fairly easy to reproduce. It seems to happen when you have a lower segment surrounded by slopes, as shown in the gif
Here's a project showing the issue, though this one merges the previous point, rather than swapping the order of the end one and the next. Unfortunately I can't find the project that reproduced the original bug, but I know it'll come back to bite me at some point. I'll make sure I post it here when it pops up again