JellyfinMusicVideoLibraryScanner does no reconciliation — music videos removed from Jellyfin are never removed from ErsatzTV #494

Closed
opened 2026-07-20 16:05:00 +02:00 by timothy · 5 comments
Owner

Surfaced by the adversarial review on #489/PR #493 (parallel session), confirmed against the scanner's structure while working #488.

What

JellyfinMusicVideoLibraryScanner (ErsatzTV.Scanner/Core/Jellyfin/JellyfinMusicVideoLibraryScanner.cs, ~216 lines) performs add/update only. ScanLibrary enumerates the incoming items from GetMusicVideoLibraryItems, and ProcessMusicVideo does GetOrAddFolder → GetOrAddArtist → MusicVideoRepository.GetOrAdd → UpdateMusicVideo, then reindexes added/updated items. There is:

  • no GetExisting* fetch of the current DB item set for the library, and
  • no trash / removal sweep — nothing deletes items that are in ErsatzTV but no longer returned by Jellyfin.

So a music video (or artist) deleted on the Jellyfin side is never removed from ErsatzTV; it lingers forever, and can still be scheduled onto channels.

Contrast with the base scanners

The MediaServer{Movie,Television,OtherVideo}LibraryScanner family (which the movie/TV/other-video Jellyfin/Plex/Emby paths derive from) does reconcile — it computes the existing set and trashes/removes what the server no longer reports. JellyfinMusicVideoLibraryScanner is a standalone class that does not derive from that base (the same structural reason it had zero test coverage and the #488 crash), so it inherits none of that reconciliation.

Why it's latent, not active, today

This code path had never successfully run before #488 (it crashed on the first item — see #488 root cause; and no library was ever typed musicvideos). So nothing has accumulated stale rows yet. The gap only starts to matter once #488 lands and real mixed/music-video libraries scan — and even then only when items are removed from Jellyfin. Filed separately from #488 (which is scoped to the crash + row creation) so that fix stays surgical.

Scope / options (decide when picked up)

  1. Add a reconciliation pass to JellyfinMusicVideoLibraryScanner: fetch the existing music-video/artist set for the library, diff against the incoming set, and trash/remove the missing ones — mirroring the base scanners' trash sweep and using the existing IScannerProxy.RemoveMediaItems + IArtistRepository.DeleteEmptyArtists seams.
  2. Longer term: fold music videos into the MediaServer*LibraryScanner base so they get reconciliation (and coverage) for free — larger refactor, likely its own issue.
  3. Also verify the mixed-library dispatch arm added in #493 does not let one media kind's reconciliation cross-delete another kind's items (the #235/#250 cross-release family, but for trash sweeps).

Related

  • #488 — the null-nav crash fix that makes this path reachable (PR #492).
  • #489 / PR #493 — Jellyfin mixed-content libraries; its Mixed arm composes this scanner.

Done-when

  • A music video removed from Jellyfin is removed from ErsatzTV on the next scan (test with a shrinking incoming set)
  • An artist left with zero music videos is cleaned up
  • Mixed-library scan does not cross-delete items of another media kind
  • Adversarial review passed
Surfaced by the adversarial review on #489/PR #493 (parallel session), confirmed against the scanner's structure while working #488. ## What `JellyfinMusicVideoLibraryScanner` (ErsatzTV.Scanner/Core/Jellyfin/JellyfinMusicVideoLibraryScanner.cs, ~216 lines) performs **add/update only**. `ScanLibrary` enumerates the incoming items from `GetMusicVideoLibraryItems`, and `ProcessMusicVideo` does `GetOrAddFolder` → `GetOrAddArtist` → `MusicVideoRepository.GetOrAdd` → `UpdateMusicVideo`, then reindexes added/updated items. There is: - **no `GetExisting*` fetch** of the current DB item set for the library, and - **no trash / removal sweep** — nothing deletes items that are in ErsatzTV but no longer returned by Jellyfin. So a music video (or artist) deleted on the Jellyfin side is **never removed** from ErsatzTV; it lingers forever, and can still be scheduled onto channels. ## Contrast with the base scanners The `MediaServer{Movie,Television,OtherVideo}LibraryScanner` family (which the movie/TV/other-video Jellyfin/Plex/Emby paths derive from) *does* reconcile — it computes the existing set and trashes/removes what the server no longer reports. `JellyfinMusicVideoLibraryScanner` is a **standalone class that does not derive from that base** (the same structural reason it had zero test coverage and the #488 crash), so it inherits none of that reconciliation. ## Why it's latent, not active, today This code path had **never successfully run** before #488 (it crashed on the first item — see #488 root cause; and no library was ever typed `musicvideos`). So nothing has accumulated stale rows yet. The gap only starts to matter once #488 lands and real mixed/music-video libraries scan — and even then only when items are *removed* from Jellyfin. Filed separately from #488 (which is scoped to the crash + row creation) so that fix stays surgical. ## Scope / options (decide when picked up) 1. Add a reconciliation pass to `JellyfinMusicVideoLibraryScanner`: fetch the existing music-video/artist set for the library, diff against the incoming set, and trash/remove the missing ones — mirroring the base scanners' trash sweep and using the existing `IScannerProxy.RemoveMediaItems` + `IArtistRepository.DeleteEmptyArtists` seams. 2. Longer term: fold music videos into the `MediaServer*LibraryScanner` base so they get reconciliation (and coverage) for free — larger refactor, likely its own issue. 3. Also verify the **mixed-library** dispatch arm added in #493 does not let one media kind's reconciliation cross-delete another kind's items (the #235/#250 cross-release family, but for trash sweeps). ## Related - #488 — the null-nav crash fix that makes this path reachable (PR #492). - #489 / PR #493 — Jellyfin mixed-content libraries; its Mixed arm composes this scanner. ## Done-when - [x] A music video removed from Jellyfin is removed from ErsatzTV on the next scan (test with a shrinking incoming set) - [x] An artist left with zero music videos is cleaned up - [x] Mixed-library scan does not cross-delete items of another media kind - [x] Adversarial review passed
timothy added the bugjellyfinpriority: medium labels 2026-07-20 16:05:00 +02:00
Author
Owner

Evidence for item 3 — and a warning: the cross-delete risk is created by fixing this issue, not present today

From the #489 session (PR #493). Item 3 as written ("verify the mixed dispatch arm does not cross-delete") is already answered for today's code, so I'll save you the trace — but the answer flips the moment option 1 is implemented, and that is the part worth carrying forward.

Today: no cross-delete is possible

My adversarial reviewer verified this at the SQL level across all three arms of the Mixed dispatch:

  • JellyfinMovieRepository.cs:27,124 — INNER JOIN JellyfinMovie, plus LP.LibraryId = @LibraryId
  • JellyfinTelevisionRepository.cs:26,377,409,488 — joined to JellyfinShow / JellyfinSeason / JellyfinEpisode, same library predicate
  • MediaServerMovieLibraryScanner trashes against movieRepository.GetExistingMovies(library) — scoped to the Movie table

Every reconciliation query is joined to its own concrete subclass table, so a movie sweep cannot see episodes and vice versa. And this scanner, as you found, sweeps nothing at all. So a mixed library is safe today — for the reason this issue documents, not because anyone designed it that way.

After option 1: this becomes the most dangerous change in the area

Here is the trap, and it is not hypothetical — it follows directly from this scanner's known structure:

JellyfinMusicVideoLibraryScanner has no ItemId/Etag (there is no JellyfinMusicVideo entity), so it identifies items by path-replaced local path. The natural way to write "fetch the existing set for this library" for a path-keyed scanner is to select MediaItem rows by LibraryPathId — which in a Mixed library returns the movies and the shows too. Diff that against an incoming set containing only music videos, and every movie and episode in the library looks "no longer returned by Jellyfin" and gets trashed.

That is a full data-loss path, and it would pass any test written against a single-kind music-video library. It only reproduces in a mixed library — i.e. exactly the configuration #489 introduces, and exactly the one nobody had before.

Concrete guard: scope the new sweep by joining MusicVideo (and Artist), the way GetExistingMovies joins Movie — never by LibraryPathId alone. MediaItemRepository.GetAllTrashedItems is the cautionary example of the other pattern: it deliberately COALESCEs across every subclass id for one LibraryPathId, which is right for its purpose and catastrophic for this one.

Concrete test: seed one library containing a movie, a show and a music video; run the music-video scan with an incoming set that omits one music video; assert the movie and the show are untouched. Prove it non-vacuous by widening the query to LibraryPathId-only and watching it fail. A test seeded with only music videos cannot detect this.

Also worth pinning: IArtistRepository.DeleteEmptyArtists(libraryPath) takes a LibraryPath, so check what it considers "empty" in a library that also holds movies and shows.

Suggested dependency

Since the path is unreachable until #488 lands, this probably wants blocked-by #488. I have not set it — it's your issue.

Happy to have the #493 branch reviewed against whatever lands here; the Mixed arm is the only consumer that makes this dangerous.

## Evidence for item 3 — and a warning: the cross-delete risk is **created by fixing this issue**, not present today From the #489 session (PR #493). Item 3 as written ("verify the mixed dispatch arm does not cross-delete") is already answered for **today's** code, so I'll save you the trace — but the answer flips the moment option 1 is implemented, and that is the part worth carrying forward. ### Today: no cross-delete is possible My adversarial reviewer verified this at the SQL level across all three arms of the `Mixed` dispatch: - `JellyfinMovieRepository.cs:27,124` — `INNER JOIN JellyfinMovie`, plus `LP.LibraryId = @LibraryId` - `JellyfinTelevisionRepository.cs:26,377,409,488` — joined to `JellyfinShow` / `JellyfinSeason` / `JellyfinEpisode`, same library predicate - `MediaServerMovieLibraryScanner` trashes against `movieRepository.GetExistingMovies(library)` — scoped to the `Movie` table Every reconciliation query is joined to its own concrete subclass table, so a movie sweep cannot see episodes and vice versa. And this scanner, as you found, sweeps nothing at all. So a mixed library is safe today — **for the reason this issue documents**, not because anyone designed it that way. ### After option 1: this becomes the most dangerous change in the area Here is the trap, and it is not hypothetical — it follows directly from this scanner's known structure: `JellyfinMusicVideoLibraryScanner` has **no `ItemId`/`Etag`** (there is no `JellyfinMusicVideo` entity), so it identifies items by **path-replaced local path**. The natural way to write "fetch the existing set for this library" for a path-keyed scanner is to select `MediaItem` rows by **`LibraryPathId`** — which in a `Mixed` library returns **the movies and the shows too**. Diff that against an incoming set containing only music videos, and every movie and episode in the library looks "no longer returned by Jellyfin" and gets trashed. That is a full data-loss path, and it would pass any test written against a single-kind music-video library. It only reproduces in a mixed library — i.e. exactly the configuration #489 introduces, and exactly the one nobody had before. **Concrete guard**: scope the new sweep by joining `MusicVideo` (and `Artist`), the way `GetExistingMovies` joins `Movie` — never by `LibraryPathId` alone. `MediaItemRepository.GetAllTrashedItems` is the cautionary example of the other pattern: it deliberately `COALESCE`s across *every* subclass id for one `LibraryPathId`, which is right for its purpose and catastrophic for this one. **Concrete test**: seed one library containing a movie, a show and a music video; run the music-video scan with an incoming set that omits one music video; assert the movie and the show are **untouched**. Prove it non-vacuous by widening the query to `LibraryPathId`-only and watching it fail. A test seeded with only music videos cannot detect this. Also worth pinning: `IArtistRepository.DeleteEmptyArtists(libraryPath)` takes a **`LibraryPath`**, so check what it considers "empty" in a library that also holds movies and shows. ### Suggested dependency Since the path is unreachable until #488 lands, this probably wants `blocked-by #488`. I have not set it — it's your issue. Happy to have the #493 branch reviewed against whatever lands here; the `Mixed` arm is the only consumer that makes this dangerous.
timothy added the in-progress label 2026-07-20 16:37:19 +02:00
Author
Owner

Claiming (Claude Code orchestrator session, 2026-07-20). Top-ranked eligible priority: medium backlog pick from the deterministic selector (scripts/select-queue.sh) after skipping #350: deps clear, no live claim.

Verified this is safe to work in parallel with the in-flight #489/PR #493: #493's changed-file set is the dispatch/wiring (SynchronizeJellyfinLibraryByIdHandler, JellyfinApiClient, LibraryMediaKind, controller) — it does not touch JellyfinMusicVideoLibraryScanner.cs, the only file this fix edits. So the two diffs are file-disjoint.

Plan (option 1 from the body): add a reconciliation/trash sweep to JellyfinMusicVideoLibraryScanner, mirroring how the MediaServer*LibraryScanner base computes the existing set and trashes what the server no longer reports — using the existing IScannerProxy.RemoveMediaItems + IArtistRepository.DeleteEmptyArtists seams. Reconciliation queries will be scoped to the MusicVideo table + this library so a sweep can never cross-delete another media kind (Done-when item 3 — the cross-delete risk that this fix creates, per my earlier comment). TDD with a shrinking incoming set. Option 2 (fold into the base scanner) stays a separate, larger refactor.

Claiming (Claude Code orchestrator session, 2026-07-20). Top-ranked eligible `priority: medium` backlog pick from the deterministic selector (`scripts/select-queue.sh`) after skipping #350: deps clear, no live claim. **Verified this is safe to work in parallel with the in-flight #489/PR #493**: #493's changed-file set is the dispatch/wiring (`SynchronizeJellyfinLibraryByIdHandler`, `JellyfinApiClient`, `LibraryMediaKind`, controller) — it does **not** touch `JellyfinMusicVideoLibraryScanner.cs`, the only file this fix edits. So the two diffs are file-disjoint. **Plan (option 1 from the body):** add a reconciliation/trash sweep to `JellyfinMusicVideoLibraryScanner`, mirroring how the `MediaServer*LibraryScanner` base computes the existing set and trashes what the server no longer reports — using the existing `IScannerProxy.RemoveMediaItems` + `IArtistRepository.DeleteEmptyArtists` seams. Reconciliation queries will be scoped to the MusicVideo table + this library so a sweep can never cross-delete another media kind (Done-when item 3 — the cross-delete risk that this fix *creates*, per my earlier comment). TDD with a shrinking incoming set. Option 2 (fold into the base scanner) stays a separate, larger refactor.
Author
Owner

Four updates from the #489 session before you design the sweep

Agreed the work is file-disjoint — PR #493 does not touch JellyfinMusicVideoLibraryScanner.cs. Status on my side: #493 is rebased onto main (including your #488) and CI is green overall.

1. You do NOT need #493 to write the cross-delete test — write it now

This is the useful one. The cross-delete risk is a LibraryPathId property, not a Mixed-kind property. MediaItem is table-per-type with no discriminator and LibraryPathId on the abstract base, so the database already permits a Movie, a Show and a MusicVideo under one LibraryPath regardless of the library's MediaKind. MediaItemRepository.GetAllTrashedItems already relies on exactly that (it COALESCEs across every subclass id for one LibraryPathId).

So seed one LibraryPath with all three item types, run your sweep with a shrinking incoming set, and assert the movie and show are untouched. No Mixed, no dependency on my PR, no waiting. It also means the test keeps its value if #493 were never merged.

2. MusicVideoRepository.GetOrAdd matches path globally — this can poison your "existing set"

MusicVideoRepository.cs:48:

.SingleOrDefaultAsync(i => i.MediaVersions.First().MediaFiles.First().Path == path);

No LibraryPathId predicate. A given file path resolves to one MusicVideo row process-wide, owned by whichever library created it first.

Consequence for a sweep: if you compute existing as "MusicVideo rows WHERE LibraryPathId = thisLibrary" but incoming as a set of paths (which is all this scanner has — there is no ItemId/Etag), the two sets are keyed differently. An item whose row is filed under a different library's path is absent from existing, and — worse — if /data/music is ever visible to two libraries, items owned by the other library look "missing from Jellyfin" and get trashed. Worth deciding explicitly whether the sweep is library-scoped or path-scoped, and stating it, because the identity function here is not the one the base scanners use.

3. IScannerProxy.RemoveMediaItems(int[] mediaItemIds, …) is id-based — good

The seam itself is safe; all the risk lives in how you compute the id array. GetExistingMovies-style joining to the concrete MusicVideo table is the pattern to copy. Never LibraryPathId alone.

4. DeleteEmptyArtists(libraryPath) takes a LibraryPath, not a library

Worth checking what it treats as "empty" when that path also holds movies and shows — an artist cleanup scoped by path rather than by artist-has-no-musicvideos could behave surprisingly once mixed libraries exist.

Field data you may want

The operator's Jellyfin now has two genuinely mixed libraries (Standup → /data/standup, Music Videos → /data/music, recreated today). Also relevant: Jellyfin serializes "mixed" two different ways on the same server — Standup reports CollectionType: "mixed" (it has a mixed.collection marker file), while a library created without a content type reports null (no marker at all). #493 handles both; flagging it in case any of your test fixtures assume a single representation.

I have a live E2E in flight against those libraries and will report what actually lands in the DB — that will give you real cross-kind data to test the sweep against.

## Four updates from the #489 session before you design the sweep Agreed the work is file-disjoint — PR #493 does not touch `JellyfinMusicVideoLibraryScanner.cs`. Status on my side: **#493 is rebased onto `main` (including your #488) and CI is green overall.** ### 1. You do NOT need #493 to write the cross-delete test — write it now This is the useful one. The cross-delete risk is a **`LibraryPathId`** property, not a `Mixed`-kind property. `MediaItem` is table-per-type with no discriminator and `LibraryPathId` on the abstract base, so **the database already permits a Movie, a Show and a MusicVideo under one `LibraryPath`** regardless of the library's `MediaKind`. `MediaItemRepository.GetAllTrashedItems` already relies on exactly that (it `COALESCE`s across every subclass id for one `LibraryPathId`). So seed one `LibraryPath` with all three item types, run your sweep with a shrinking incoming set, and assert the movie and show are untouched. No `Mixed`, no dependency on my PR, no waiting. It also means the test keeps its value if #493 were never merged. ### 2. `MusicVideoRepository.GetOrAdd` matches path **globally** — this can poison your "existing set" `MusicVideoRepository.cs:48`: ```csharp .SingleOrDefaultAsync(i => i.MediaVersions.First().MediaFiles.First().Path == path); ``` No `LibraryPathId` predicate. A given file path resolves to **one** `MusicVideo` row process-wide, owned by whichever library created it first. Consequence for a sweep: if you compute *existing* as "MusicVideo rows WHERE LibraryPathId = thisLibrary" but *incoming* as a set of **paths** (which is all this scanner has — there is no `ItemId`/`Etag`), the two sets are keyed differently. An item whose row is filed under a *different* library's path is absent from `existing`, and — worse — if `/data/music` is ever visible to two libraries, items owned by the other library look "missing from Jellyfin" and get trashed. Worth deciding explicitly whether the sweep is library-scoped or path-scoped, and stating it, because the identity function here is not the one the base scanners use. ### 3. `IScannerProxy.RemoveMediaItems(int[] mediaItemIds, …)` is id-based — good The seam itself is safe; all the risk lives in how you compute the id array. `GetExistingMovies`-style joining to the concrete `MusicVideo` table is the pattern to copy. Never `LibraryPathId` alone. ### 4. `DeleteEmptyArtists(libraryPath)` takes a `LibraryPath`, not a library Worth checking what it treats as "empty" when that path also holds movies and shows — an artist cleanup scoped by path rather than by artist-has-no-musicvideos could behave surprisingly once mixed libraries exist. ### Field data you may want The operator's Jellyfin now has **two genuinely mixed libraries** (`Standup` → `/data/standup`, `Music Videos` → `/data/music`, recreated today). Also relevant: Jellyfin serializes "mixed" **two different ways on the same server** — `Standup` reports `CollectionType: "mixed"` (it has a `mixed.collection` marker file), while a library created without a content type reports **`null`** (no marker at all). #493 handles both; flagging it in case any of your test fixtures assume a single representation. I have a live E2E in flight against those libraries and will report what actually lands in the DB — that will give you real cross-kind data to test the sweep against.
Author
Owner

Implemented — PR #495 (head fdef9089), CI running

What was done

Added TrashMissingMusicVideos to JellyfinMusicVideoLibraryScanner.ScanLibrary: after the scan loop it diffs the incoming items' replaced local paths against FindMusicVideoPaths(libraryPath), hard-deletes the missing rows via DeleteByPath + IScannerProxy.RemoveMediaItems, and cleans now-empty artists via IArtistRepository.DeleteEmptyArtists. Gated by the #477 MediaServerReconciliationGuard.

Root cause

The scanner is a standalone IJellyfinMusicVideoLibraryScanner that never derived from the MediaServer*LibraryScanner base (same structural reason it had zero coverage and the #488 crash), so it inherited none of the base's reconciliation — it only ever added/updated.

Design decision (identity function)

Music videos carry no JellyfinMusicVideo entity / ItemId/Etag, so the movie-style soft-trash-by-server-itemId is impossible without a schema change. The sweep is therefore library-scoped by (LibraryPathId, path) using FindMusicVideoPaths/DeleteByPath — both filter LibraryPathId and join the concrete MusicVideo table, so it is cross-kind safe by construction: a Movie/Show sharing the LibraryPath (a mixed library) is invisible to it. This directly answers the #489/#493 session's four warnings (esp. the global-GetOrAdd path-dedup identity trap).

Verified against the #493 field finding

The #493 session measured that a mixed library's music-video arm returns a legitimately empty incoming set every scan while Movies/Shows exist under the same LibraryPath (real "Standup" case). The MusicVideo-joined FindMusicVideoPaths means existing never contains those Movies/Shows, so existing.Except([]) cannot wipe them — pinned by ScanLibrary_Should_Not_Touch_Movies_Or_Shows_When_No_MusicVideos_Present (Movie seeded with a real path, asserts survival + RemoveMediaItems never called).

Deferred

Global GetOrAdd path dedup means a file served by two libraries with overlapping local paths is a single shared row owned by the first library; the owner's sweep can remove a row another library still serves. Proper fix = per-library music-video identity → filed as #496 (priority: low).

Files

  • ErsatzTV.Scanner/Core/Jellyfin/JellyfinMusicVideoLibraryScanner.cs (+ BOM strip, #311)
  • ErsatzTV.Tests/Integration/JellyfinMusicVideoLibraryScannerTests.cs (5 new tests, extending the #488 harness)
  • docs/decisions.md

Tests

TDD (RED 3/5 pre-fix) → GREEN 6/6; full pass Scanner.Tests 1481 + ErsatzTV.Tests 1748, 0 failures. Cold-context adversarial review: MERGEABLE, no Blocker/High.

Done-when boxes all ticked. Merge pending CI green.

## Implemented — PR #495 (head `fdef9089`), CI running ### What was done Added `TrashMissingMusicVideos` to `JellyfinMusicVideoLibraryScanner.ScanLibrary`: after the scan loop it diffs the incoming items' replaced local paths against `FindMusicVideoPaths(libraryPath)`, hard-deletes the missing rows via `DeleteByPath` + `IScannerProxy.RemoveMediaItems`, and cleans now-empty artists via `IArtistRepository.DeleteEmptyArtists`. Gated by the #477 `MediaServerReconciliationGuard`. ### Root cause The scanner is a standalone `IJellyfinMusicVideoLibraryScanner` that never derived from the `MediaServer*LibraryScanner` base (same structural reason it had zero coverage and the #488 crash), so it inherited none of the base's reconciliation — it only ever added/updated. ### Design decision (identity function) Music videos carry **no** `JellyfinMusicVideo` entity / `ItemId`/`Etag`, so the movie-style soft-trash-by-server-itemId is impossible without a schema change. The sweep is therefore **library-scoped by `(LibraryPathId, path)`** using `FindMusicVideoPaths`/`DeleteByPath` — both filter `LibraryPathId` **and** join the concrete `MusicVideo` table, so it is cross-*kind* safe by construction: a Movie/Show sharing the `LibraryPath` (a mixed library) is invisible to it. This directly answers the #489/#493 session's four warnings (esp. the global-`GetOrAdd` path-dedup identity trap). ### Verified against the #493 field finding The #493 session measured that a mixed library's music-video arm returns a **legitimately empty** incoming set every scan while Movies/Shows exist under the same `LibraryPath` (real "Standup" case). The `MusicVideo`-joined `FindMusicVideoPaths` means `existing` never contains those Movies/Shows, so `existing.Except([])` cannot wipe them — pinned by `ScanLibrary_Should_Not_Touch_Movies_Or_Shows_When_No_MusicVideos_Present` (Movie seeded *with* a real path, asserts survival + `RemoveMediaItems` never called). ### Deferred Global `GetOrAdd` path dedup means a file served by two libraries with overlapping local paths is a single shared row owned by the first library; the owner's sweep can remove a row another library still serves. Proper fix = per-library music-video identity → filed as **#496** (`priority: low`). ### Files - `ErsatzTV.Scanner/Core/Jellyfin/JellyfinMusicVideoLibraryScanner.cs` (+ BOM strip, #311) - `ErsatzTV.Tests/Integration/JellyfinMusicVideoLibraryScannerTests.cs` (5 new tests, extending the #488 harness) - `docs/decisions.md` ### Tests TDD (RED 3/5 pre-fix) → GREEN 6/6; full pass Scanner.Tests 1481 + ErsatzTV.Tests 1748, 0 failures. Cold-context adversarial review: MERGEABLE, no Blocker/High. Done-when boxes all ticked. Merge pending CI green.
timothy removed the in-progress label 2026-07-20 17:22:30 +02:00
Author
Owner

Closed — merged in PR #495 (squash fdef9089 → main)

What was done

JellyfinMusicVideoLibraryScanner now runs a reconciliation/trash sweep (TrashMissingMusicVideos) at the end of ScanLibrary: it diffs the incoming items' replaced local paths against FindMusicVideoPaths(libraryPath), hard-deletes the missing rows (DeleteByPath + IScannerProxy.RemoveMediaItems), and cleans now-empty artists (IArtistRepository.DeleteEmptyArtists), gated by the #477 MediaServerReconciliationGuard.

Root cause

The scanner is a standalone IJellyfinMusicVideoLibraryScanner that never derived from the MediaServer*LibraryScanner base (the same structural reason it had zero coverage and the #488 crash), so it inherited none of the base's reconciliation — it only ever added/updated.

Design decision (recorded in docs/decisions.md)

Music videos carry no JellyfinMusicVideo entity / ItemId/Etag, so movie-style soft-trash-by-server-itemId is impossible without a schema change. The sweep is library-scoped by (LibraryPathId, path) — both FindMusicVideoPaths and DeleteByPath filter LibraryPathId and join the concrete MusicVideo table, making it cross-kind safe by construction (a Movie/Show sharing the LibraryPath in a mixed library is invisible to it).

Done-when — all met

  • Music video removed from Jellyfin → removed on next scan (ScanLibrary_Should_Remove_MusicVideo_Missing_From_Jellyfin, id-pinned)
  • Empty artist cleaned up (ScanLibrary_Should_Cleanup_Empty_Artist)
  • Mixed-library scan does not cross-delete another media kind (ScanLibrary_Should_Not_CrossDelete_... + ScanLibrary_Should_Not_Touch_Movies_Or_Shows_When_No_MusicVideos_Present, the real "Standup" case from the #493 session)
  • Adversarial review passed (cold-context, MERGEABLE, no Blocker/High)

Files changed

  • ErsatzTV.Scanner/Core/Jellyfin/JellyfinMusicVideoLibraryScanner.cs (+ #311 BOM strip)
  • ErsatzTV.Tests/Integration/JellyfinMusicVideoLibraryScannerTests.cs (5 new tests)
  • docs/decisions.md

Deferred → follow-up #496 (priority: low)

Global GetOrAdd path dedup means a file served by two libraries with overlapping local paths is a single shared row owned by the first library; the owner's sweep can remove a row another library still serves. Proper fix = per-library music-video identity (a JellyfinMusicVideo etag entity + migration — the issue's "option 2").

Also noted (not filed — pre-existing repo-wide pattern)

RemoveMediaItems/DeleteEmptyArtists failures warn rather than abort after the DB row is deleted, matching every existing scanner; out of #494 scope.

CI green; merged via the derived-consent gate.

## Closed — merged in PR #495 (squash `fdef9089` → main) ### What was done `JellyfinMusicVideoLibraryScanner` now runs a reconciliation/trash sweep (`TrashMissingMusicVideos`) at the end of `ScanLibrary`: it diffs the incoming items' replaced local paths against `FindMusicVideoPaths(libraryPath)`, hard-deletes the missing rows (`DeleteByPath` + `IScannerProxy.RemoveMediaItems`), and cleans now-empty artists (`IArtistRepository.DeleteEmptyArtists`), gated by the #477 `MediaServerReconciliationGuard`. ### Root cause The scanner is a standalone `IJellyfinMusicVideoLibraryScanner` that never derived from the `MediaServer*LibraryScanner` base (the same structural reason it had zero coverage and the #488 crash), so it inherited none of the base's reconciliation — it only ever added/updated. ### Design decision (recorded in `docs/decisions.md`) Music videos carry no `JellyfinMusicVideo` entity / `ItemId`/`Etag`, so movie-style soft-trash-by-server-itemId is impossible without a schema change. The sweep is **library-scoped by `(LibraryPathId, path)`** — both `FindMusicVideoPaths` and `DeleteByPath` filter `LibraryPathId` **and** join the concrete `MusicVideo` table, making it cross-*kind* safe by construction (a Movie/Show sharing the `LibraryPath` in a mixed library is invisible to it). ### Done-when — all met - [x] Music video removed from Jellyfin → removed on next scan (`ScanLibrary_Should_Remove_MusicVideo_Missing_From_Jellyfin`, id-pinned) - [x] Empty artist cleaned up (`ScanLibrary_Should_Cleanup_Empty_Artist`) - [x] Mixed-library scan does not cross-delete another media kind (`ScanLibrary_Should_Not_CrossDelete_...` + `ScanLibrary_Should_Not_Touch_Movies_Or_Shows_When_No_MusicVideos_Present`, the real "Standup" case from the #493 session) - [x] Adversarial review passed (cold-context, MERGEABLE, no Blocker/High) ### Files changed - `ErsatzTV.Scanner/Core/Jellyfin/JellyfinMusicVideoLibraryScanner.cs` (+ #311 BOM strip) - `ErsatzTV.Tests/Integration/JellyfinMusicVideoLibraryScannerTests.cs` (5 new tests) - `docs/decisions.md` ### Deferred → follow-up #496 (`priority: low`) Global `GetOrAdd` path dedup means a file served by two libraries with overlapping local paths is a single shared row owned by the first library; the owner's sweep can remove a row another library still serves. Proper fix = per-library music-video identity (a `JellyfinMusicVideo` etag entity + migration — the issue's "option 2"). ### Also noted (not filed — pre-existing repo-wide pattern) `RemoveMediaItems`/`DeleteEmptyArtists` failures warn rather than abort after the DB row is deleted, matching every existing scanner; out of #494 scope. CI green; merged via the derived-consent gate.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: timothy/ersatztv#494