The Community user automatically removes an auto-generated "possible duplicate" comment when the post gets closed. For example,
When there's already an existing comment with the same duplicate link (such as when the user first comments and then votes to close), an auto-generated comment is not created.
However, Community still tries to remove a comment with the dupe link (possibly by attempting to find the right one using regexes), and messes up in cases where there's more than one comment by the same user, as in this question.
This might be related to the fact that both comments have
duplicate* in them, and the bot just removes the last one it finds. Can this be made more robust, so that the bot doesn't remove anything more than it needs to?