fix(discovery): ranking endpoints honor pinned/accepted representative thumbnails #1092
Loading…
Reference in a new issue
No description provided.
Delete branch "fix/ranking-thumbnail-representative"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Symptom
The people-picker dropdown ("choose another person") in the discovery suggestions UI shows the newest tentative face of a person instead of the user-selected / confirmed thumbnail. Introduced behaviorally by #1088 (picker reuses the card's prefetched ranking rows) + #1089 (ranking latency fix made the fast path reliable): the ranking path now wins where it used to time out into the fallback. The SQL itself predates #1089.
Root cause
All three ranking endpoints (
personRanking,mergeTargetRankings,mergeSuggestion) re-derivedthumbnail_urlwith a subquery that ignoresclass_instances.representative_occurrence_idand orders by newest of EITHER state:So a newer tentative (auto-assigned, unconfirmed) face outranked the pinned or accepted representative.
Fix shape
One shared constant
REPRESENTATIVE_FACE_THUMBNAIL_SUBQUERYinterpolated into the same three statements (still one statement each), selecting:ORDER BY CASE WHEN cio3.id = ci.representative_occurrence_id THEN 0 ELSE 1 END(the pin is accepted-only by construction, seesetRepresentativeOccurrence);CASE WHEN cio3.state='accepted' THEN 0 ELSE 1 END, recency only as tiebreaker within a state;ClassInstanceService.representativeEnrichmentForPeople), falling back to null; unnamed instances keep the tentative crop as last-resort fallback (accepted ranks first).Thumbnail selection only: scores, ADR 0109 multi-representant ranking semantics, occurrence counts, row sets, response DTO shapes and the #1089 batching/deferral statement budget are untouched. No schema changes.
Test evidence
Regression tests in
ClassInstanceDiscoveryServiceTest(new Fixture helpers insert face annotations WITHface_thumbnailderived assets, occurrences with explicit state + timestamp offsets, and pin occurrences):Failing-before proof produced by running the final test shapes with only the production change stashed:
11 tests completed, 10 failed(each assertion runs twice in the Gradle console; 5 of 6 distinct tests failed, the 6th pins intentionally-preserved behavior).Suite results (
rtk ./gradlew :apps:api:test):ClassInstanceDiscoveryServiceTest: 297 tests, 0 failures, 0 errors (incl.personRankingRunsConstantNumberOfStatementsRegardlessOfFaceCount50-faces ≤ 7 statements, andpersonRankingDefersPersonEmbeddingScanByComposerCoverageNotRepPresence)Residual risk
KNOWN_ISSUES.md ISSUE-112 (low):
suggestSimilarInstances(a different endpoint — the /instances/similar search, not the three pickers) carries the same newest-of-either-state subquery in three places; left untouched to keep this PR thumbnail-selection-only for the picker regression.Branch based on latest origin/main (
0461b5fc). No merge performed, no docker/deploy actions.