from-google-photos: a takeout duplicate of a server copy that the run has just replaced gets the deleted asset's ID, and the group's stack fails
Summary
When the server already has a copy of a photo and the takeout has a bigger copy with the same name and date, immich-go replaces the server's copy (replaceAsset: upload, copy metadata, force-delete the old asset). A Google Takeout often also has X(1).jpg, a duplicate with the same content as that older copy. That file is matched to the deleted asset:
- processed after the replacement: the local index still lists the deleted asset under its checksum (it is only marked trashed), so
ShouldUploadreturns it as "same asset on the server"; - processed before the replacement: it is matched to the still-live copy, whose ID then goes stale when the replacement deletes it.
Either way the file gets the ID of an asset that no longer exists, and the group's POST /api/stacks is made with it: 400 Not found or no asset.update access (or, when the server has not finished the deletion yet, a stack whose primary asset is deleted, which Immich's AssetDelete job then cannot purge). The name+date heuristic has the same blind spot (from the code; the PR's unit test covers it): a same-named, same-dated copy is compared with the deleted asset, not with its replacement.
This is the other source of #1285's stack errors, next to the edited-pair mechanism of #1422: after fixing that one, a 26k-asset import still had 17 Can't create stack errors, all in groups of this kind (42 X(N) files in that run were reported as server duplicates next to a sibling that replaced the server's copy).
Minimal reproduction
Two runs against the same user (files are the fixture added in the PR, internal/e2e/client/DATA/fromGooglePhotos/replaced-copy):
before/Google Photos/phone backup/photo.jpg, small, with a sidecar dated 2023-11-14.takeout/Google Photos/Photos from 2023/withphoto.jpg(bigger, same date),photo-edited.jpg,photo(1).jpg(the same bytes as the small copy),photo.jpg.supplemental-metadata.jsonandphoto.jpg.supplemental-metadata(1).json.
Run 2 with --manage-burst=Stack:
INF server has duplicate photo(1).jpg ← ID of the small server copy
INF server asset upgraded photo.jpg ← uploads, copies metadata, DELETE {"force":true} the small copy
INF uploaded successfully photo-edited.jpg
INF stacked photo(1).jpg / photo.jpg / photo-edited.jpg
ERR Can't create stack error=createStack, POST, …/api/stacks, 400 Bad Request
Not found or no asset.update accessPOST /api/stacks body: {"assetIds":["<deleted small copy>","<bigger photo.jpg>","<edited>"]}. End state: the two new assets on the server, no stack.
Fix
PR #1423 (together with the edited-pair fix of #1422):
- the index records which asset replaced a deleted one;
ShouldUploadresolves a matched asset to its replacement before comparing, sophoto(1).jpgis advised as "bigger copy on the server" for the replacement and takes its ID;- the stack request resolves the group's IDs the same way, for files matched before the replacement happened.
Source: simulot/immich-go