Repository navigation
feat(watchsync): sync MDBList movie and show ratings - #1356
Conversation
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]>
|
Warning Review limit reachedNext included review available in 8 minutes. View limit detailsLimit 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. Review configuration: ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (54)
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. Comment |
There was a problem hiding this comment.
Quick104 has reached the 50-credit limit for trial accounts. To continue receiving code reviews, upgrade your plan.
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
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]>
…mdblist-key-redaction
…-trakt-pagination
There was a problem hiding this comment.
💡 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".
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]>
…mdblist-key-redaction
…-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]>
…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]>
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
There was a problem hiding this comment.
💡 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".
…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]>
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
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/ratingsis read with cursor paging, falling back to offsets. Whentotalis reported, a read that ends short of it is not a complete snapshot of either kind.showslist at all, since its documented sample has none and absent shows must not read as removals.Writes. Ratings go to
/sync/ratingsand 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:
not_foundfails the batch;not_foundreconciles it;errorsfails the batch.Watchlist behavior is unchanged.
Validation
Tests cover:
total(three pages for 2,500 entries);shows;go test ./internal/watchsync/...passes.make lint-changedreports 0 issues.Not confirmed against a live account:
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
AI Disclosure
next_cursorended the read short oftotalwhile still claiming both kinds, and that MDBList-only ids counted as identified; both are fixed with tests.🤖 Generated with Claude Code