Repository navigation
feat(watchsync): sync Simkl movie and show ratings - #1355
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 Simkl ratings only when the matching /sync/activities rated_at moved, and then in full, so every read kind is a complete snapshot and unchanged kinds stay unknown. Simkl keeps anime, anime movies included, in its own domain: anime movies map to movies and other anime to series, so the anime read belongs to both kinds and an anime change re-reads both. Send ratings to /sync/ratings (series as shows) and clear them through /sync/ratings/remove, matching not_found echoes by any shared id. Rating an unlisted movie on Simkl files it as completed, so the provider opts into the watch gate: Silo sends a movie rating only after the profile has a completed play of the movie. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
|
Warning Review limit reachedNext included review available in 9 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 |
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. |
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.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 78b3a3fdd5
ℹ️ 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".
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]>
Simkl's ratings read documents no anime_type, so an anime movie reads as a series. The movie read then cannot be shown complete, and a rated anime movie could look removed. When any rated anime entry lacks a movie or tv type, the batch no longer claims a movie snapshot and warns. 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: b7d56bdbf9
ℹ️ 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]>
…y is skipped A rated Simkl entry with no usable id (for example an untyped anime entry whose only id was a TMDB id) was skipped with a warning, but FetchRatings still claimed its kind as a complete snapshot. A previously confirmed title missing for that reason would then be read as removed on Simkl. ratingRowsFromList now reports the kind of each skipped rated entry, and FetchRatings leaves those kinds out of SnapshotKinds. An untyped anime entry counts as series; the existing untyped path already keeps the movie snapshot out. 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]>
…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: 0e6c38e5a4
ℹ️ 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".
| switch strings.ToLower(strings.TrimSpace(animeType)) { | ||
| case simklAnimeTypeMovie, simklAnimeTypeTV: | ||
| return true | ||
| default: | ||
| return false |
There was a problem hiding this comment.
Treat known non-movie anime types as classified
typedAnime returns false for the documented ova, ona, special, and music video values even though animeRatingIdentity deliberately classifies all of them as series. Consequently, an account with any such rated title never gets a movie snapshot when movie ratings change, so removing an ordinary movie rating on Simkl remains unknown locally rather than being imported. Reserve the incomplete-movie safeguard for missing or genuinely unrecognized types.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Keeping this as designed. animeRatingIdentity drops the TMDB id from ova, ona, special and music video entries because Simkl can attach a TMDB movie id to them. The same title can then exist in Silo's catalog as a movie, matched through that id. If the read claimed a complete movie snapshot while such a rated entry was classified as a series without its TMDB id, the local movie rating would look absent and be deleted.
The price is that movie rating removals made on Simkl aren't imported while the account has a rated OVA, ONA, special or music video. They stay unknown, and nothing is deleted wrongly. The Simkl OpenAPI spec doesn't document anime_type on /sync/ratings at all, so most reads take the missing-type path anyway. I'd rather keep the safe side until a live account shows how these rows come back. Leaving this open for a maintainer call.
…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
Problem
Related issue: N/A
Validation tasks: none
Stack: builds on #1354; merge that first.
Rating sync (#1354) supports Trakt. Simkl users need the same two-way sync.
Approach
Reads. Ratings are read only when the matching
/sync/activitiesrated_athas moved, and then in full with the1,…,10rating filter. Every kind that is read is therefore a complete snapshot, and kinds that weren't read stay unknown instead of looking removed. A kind with a rated entry that has no usable id is also left out of the snapshot, with a warning.Anime. Simkl keeps anime, anime movies included, in its own domain:
anime_typemoviemaps to a movie andtvto a series.Writes.
/sync/ratings, with series sent asshows(Simkl resolves anime there too)./sync/ratings/remove.not_foundechoes are matched to items by any shared id, and results name items by media item id only.Watch gate. Rating an unlisted movie on Simkl files it as completed. So Silo sends a movie rating only after the profile has watched the movie, unless Simkl already holds a rating for it. Series are not gated.
Validation
Tests cover:
rated_at;not_foundmatching by a different id subset, with a movie and show sharing a TMDB number;go test ./internal/watchsync/...passes.make lint-changedreports 0 issues.Not confirmed against a live account:
anime_type, which Simkl's docs show only for/sync/all-items;If
anime_typeis missing, anime movies read back as series and are re-sent, but nothing is deleted: while any rated anime entry lacks amovieortvtype, the read does not claim a complete movie snapshot, so movie removals wait for a read without such entries.Risks
Each run that finds a changed bucket does full reads for it. Unchanged buckets cost only the activities request.
Checklist
AI Disclosure
🤖 Generated with Claude Code