Skip to content

feat(watchsync): sync MDBList movie and show ratings - #1356

Merged
Quick104 merged 39 commits into
mainfrom
feat/watchsync-mdblist-ratings
Sep 24, 2026
Merged

Quick104 merged 39 commits into
mainfrom
feat/watchsync-mdblist-ratings

Conversation

@Quick104

@Quick104 Quick104 commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Related issue: N/A
Validation tasks: none
Stack: builds on #1354; merge that first.

Rating sync (#1354) supports Trakt. MDBList users need the same two-way sync.

Approach

Reads. GET /sync/ratings is read with cursor paging, falling back to offsets. When total is reported, a read that ends short of it is not a complete snapshot of either kind.

  • Movies form a snapshot once every page is read.
  • Shows form one only when MDBList returns a shows list at all, since its documented sample has none and absent shows must not read as removals.
  • A rated title with no IMDb, TMDB or TVDB id also keeps its kind out of the snapshot.
  • If any page repeats an entry (a rating, season or episode), ratings changed during the read and the pages shifted, so neither kind is a snapshot.

Writes. Ratings go to /sync/ratings and removals to /sync/ratings/remove, in requests of at most 200 titles.

MDBList answers writes with counts, not item identities. The watchlist result mapping therefore becomes a shared helper:

  • a set with any not_found fails the batch;
  • a removal with any not_found reconciles it;
  • a rating write that reports errors fails the batch.

Watchlist behavior is unchanged.

Validation

  • Tests cover:

    • cursor paging;
    • offset paging with total (three pages for 2,500 entries);
    • short reads in each response shape;
    • missing, null and empty shows;
    • rows without external ids;
    • write and remove payloads;
    • both documented response shapes;
    • the batch outcomes;
    • chunking;
    • watchlist behavior staying unchanged.
  • go test ./internal/watchsync/... passes. make lint-changed reports 0 issues.

  • Not confirmed against a live account:

    • the show item shape in ratings reads;
    • whether MDBList keeps show-level ratings.

    If it drops them silently, series ratings are re-sent each run, but none are deleted.

Risks

Ratings are read in full on every run (one request per 1,000 ratings), like MDBList's other reads.

Checklist

  • I read and can explain the complete diff.
  • This pull request addresses one concern.

AI Disclosure

  • Harness: Claude Code (in T3 Code)
  • Tool(s): Claude Code subagents
  • Model(s): claude-opus-5-5
  • Involvement: Fully AI-generated; the maintainer set scope and product decisions. Human review of the diff is pending.
  • Adversarial review: An independent Claude Opus 5.5 subagent reviewed this provider read-only against MDBList's schema, focusing on snapshot claims that could delete ratings. It found that a page without next_cursor ended the read short of total while still claiming both kinds, and that MDBList-only ids counted as identified; both are fixed with tests.

🤖 Generated with Claude Code

Quick104 and others added 7 commits September 24, 2026 00:42
Trakt and Simkl answered every non-2xx the same way, so a 429 never
became a RateLimitedError and the sync service never deferred the
account. Both providers now map 429 (and Simkl's documented
rate_limit/RATE_LIMIT bodies) to RateLimitedError with the provider's
Retry-After, retry short waits in place, and pace authenticated writes
to one per second per access token as the providers document.

Retry-After parsing and the per-credential write limiter move into
internal/watchsync so MDBList, Trakt and Simkl share them.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Since April 2026 Trakt serves only the first 100 items when page and
limit are omitted. Favorites, watchlist, and history reads sent neither,
so users with longer lists got partial imports, and ExportWatched
compared local plays against a truncated history and re-sent older
plays, which Trakt stores as duplicates.

Generalize the watched-only pager into fetchTraktPages and use it for
watched, favorites, watchlist, and history. It always sends limit=250,
stops on X-Pagination-Page-Count, a page shorter than the applied
X-Pagination-Limit, or an empty page, caps the walk, and returns no
rows when any page fails.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
The MDBList watch-sync provider puts the API key in the request query
string. Transport errors wrap *url.Error, whose message includes that
URL, and those errors reach the connection's last_error, sync run
errors shown in the web UI, and logs. Build the keyed URL only inside
the single request helper, sanitize transport and request-build errors
with logredact.SanitizeURLError, and mask the key (raw or escaped) in
error-body excerpts. Cancellation and timeout classification is kept.

Same bug class as #692, which covers the separate internal/mdblist
discovery client.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Trakt favorites and watchlist writes mapped not_found echoes back to
request items by one derived key per side. Silo keys items IMDb-first
while the provider keyed shows TVDB-first, so a show sent with both ids
and echoed as missing was still reported as sent. Match echoes by any
shared identifier (Trakt id, slug, IMDb, TMDB, TVDB), namespaced by kind
because TMDB and TVDB number movies and shows separately.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Silo profiles rate movies and series with 1-5 stars, but watch-provider
sync never carried ratings. Add rating sync with separate import and
export settings per connection; new connections get both on, existing
connections start with both off.

Each item is a three-way merge of the local rating, the provider rating
(integers 1-10, converted to stars by rounding half up), and the last
rating both sides agreed on, stored in watch_provider_rating_items. The
side that changed wins; a conflict never deletes and otherwise the newer
change wins. Missing items count as provider removals only in complete
snapshots of their kind, when no read row shares one of their ids, and
when a previous read confirmed the provider held the rating. Imports are
compare-and-set against the observed local value, so concurrent edits
and multi-node runs stay safe without a lock. Local rating changes are
sent through a value-less event from the shared rating seam.

Settings and run counters are exposed on /api/v2 and in the web
settings page; the frozen v1 responses and settings update are
unchanged apart from two additive capability flags.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Read every Trakt movie and show rating through the paged reader and
report both as complete snapshots. Send ratings to /sync/ratings with
the local rating time and clear them through /sync/ratings/remove,
mapping not_found echoes back to items by any shared id. Trakt already
uses the 1-10 scale, so values pass through unchanged. Season and
episode ratings are left alone.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Read MDBList ratings with cursor paging. Movies form a complete
snapshot once every page is read; shows do only when MDBList returns a
shows list at all, because its documented response has none and absent
shows must not read as removals. A kind with a rated title Silo cannot
identify is also left out of the snapshot. Send ratings to
/sync/ratings and clear them through /sync/ratings/remove in requests of
at most 200 titles.

MDBList answers writes with counts, not item identities, so the watchlist
result mapping becomes a shared helper: a set with any not_found fails
the batch, a removal with any not_found reconciles it, and a rating
write that reports errors fails the batch.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@coderabbitai

coderabbitai Bot commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

Next included review available in 8 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 2 included reviews currently available.

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Advanced

Run ID: 5c4cef2a-b56e-4ab9-8361-01786da74aff

📥 Commits

Reviewing files that changed from the base of the PR and between de0f070 and b0fd39b.

📒 Files selected for processing (54)
  • cmd/silo/main.go
  • contracts/api/v2/fixtures/get_system_info_ok.json
  • contracts/api/v2/fixtures/watch_provider_api_key_ok.json
  • contracts/api/v2/fixtures/watch_provider_connection_ok.json
  • contracts/api/v2/fixtures/watch_provider_poll_ok.json
  • contracts/api/v2/fixtures/watch_provider_settings_ok.json
  • contracts/api/v2/fixtures/watch_provider_sync_ok.json
  • contracts/api/v2/fixtures/watch_provider_update_ok.json
  • contracts/api/v2/openapi.json
  • docs/architecture/api-contract.md
  • docs/architecture/watch-provider-rating-sync.md
  • internal/api/handlers/ratings.go
  • internal/api/handlers/watch_providers.go
  • internal/api/handlers/watch_providers_test.go
  • internal/api/router.go
  • internal/apiv2/request_lifecycle.go
  • internal/apiv2/request_lifecycle_test.go
  • internal/apiv2/schema_names.go
  • internal/apiv2/schema_ownership_test.go
  • internal/catalog/orphan_cleanup.go
  • internal/catalog/orphan_cleanup_test.go
  • internal/catalog/ratings_repo.go
  • internal/catalog/ratings_repo_db_test.go
  • internal/catalog/reattribute/rating_sync_move_db_test.go
  • internal/catalog/reattribute/reattribute.go
  • internal/metadata/provider_id_integrity.go
  • internal/metadata/provider_id_integrity_test.go
  • internal/watchsync/connection_settings.go
  • internal/watchsync/lists.go
  • internal/watchsync/providers/mdblist/provider.go
  • internal/watchsync/providers/mdblist/provider_test.go
  • internal/watchsync/providers/mdblist/ratings.go
  • internal/watchsync/providers/mdblist/ratings_test.go
  • internal/watchsync/providers/trakt/history_test.go
  • internal/watchsync/providers/trakt/pagination_test.go
  • internal/watchsync/providers/trakt/provider.go
  • internal/watchsync/providers/trakt/provider_test.go
  • internal/watchsync/providers/trakt/ratings.go
  • internal/watchsync/providers/trakt/ratings_test.go
  • internal/watchsync/providers/trakt/watched_test.go
  • internal/watchsync/ratings.go
  • internal/watchsync/ratings_db_test.go
  • internal/watchsync/ratings_test.go
  • internal/watchsync/repository.go
  • internal/watchsync/service.go
  • internal/watchsync/service_test.go
  • internal/watchsync/types.go
  • migrations/sql/20260923214332_watch_provider_ratings.sql
  • web/src/api/v2/schema.ts
  • web/src/hooks/queries/ratingsSurfaceRefresh.test.ts
  • web/src/hooks/queries/ratingsSurfaceRefresh.ts
  • web/src/hooks/queries/watchProviders.test.ts
  • web/src/hooks/queries/watchProviders.ts
  • web/src/pages/settings/WatchProvidersSettings.tsx

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.

@greptile-apps greptile-apps 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.

Quick104 has reached the 50-credit limit for trial accounts. To continue receiving code reviews, upgrade your plan.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 24, 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-09-24T18:02:34.582270Z b0fd39b 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.

Quick104 and others added 8 commits September 24, 2026 01:18
A provider 429 during a watch-provider call, such as Trakt's slow_down
answer to a device-code poll, now reaches clients as a rate-limited
problem carrying the provider's wait instead of an internal error.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
One title added and another removed between page requests keeps the
item count unchanged while shifting page boundaries, so a row can be
skipped without any header changing. A listing that spans several pages
is now read twice, and the read fails unless both passes return the
same rows. Single-page listings are read once.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Address review findings on the rating sync core:

- The shared capabilities object is serialized by the frozen /api/v1
  responses, so its rating flags were leaking into v1. v2 now projects
  its own WatchProviderCapabilities type (same schema name and fields,
  so the v2 contract is unchanged) and the shared type hides the flags.
- A sync still in flight when the connection is re-bound to another
  provider account (possibly on another node) no longer applies the old
  account's ratings.
- The import compare-and-set also compares rated_at, so re-saving the
  same stars after the sync read them still wins.

Co-Authored-By: Claude Opus 5.5 (1M context) <[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: 16525984cc

ℹ️ 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".

Quick104 and others added 11 commits September 24, 2026 02:01
Trakt allows 500 authenticated GETs per five minutes. Reading a large
listing twice could exceed that, and the 429 discarded both passes, so a
very large account retried from page 1 without ever finishing. Paged
reads are now paced per token: a burst of 50 pages, then one every 675
ms, which keeps any five-minute window under the limit.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
A local limiter refuses at once when the next slot lies past the
context deadline. That was an ordinary error, so watched exports that
were never sent were marked failed. The refusal is now a
RateLimitedError, which leaves the work pending for a later run; a
cancelled context still returns its own error. MDBList's limiter gets
the same treatment.

Starting Trakt device authorization now reports a 429 as a rate limit
with the provider's Retry-After, like polling and token refresh.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
When a transport error quoted the keyed URL in its own message, the
masking fallback replaced it with a plain error, so errors.Is and
errors.As no longer matched cancellations, deadlines, or net.Error
timeouts. The masked error now answers Is and As from the original,
without an Unwrap that would expose its message.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
… read

A rating added or changed between MDBList page requests shifts the pages: a
later page repeats an entry and skips another. FetchRatings counted entries
against total, so the repeat hid the skip and the read still claimed both
kinds as complete snapshots, letting a skipped title read as removed.

FetchRatings now keys every entry it reads, a rating row by kind and provider
item key and any other entry (unrated, unidentified, season, episode) by its
raw JSON. A repeat in either cursor or offset mode leaves both kinds out of
SnapshotKinds with a warning, since the skipped entry's kind is unknown. The
ratingsPage test helper now numbers episodes so clean pages stay distinct.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…nged mid-send

Rating cursors now update with a jsonb patch conditioned on the bound
account instead of rewriting the whole connection row, so a concurrent
settings edit or rebind is not overwritten. A confirmed set or removal
that finds the local rating changed during the send resends the current
value once. An account rebind drops other accounts' agreed rows only
after the new binding is saved.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…-trakt-pagination

Also routes the Trakt page limiter's refused waits through
LimiterWaitError so they defer the sync like a 429.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Quick104 and others added 7 commits September 24, 2026 02:20
…until settled

Agreed-rating upserts and deletes now apply only while the connection is
still bound to the row's provider account, so a run that outlived a
rebind can't take rows back from the new account. Ratings that change
while their write is in flight are resent up to three times; if they
still haven't settled, the agreed row is dropped so the next merge keeps
the newer rating instead of importing a stale provider value.

Co-Authored-By: Claude Opus 5.5 (1M context) <[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: 4610beeaf9

ℹ️ 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".

Quick104 and others added 6 commits September 24, 2026 17:37
…te removals

Agreed-rating upserts now share-lock the connection row and check the
bound account under that lock, so a rebind either waits for the write and
clears it or the write finds no binding. When resends run out, the agreed
row records the value last confirmed on the provider, so a removal made
during the last resend is sent next run instead of being imported back.
The web settings page now refreshes rating, catalog, section and
recommendation queries when the manual sync it started finishes.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…agination

# Conflicts:
#	internal/watchsync/providers/trakt/provider.go
…rating-sync

# Conflicts:
#	contracts/api/v2/fixtures/get_system_info_ok.json
@Quick104
Quick104 changed the base branch from feat/watchsync-rating-sync to main September 24, 2026 18:48
@Quick104
Quick104 merged commit 064184d into main Sep 24, 2026
12 checks passed
@Quick104
Quick104 deleted the feat/watchsync-mdblist-ratings branch September 24, 2026 19:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant