I've had another look at this.
A few debug outputs shows that the "error" arises when trying to remove
the node <KnuthNode at 734 4527603+682968-135942 line:10 prev:687
dem:11527.971465493918> while the list of active nodes contains
<KnuthNode at 734 4527603+682968-135942 line:10 prev:683
<KnuthNode at 734 4527603+682968-135942 line:10 prev:687
This removal, however, happens at the end of the algorithm, when the best
layout is chosen (just like Vincent pointed out), and in this situation a
node could be rightly be removed even if it's not the first one.
We could maybe add a boolean parameter to removeNode(), stating whether it
is allowed to remove the nodes out of order or not, and only the calls in
filterActiveNodes() would have it "true".