This would seem to be a decent solution. But I don’t understand why this is happening in the first place? Why is Discourse adding page numbers that don’t exist to the sitemap?
In the case of the topics I’m examining with this issue there are no deleted posts or other modifications to the threading.