Skip to content

[bug] Merging duplicate rows for one provider id deletes the surviving item's cached artwork (S3); refresh does not re-upload #932

Open

Description

@jkristoph

What happened

After two media_items rows for the same TMDB id were merged (one anchored movie-imdb-tt…, one movie-tmdb-…), the surviving row's poster/backdrop objects were gone from the S3 bucket. The row still points at the hashed key, metadata_image_cache_jobs still says succeeded, so clients get 404s for the artwork (Android TV renders a blank tile) and a quick refresh does not re-upload. Probing every item matched in a 36 h window on our install found 5 affected out of 2,968 (Blood on the Crown, Little Girl Blue, Fatal Distraction, DOTGA, Everyone Is Lying to You for Money); random samples of older items were all intact. In one of the five cases (Little Girl Blue) the losing row's file was not re-linked either: media_files still carries content_id = movie-imdb-tt26714897 although that media_items row no longer exists, so that version is now invisible.

Steps to reproduce

  1. S3 artwork caching enabled (metadata.cache_images = true, public bucket configured).
  2. A movie folder containing two versions of the same film where one file carries an {imdb-tt…} tag and the other a {tmdb-…} tag (or any other path that yields two rows for one provider id, e.g. a manual re-anchor). Scan.
  3. Let the dedup/re-anchor happen (ours ran at 00:46 and 05:14 UTC without operator action — the second case right after an autoscan-triggered subtree scan of the folder).
  4. GET /api/v1/catalog/items/{surviving id} → poster_url points at …/tmdb/movies/<id>/poster/w300.<hash>.webp; the bucket directory tmdb/movies/<id>/poster/ is empty.

Expected behavior

Deleting the losing row must not remove objects that the surviving row (same provider id, same key prefix) still references — or the survivor's artwork should be re-cached after the merge.

Silo version / commit

7c1cb2d (also observed on 90b5c0f)

Deployment

Docker

Clients affected

  • Android
  • Web UI
  • Other/not client-specific (any client — the object is gone)

Relevant logs

No error is logged: the image cache jobs for the survivor show succeeded with an earlier completed_at; the bucket listing is empty; refresh-metadata jobs complete without re-uploading.

Technical notes

internal/catalog/item_repo.go ItemRepository.Delete collects poster_path/backdrop_path/logo_path of the row being deleted and returns imageDeletePrefix(...) dirs for the caller to sweep (internal/scanner/scanner.go orphanedImageDirs → DeletePrefix). Provider-cached keys are scoped by provider id (tmdb/movies/<id>/<type>/…), so when the losing row shares the provider id with the survivor the sweep deletes the survivor's objects. Re-upload never happens because metadata_image_cache_jobs upsert keeps succeeded when source_path is unchanged (enqueueBatchChunk, requeueSucceeded=false). Workaround that works: update metadata_image_cache_jobs set status='queued', attempt_count=0, next_attempt_at=now(), completed_at=null where target_content_id in (…) — the worker re-caches within a minute. Suggested fix: skip the sweep when another live row references the same prefix, or enqueue the survivor's artwork with requeueSucceeded=true after a merge.

AI harness

Claude Code

AI tool(s)

Claude (Anthropic) — investigation and this report; a human operator reviewed before filing.

Activity

  1. added
    bug
    triaged
    and removed
    triaged
    on Sep 20, 2026
  2. added theissue type on Sep 20, 2026
  3. removed
    bug
    on Sep 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions