Skip to content

fix(watchsync): sync favorites and watchlists when two items share a provider key - #2467

Merged
Quick104 merged 5 commits into
mainfrom
fix/issue-2466-list-shared-provider-key
Oct 14, 2026
Merged

Quick104 merged 5 commits into
mainfrom
fix/issue-2466-list-shared-provider-key

Conversation

@Quick104

@Quick104 Quick104 commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Closes #2466
Related issue: N/A
Validation tasks: none

Favorites and watchlist sync with Trakt, Simkl, or MDBList fails on every run when two library items share a provider key: the connection shows favorites export: upsert list item state: ... duplicate key value violates unique constraint "idx_watch_provider_list_items_provider_key", and nothing on the list reaches the provider. A user hit this right after importing favorites from Emby. This change lets each library item keep its own sync row and handles the shared key on import, export, and removal.

The sync row's key is the item's IMDb id, else TMDB, else TVDB id, with no kind. media_items does not keep those ids unique, so two items for one title, or a movie and a series with the same TMDB id and no IMDb id, produce one key. The unique index on (connection_id, list_kind, provider_item_key) rejected the second row, and the error stopped the run.

Approach

A new migration replaces the unique key index with a plain one, building and dropping both concurrently so syncs keep running. Rows stay unique per library item, as the ratings and dropped-show sync rows already are.

The list sync now handles several items per key:

  • A provider removal waits while another item of the same kind, still on the local list and still in the catalog, has the key. Otherwise unfavoriting one copy of a title would take the other copy off the provider. This applies to the scheduled pass and to realtime removals.
  • With removal sync on, an import does not favorite an item again while its local removal has not reached the provider, unless the provider dated its listing after the removal. A listing without a date (the host fills in the import time) never counts as newer.
  • A full import counts every IMDb, TMDB, and TVDB id on a provider row as present for that row's kind, even when the matcher finds more than one library item for it, so neither copy is removed locally. The ids matter because a plugin's key can differ from the one stored at export: Trakt keys shows by TVDB id first. A movie row no longer keeps a series with the same TMDB id; a row or stored item without a kind still matches any kind.
  • A remote tombstone removes every row with its key, and with its kind when it names one. Plugin tombstones carry only the key, so a tombstone whose rows name more than one kind of title is skipped with a warning.

docs/architecture/watch-provider-plugins.md records these rules. Only the server's watch-sync code changes; there is no API, client, or jellycompat change.

Validation

  • Reproduced the reported error on a dev deployment's Postgres with unfixed main: a focused database test that writes two rows with one key fails with the same message. A full sync could not run there because no watch-provider plugin was connected.
  • After rebuilding the deployment with this branch, the migration applied and every watchsync database test passed, including the new one, which also checks the removal hold across kinds and for an item deleted from the catalog. It is added to the CI database contract list.
  • Up, Down, and Up again, run statement by statement on a dev deployment with duplicate rows: Down keeps the most recently updated row per key and restores the unique index, and both indexes come out valid.
  • New service tests cover tombstones, ambiguous imports with Trakt's show key, kind-scoped presence, pending-removal imports with older, newer, and undated provider listings, a tombstone followed by a re-add, and held removals; each fails on the code before the fix.
  • go build ./..., gofmt, go vet ./..., make lint-changed, make migrate-validate, make verify-migration-ledger, and make verify-local-paths pass. make test-go passes apart from two real-FFmpeg tests in internal/mediasample, which fail the same way on main with the FFmpeg 6.1 installed on the test machine. No web files changed, so the web gate was not run.

Evidence

Evidence: https://evidence.siloserver.org/r/silo-server/issue-2466/

Risks

  • The migration runs outside a transaction and builds the new index concurrently. If it is interrupted, the retry drops the half-built index and starts over.
  • Rolling back deletes all but the newest sync row per key, which the next sync rebuilds.
  • With a provider that sends no listing time, a title re-added there while a Silo removal is still pending is removed again by that removal.
  • Known limit, erring toward keeping a favorite: if a realtime removal is lost, the stale row keeps holding the key for the other copy.

Checklist

  • I read and can explain the complete diff.
  • This pull request addresses one concern.
  • The Evidence section shows every change a user can see, or says there is none.

AI Disclosure

  • Harness: Claude Code in T3 Code
  • Tool(s): Claude Code; Codex (cross-provider plan review)
  • Model(s): claude-opus-5-5 (implementation), gpt-6.1-sol (plan review), claude-sonnet-5-5 (review subagents)
  • Involvement: Fully AI-generated, not yet verified by a human
  • Adversarial review: gpt-6.1-sol reviewed the plan and the first implementation. It found four issues; three were fixed here (ambiguous imports removing both copies, the removal hold ignoring kind, items deleted from the catalog holding a key), and a race between concurrent realtime add and remove events was left out as pre-existing. A multi-agent code review then led to the no-re-add rule, tombstones using their kind, and the index predicate. A background gpt-6.1-sol review of cef03ad found two more, both fixed in 1c2ca9c: Trakt's TVDB-first show keys still let an ambiguous import remove both copies, and the pending-removal skip ignored a newer add on the provider. The Codex review of 1c2ca9c found that an undated listing counted as newer and that presence ignored kind; both are fixed in 1020f25. Kody found two more, fixed in 548549f: a tombstone followed by a re-add in one incremental read lost the re-add, and the index swap locked the table. Kody accepted the answers to its other three findings. Codex's review of 548549f found that a retried rollback could keep an invalid unique index; b2000e1 drops it first.

🤖 Generated with Claude Code

Note

Fix favorites and watchlist sync when two items share a provider key

  • Fixes list sync to handle multiple library items that map to the same provider key. Each item gets its own shadow row in watch_provider_list_items, tracked by key and title kind.
  • Provider removals are now deferred while another same-kind local item still holds the key; the key is sent to the provider only after the last holder is removed.
  • Complete imports now track presence by provider key, title kind, and all IMDb/TMDB/TVDB identifiers on a provider row. Pending local removals are not re-added unless the provider supplies a listing dated newer than the removal; an undated listing is flagged as guessed.
  • Tombstones with a shared key remove all same-kind rows. A key-only tombstone spanning movie and series kinds is skipped with a warning.
  • Risk: migration drops the unique index on provider key and replaces it with a non-unique index; rollback deletes older duplicate rows first. Repository implementations must add the new ListListItemsWithSharedKeyHeld method to satisfy watchsync.Repository in repository.go.

Macroscope summarized b2000e1.

…provider key

watch_provider_list_items allowed one row per provider key, but the key
(an IMDb, TMDB, or TVDB id without its kind) is not unique across library
items. A list holding two such items failed every sync with a duplicate key
error before anything was sent.

Make the key index non-unique, as on the ratings and dropped-show tables, and
handle several items per key: a removal stays held while another item of the
same kind still on the local list has the key, an import does not add back an
item whose removal is still pending, and a remote tombstone removes every row
with its key unless the rows name more than one kind of title.

Closes #2466

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@silo-kody

silo-kody Bot commented Oct 14, 2026 •

Copy link
Copy Markdown

Silo Kody — review complete

Review finished. Check the inline comments for findings and verify each suggestion against the code and tests.

Reviewing changes in Silo
  • Include the related issue, expected behavior, and validation steps in the PR description.
  • For API changes, describe the effect on Apple and Android clients and Jellyfin compatibility.
  • For plugin changes, identify the affected SDK contract, plugin, and catalog entry.
  • Follow this repository's AGENTS.md and CONTRIBUTING.md.
  • Request another review with @kody start-review in a PR comment.
  • React with 👍 or 👎 to give feedback on individual suggestions.
Review settings
Review Options

The following review options are enabled or disabled:

Options Enabled
Bug ✅
Performance ✅
Security ✅
Business Logic ❌

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 14, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-14T19:10:40.522832Z 548549f New commits
🔒 Security Review ✅ Completed 2026-10-14T19:10:03.520155Z 548549f New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@coderabbitai

coderabbitai Bot commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 694df376-af93-47c0-b306-7f075880fa5e
📥 Commits

Reviewing files that changed from the base of the PR and between 1020f25 and b2000e1.

📒 Files selected for processing: 3
  • internal/watchsync/lists.go
  • internal/watchsync/service_test.go
  • migrations/sql/20261014175636_list_items_shared_provider_key.sql

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 2 remain after this review.

📝 Walkthrough

List synchronization now permits multiple local items to share a provider key. Imports and tombstones account for item kind and local removal time. Provider removals are deferred while another locally present item holds the same key.

Changes: Shared provider-key synchronization

Layer / File(s) Summary
Shared-key storage and repository support
migrations/sql/20261014175636_list_items_shared_provider_key.sql, internal/watchsync/repository.go, internal/watchsync/list_items_db_test.go, scripts/ci/db-contracts.txt
The migration permits duplicate nonempty provider keys. Repository queries detect when another locally present item holds a key and exclude held items from pending removals. Database-contract coverage exercises shared-key list states.
Import and tombstone handling
internal/watchsync/types.go, internal/watchsync/plugin_provider_state.go, internal/watchsync/lists.go, internal/watchsync/plugin_provider_test.go, internal/watchsync/service_test.go, docs/architecture/watch-provider-plugins.md
Imports track provider identifiers by item kind and use a guessed-time flag when the provider omits listed_at. Guessed or older listings do not restore locally removed items. Tombstones update matching items and warn when a key spans different kinds. Tests and documentation cover these behaviors.
Local removal synchronization
internal/watchsync/lists.go, internal/watchsync/service_test.go
Local removal events send only items whose keys are no longer held by another local item. Tests cover withholding provider removal until the final local holder leaves.

Priority: ➖ Normal

Estimated code review effort: 4 (Complex) | ~45 minutes

Change: Bug fix · Severity of issue fixed: Medium

Sequence Diagram(s)

sequenceDiagram
  participant LocalRemovalEvent
  participant listItemsReleasedLocally
  participant Repository
  participant WatchProvider
  LocalRemovalEvent->>listItemsReleasedLocally: filter items by held provider keys
  listItemsReleasedLocally->>Repository: ListListItemsWithSharedKeyHeld
  Repository-->>listItemsReleasedLocally: return held item IDs
  listItemsReleasedLocally-->>LocalRemovalEvent: return released items
  LocalRemovalEvent->>WatchProvider: remove released items
Loading
Merge Risk: 🟡 Moderate · up to b2000

