only to see the exact same code I've written in another question by another user.
If you see a question with the same code as another question asking the same thing, flag (or vote, at 3k+ reputation) the question as a duplicate of the first one.
What should I do?
I have been exactly where you are multiple times before. You should downvote such questions for not being clear or including enough prior research, and walk away. Especially if you are getting upset, as you say. There are always going to be other questions to answer where the asker won't rewrite their question five times over.
If a user is changing their question over and over again, you can leave a comment saying that that's not recommended, and in fact not allowed if the change invalidates an existing answer (such as yours).
But regardless, if it's starting to annoy you or frustrate you, the best course of action is to remove yourself.
If what OP is really wanting is truly so unclear that you can't guess at what the ultimate answer would be, you can flag the question for closure as "Unclear what you're asking". At 3,000 reputation, this option turns into a vote to close rather than a flag.
Regarding your concern about the user, there's no option to make any user-based note. Moderators have that ability, but it's private (for obvious reasons). However, the behavior you've described isn't really actionable by moderators thus far.
help-vampire
then watch someone else answer that and so on.