registerLocalDocument always did a plain insert, so retrying a document whose first OCR attempt failed created a new duplicate row each time instead of updating the existing one. Now looks up an existing (case_id, filename) match and updates it in place.