It’s not really a fix — your modified code still performs the same operation, just with an extra loop triggering the same function again. That doesn’t solve the problem (and in fact, it didn’t).
The root cause occurs when, during or immediately after a trade, one or both trading players switch to another core and request a DB load.
After the load, the item reverts to its previous owner and gets saved there again.
So yes, at that moment, there are technically two instances of the same item. This state persists until the other character also performs a load request — at which point the item is removed from their inventory.
In short, there’s no definitive fix for this. However, if you add an exchange-time check to functions that can move a player to another core (like channel switch or warp), this issue won’t happen during normal operations.
But if the client crashes or is force-closed during a trade, the problem can still reoccur.