fix(api): tolerate duplicate upload_session_files rows in media maintenance lookup #943

Merged
chris merged 2 commits from fix/media-maintenance-duplicate-usf into main 2026-09-28 17:40:02 +02:00
Owner

Summary

  • requireOwnedMedia crashed with IncorrectResultSizeDataAccessException (HTTP 500) on POST /api/media/{id}/reset-faces whenever a media item had multiple upload_session_files rows — which the upload dedup path produces on re-upload of an identical photo (original processing_queued + later skipped_duplicate rows, all with committed_media_item_id set). Hundreds of affected items in production.
  • Fix: pick usf columns via correlated scalar subqueries (earliest row) instead of a plain LEFT JOIN + singleRow(). Same treatment for ownerMediaForPixelProcessing and ownerMediaMissingDimensions (duplicates would double-enqueue jobs / double-count scans).
  • LATERAL was considered but is not parseable by the H2 test harness; scalar subqueries are semantically equivalent and run on both H2 and Postgres.

Tests

  • New regression test: resetFaces succeeds with two usf rows (oldest jpeg original + newest png duplicate) and the re-queued discovery job payload carries the oldest row's detectedFormat.
  • Full rtk ./gradlew :apps:api:test green.

Found but intentionally not touched (follow-up candidates)

  • SearchService count/backfill feeds, WorkerJobEnqueueService backfill feeds, DiscoveryReprocessScheduler, UserDiscoveryService batches: same latent fan-out class (duplicate job enqueues per pass), no crash. ProcessingIssueService self-heals.

Unblocks the EXIF face-box migration (companion to PR #942).

## Summary - `requireOwnedMedia` crashed with `IncorrectResultSizeDataAccessException` (HTTP 500) on POST /api/media/{id}/reset-faces whenever a media item had multiple `upload_session_files` rows — which the upload dedup path produces on re-upload of an identical photo (original `processing_queued` + later `skipped_duplicate` rows, all with `committed_media_item_id` set). Hundreds of affected items in production. - Fix: pick usf columns via correlated scalar subqueries (earliest row) instead of a plain LEFT JOIN + `singleRow()`. Same treatment for `ownerMediaForPixelProcessing` and `ownerMediaMissingDimensions` (duplicates would double-enqueue jobs / double-count scans). - LATERAL was considered but is not parseable by the H2 test harness; scalar subqueries are semantically equivalent and run on both H2 and Postgres. ## Tests - New regression test: resetFaces succeeds with two usf rows (oldest jpeg original + newest png duplicate) and the re-queued discovery job payload carries the oldest row's `detectedFormat`. - Full `rtk ./gradlew :apps:api:test` green. ## Found but intentionally not touched (follow-up candidates) - SearchService count/backfill feeds, WorkerJobEnqueueService backfill feeds, DiscoveryReprocessScheduler, UserDiscoveryService batches: same latent fan-out class (duplicate job enqueues per pass), no crash. ProcessingIssueService self-heals. Unblocks the EXIF face-box migration (companion to PR #942).
chore: version bump 1.21.55
All checks were successful
Wiki Sync / Sync wiki from docs (push) Has been skipped
Build and Deploy / Detect changed services and test scopes (push) Successful in 3s
Build and Deploy / Android unit tests and debug APK (push) Has been skipped
Build and Deploy / Smoke API and media worker (push) Has been skipped
Build and Deploy / Smoke web (push) Has been skipped
Build and Deploy / Smoke ML worker (push) Has been skipped
Build and Deploy / Smoke people worker (push) Has been skipped
Build and Deploy / Build postgres image (push) Has been skipped
Build and Deploy / Build plants worker image (push) Has been skipped
Build and Deploy / Build converter worker image (push) Has been skipped
Build and Deploy / Deploy postgres (push) Has been skipped
Build and Deploy / Build API image (push) Has been skipped
Build and Deploy / Build media worker image (push) Has been skipped
Build and Deploy / Build ML worker image (push) Has been skipped
Build and Deploy / Build people worker image (push) Has been skipped
Build and Deploy / Build web image (push) Has been skipped
Build and Deploy / Deploy API (push) Has been skipped
Build and Deploy / Deploy web (push) Has been skipped
Build and Deploy / Deploy media worker (push) Has been skipped
Build and Deploy / Deploy ML worker (push) Has been skipped
Build and Deploy / Deploy plants worker (push) Has been skipped
Build and Deploy / Deploy people worker (push) Has been skipped
Build and Deploy / Deploy converter worker (push) Has been skipped
Build and Deploy / Clean Docker build artifacts (push) Has been skipped
Build and Deploy / Run scoped PR tests (push) Successful in 1m57s
e26e2560de
chris merged commit a7affc89b8 into main 2026-09-28 17:40:02 +02:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
chris/memories!943
No description provided.