Skip to content

fix: prevent rule-removed items from being re-added as manual additions#2440

Merged
ydkmlt84 merged 1 commit into
Maintainerr:mainfrom
enoch85:fix/prevent-manual-readd-after-rule-removal
Mar 1, 2026
Merged

fix: prevent rule-removed items from being re-added as manual additions#2440
ydkmlt84 merged 1 commit into
Maintainerr:mainfrom
enoch85:fix/prevent-manual-readd-after-rule-removal

Conversation

@enoch85

@enoch85 enoch85 commented Feb 28, 2026

Copy link
Copy Markdown
Collaborator

Problem

After PR #2429 introduced touchedMediaServerIds to prevent syncManualMediaServerToCollectionDB() from double-handling items that were just processed by rule execution, the guard was only applied to the manually removed loop — not the manually added loop.

Race condition

  1. handleCollection() removes item X (rule evaluated false) — deletes from both DB and media server collection
  2. syncManualMediaServerToCollectionDB() runs immediately after
  3. DB correctly shows X is gone, but getCollectionChildren() may still return X from the media server API (sync delay — especially on Jellyfin, but also possible on Plex)
  4. X is in media server children but not in DB → re-added as a manual addition

Fix

Add the touchedMediaServerIds guard to the manually-added loop (mirroring the existing guard in the removal loop), so items just processed by rules are skipped and not mistakenly treated as manual additions.

Testing

  • Added regression test: does not re-add a rule-removed item as manual when media server returns stale children
  • All 494 existing tests continue to pass

After handleCollection() removes an item by rule, the media server API
may still return the item as a collection child due to sync delay. The
syncManualMediaServerToCollectionDB() method checks touchedMediaServerIds
to skip these stale items in the removal loop, but was missing the same
guard in the addition loop. This caused removed items to be immediately
re-added as manual additions.

Add the touchedMediaServerIds guard to the manually-added loop so items
just processed by rules are not mistakenly treated as manual additions.
@enoch85 enoch85 requested a review from ydkmlt84 as a code owner February 28, 2026 21:03
@ydkmlt84 ydkmlt84 merged commit 0582a72 into Maintainerr:main Mar 1, 2026
9 checks passed
@enoch85 enoch85 deleted the fix/prevent-manual-readd-after-rule-removal branch March 1, 2026 07:54
@github-actions

Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 3.1.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants