Find the invalid rows before changing anything.

Repair a copy first and compare row counts.

Apply the repair in place.

Re-run the failing spatial query.

Guard the write path so it does not come back.