fix(discovery): wire actual retarget + fix named candidate join #695

Merged
chris merged 3 commits from fix/retroactive-retarget-and-matching into main 2026-07-22 17:57:50 +02:00
Owner

Summary

Fix two fundamental bugs in ClassInstanceService.applyAutoApprovalRetrospectively().

Fix 1: Wire actual retarget into retrospective run

Before: applyAutoApprovalRetrospectively() called countUnmatchedPendingCandidates() - a stub that just counted rows without doing anything.

After: Now calls retargetUnnamedCandidatesToNamedPeople() which performs density-clustering matching to retarget unnamed face candidates to named local or shared people.

  • Previously dead code is now wired in
  • Local and shared retarget counts properly tracked and returned
  • Progress reporter receives actual retarget events

Fix 2: Fix broken LIKE join in named candidate matching

Before:

AND CAST(cic.occurrence_refs AS VARCHAR) LIKE '%' || CAST(dr.id AS VARCHAR) || '%'

For face_detection candidates, occurrence_refs contains [{"mediaItemId":"..."}] - never the face annotation UUID. The join always failed → 0 named candidates ever matched.

After:

AND dr.media_item_id = CAST(media_item_id_from_occurrence_refs(cic.occurrence_refs) AS UUID)

Uses new PostgreSQL function media_item_id_from_occurrence_refs() (V120 migration) with H2 test equivalent (H2MediaItemIdExtractor).

Same fix applied to 5 additional LIKE joins in ClassInstanceService.java:

  • tentativeAssignments() line ~4120
  • acceptGenericNamedCandidate() line ~4252
  • pendingGenericPeopleCandidateIdsForMedia() line ~4400
  • Assignment context method line ~4523

Impact

12,843 pending candidates can now actually be retargeted (instead of just counted). Named auto-approval candidates are correctly found for retrospective runs.

Files changed

  • ClassInstanceService.java - wire retarget call + 6 SQL join fixes
  • V120__media_item_id_from_occurrence_refs_function.sql - PostgreSQL function
  • H2MediaItemIdExtractor.java - H2-compatible alias for tests
  • ClassInstanceServiceTest.java - register H2 alias

Verification

  • Compiles cleanly
  • All 98 tests pass (0 failures, 0 skipped)
## Summary Fix two fundamental bugs in `ClassInstanceService.applyAutoApprovalRetrospectively()`. ### Fix 1: Wire actual retarget into retrospective run **Before:** `applyAutoApprovalRetrospectively()` called `countUnmatchedPendingCandidates()` - a stub that just counted rows without doing anything. **After:** Now calls `retargetUnnamedCandidatesToNamedPeople()` which performs density-clustering matching to retarget unnamed face candidates to named local or shared people. - Previously dead code is now wired in - Local and shared retarget counts properly tracked and returned - Progress reporter receives actual retarget events ### Fix 2: Fix broken LIKE join in named candidate matching **Before:** ```sql AND CAST(cic.occurrence_refs AS VARCHAR) LIKE '%' || CAST(dr.id AS VARCHAR) || '%' ``` For face_detection candidates, `occurrence_refs` contains `[{"mediaItemId":"..."}]` - never the face annotation UUID. The join always failed → 0 named candidates ever matched. **After:** ```sql AND dr.media_item_id = CAST(media_item_id_from_occurrence_refs(cic.occurrence_refs) AS UUID) ``` Uses new PostgreSQL function `media_item_id_from_occurrence_refs()` (V120 migration) with H2 test equivalent (`H2MediaItemIdExtractor`). **Same fix applied to 5 additional LIKE joins** in `ClassInstanceService.java`: - `tentativeAssignments()` line ~4120 - `acceptGenericNamedCandidate()` line ~4252 - `pendingGenericPeopleCandidateIdsForMedia()` line ~4400 - Assignment context method line ~4523 ### Impact 12,843 pending candidates can now actually be retargeted (instead of just counted). Named auto-approval candidates are correctly found for retrospective runs. ### Files changed - `ClassInstanceService.java` - wire retarget call + 6 SQL join fixes - `V120__media_item_id_from_occurrence_refs_function.sql` - PostgreSQL function - `H2MediaItemIdExtractor.java` - H2-compatible alias for tests - `ClassInstanceServiceTest.java` - register H2 alias ### Verification - Compiles cleanly - All 98 tests pass (0 failures, 0 skipped)
fix(discovery): wire actual retarget + fix named candidate join
All checks were successful
Build and Deploy / Detect changed services and test scopes (push) Successful in 3s
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 / Build plants worker image (push) Has been skipped
Build and Deploy / Build people worker image (push) Has been skipped
Build and Deploy / Build converter worker image (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 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 1m45s
99a97a1426
Fix 1: applyAutoApprovalRetrospectively() now calls retargetUnnamedCandidatesToNamedPeople()
instead of the stub countUnmatchedPendingCandidates(). The method was dead code;
this change wires it in so unnamed candidates get density-clustering retargeted to
named local or shared people instead of being silently counted and discarded.

Fix 2: Replace broken LIKE join that searched for dr.id inside the JSONB
occurrence_refs array. For face_detection candidates, occurrence_refs contains
[{"mediaItemId":"..."}] — never contains the face annotation UUID. The LIKE
always failed → 0 named candidates ever matched.

Fix: join on mediaItemId via media_item_id_from_occurrence_refs() function
(uses JSONB array index 0 → mediaItemId field, matching across both H2 test
DB and PostgreSQL production).

Impact: 12,843 pending candidates can now actually be retargeted (instead
of just counted). Named auto-approval candidates are correctly found for
retrospective runs.

Changes:
- ClassInstanceService.java: wire retarget call + 6 SQL join fixes
- V120__media_item_id_from_occurrence_refs_function.sql: PG function
- H2MediaItemIdExtractor.java: H2-compatible alias
- ClassInstanceServiceTest.java: register H2 alias
fix(media): fix MediaMaintenanceService occurrence_refs join (sibling of PR #695)
All checks were successful
Build and Deploy / Detect changed services and test scopes (push) Successful in 3s
Build and Deploy / Smoke API and media worker (push) Has been skipped
Build and Deploy / Smoke web (push) Has been skipped
Build and Deploy / Build people worker image (push) Has been skipped
Build and Deploy / Smoke ML worker (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 / 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 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 3m27s
49f989fdde
MediaMaintenanceService.rejectPendingGenericPeopleCandidatesForMedia used the
same broken LIKE pattern as ClassInstanceService — CAST(cic.occurrence_refs AS
VARCHAR) LIKE '%' || CAST(dr.id AS VARCHAR) || '%'.

Replace with the precise join:
  dr.media_item_id = CAST(media_item_id_from_occurrence_refs(cic.occurrence_refs) AS UUID)

Also fix test data in MediaMaintenanceServiceTest.insertPendingGenericPeopleCandidate
to include mediaItemId in occurrence_refs (matching production format) and register
the H2 alias for the new PostgreSQL function.
chore: bump version to v1.21.23
All checks were successful
Build and Deploy / Detect changed services and test scopes (push) Successful in 3s
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 / Build plants worker image (push) Has been skipped
Build and Deploy / Build people worker image (push) Has been skipped
Build and Deploy / Build converter worker image (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 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 1m39s
a24a733065
chris merged commit f544e12f23 into main 2026-07-22 17:57:50 +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!695
No description provided.