Having a related party buy the shares back causes a problem. For instance, if taxpayer and spouse have separate brokerage accounts, and spouse buys shares sold by taxpayer, no good. Even if separate returns are filed.
Test appears to be whether the seller controls the purchase in the other account.