A complete sync can remove favorites or watchlist entries that should remain, and a concurrent add and removal can incorrectly remove a shared provider key. Resolve these cases before merging unless their impact is explicitly accepted.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 46.15% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 13 functions across 7 files. (1 skipped: … Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Linked Issues check Passed The changes meet the coding requirements in [#2466]. The migration replaces the unique provider-key index with a non-unique index, so each library item can retain its own sync row. The sync code holds…
Out of Scope Changes check Passed The changes stay within [#2466]. The migration, watch-sync code, provider timestamp handling, tests, CI contract entry, and watch-provider documentation support reliable synchronization for shared pro…
Description check Passed The description directly explains the shared provider-key failure and the changes to migration, imports, exports, removals, tombstones, tests, and risks.
Title check Passed The title clearly and concisely identifies the main change: fixing favorites and watchlist synchronization when multiple items share a provider key.
Full details: Docstring Coverage

Explanation

Docstring coverage is 46.15% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 13 functions across 7 files. (1 skipped: 1 unsupported.)

  • Fix all pre-merge checks with AI
✨ Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@silo-triage silo-triage Bot added bug Something isn't working go Pull requests that update go code impact: usability Core flow broken or severely blocked priority: P2 Limited scope, workaround exists, or polish labels Oct 14, 2026

@Quick104 Quick104 left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adversarial review (gpt-6.1-sol, reviewed cef03ad)

Two findings verified against the source. Focused Go tests could not run because the Go toolchain is unavailable.

Comment thread internal/watchsync/lists.go Resolved
Comment thread internal/watchsync/lists.go Resolved
…r adds

A full import now counts each IMDb, TMDB, and TVDB id on a provider row as
present, because a plugin's key can use a different id than the one stored at
export (Trakt keys shows by TVDB id first). Otherwise an ambiguous match on two
copies of a series removed both locally.

An import skips re-adding an item with a pending local removal only when the
provider's listing is not newer than the removal, so a title re-added on the
provider after a failed removal is imported instead of removed again.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1c2ca9cd44

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread internal/watchsync/lists.go Resolved
Comment thread internal/watchsync/lists.go Resolved
A full import records each listed key with the kind of title the provider
row names, so a movie row no longer keeps a series with the same TMDB id. A
row or stored item without a kind still matches any kind.

Plugins that omit listed_at get the import time; RemoteFavorite now marks
that time as guessed, and an import never treats a guessed listing as newer
than a pending local removal.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Comment thread internal/watchsync/lists.go Resolved
Comment thread internal/watchsync/lists.go Resolved
Comment thread internal/watchsync/lists.go Resolved
Comment thread internal/watchsync/lists.go Resolved
…ds after tombstones

The migration now runs without a transaction, builds the non-unique key
index concurrently under a new name, and drops the unique one concurrently,
so list syncs keep reading and writing the table while it runs. Down
restores the unique index the same way.

A tombstone in an incremental read clears the pending local removal of the
rows it unlists, so a later row in the same read that lists the item again
counts as a new add.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@silo-kody

silo-kody Bot commented Oct 14, 2026 •

Copy link
Copy Markdown

Silo Kody — review complete

Review finished. Check the inline comments for findings and verify each suggestion against the code and tests.

Reviewing changes in Silo
  • Include the related issue, expected behavior, and validation steps in the PR description.
  • For API changes, describe the effect on Apple and Android clients and Jellyfin compatibility.
  • For plugin changes, identify the affected SDK contract, plugin, and catalog entry.
  • Follow this repository's AGENTS.md and CONTRIBUTING.md.
  • Request another review with @kody start-review in a PR comment.
  • React with 👍 or 👎 to give feedback on individual suggestions.
Review settings
Review Options

The following review options are enabled or disabled:

Options Enabled
Bug ✅
Performance ✅
Security ✅
Business Logic ❌
⚠️ 1 Kody Rule(s) were not evaluated

These rules declare that they need repository context beyond this diff, and the review could not retrieve it, so they were not judged on this pull request:

  • Preserve optional store capabilities through production wrappers

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 548549f65f

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

…ilds it

An interrupted Down can leave the concurrently built unique index invalid,
and IF NOT EXISTS would then skip rebuilding it on retry. Drop it
concurrently first, as Up does for its own index.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@Quick104
Quick104 merged commit c6ecf77 into main Oct 14, 2026
27 checks passed
@Quick104
Quick104 deleted the fix/issue-2466-list-shared-provider-key branch October 14, 2026 19:36
Quick104 added a commit that referenced this pull request Oct 14, 2026
Resolves the conflicts with main's list sync change (#2467), which now
removes every copy of a title that shares a provider key: a removal is
still counted once the local list changes, before the bookkeeping write.
TasteSeed returns to the renamed Personalize settings page (#2398).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working go Pull requests that update go code impact: usability Core flow broken or severely blocked priority: P2 Limited scope, workaround exists, or polish

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug] Favorites and watchlist export fails every sync when two library items share a provider key

1 participant