Target undo op not found

IIRC CollectionOps are serialized, so if you wrap your code in it, it should prevent other operations from interleaving with yours. That will also avoid hanging the UI if it takes too long.

Please note that changing the cards like this during review (whether in a CollectionOp or not) is going to waste a fair few CPU cycles and lead to slower display of the next card, as it will cause the queues to be rebuilt after every card is answered. A more efficient approach would be to do this processing in bulk, when the user is not in the middle of reviews.