The -walletnotify and UI notification dispatch for the transaction update happens in AddToWallet. Ideally we'd want to do this invalidation before the notification is launched to prevent races.
One idea would be to move this logic here: https://github.com/bitcoin/bitcoin/blob/master/src/wallet.cpp#L566 where previously the WalletUpdateSpent happened? (execution will get there anyway through AddToWalletIfInvolvingme as fExisted will be true as well as fUpdate)