Even if you select sorting and press F5, the location of the topics will always change. This is not sorting, this is pure randomness.
It's not really random, it's probably whatever the database (MySQL?) does when you don't specify a sort order. I'm guessing that when you sort by a column, it generates a SQL query that has only that column in the "order by" clause and no fallback sort that would be used in case there are multiple records with the same column value (e.g. multiple threads with 0 replies).
Something like this:
select thread_id, thread_title, ...
from threads
order by replies
Technically not exactly a bug as it's doing what you want it to do (since you're asking it to sort by replies), but surely inconvenient (since you can't specify additional sort order even if you wanted). A workaround in the code should be simple, just add e.g. thread id as the last part of the "order by", so that the resulting order is always defined the same way.
Like this:
select thread_id, thread_title, ...
from threads
order by replies, thread_id
Not sure what the problem is because the sorting by "Replies" works for me, without some duplicates here and there.
If I sort by Replies I get the first 31 pages with 0 replies and then 1 reply starts from page 32
And also the sort by "Started by" works as advertised. It orders by OP. It is true that the multiple threads opened by the same user are not sorted, but it is to be expected because there is no other keyword except ";sort=replies".
I couldn't reproduce the issue with replies, but it did happen with "started by" - the ETC pool thread id 1651959 appeared on page 6 and page 7, then after a few refreshes disappeared from both, then appeared only on page 6, etc (pun not intended).