Repository navigation
fix(watchsync): match Trakt not_found echoes by any shared id - #1353
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]>
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.
|
Warning Review limit reachedNext included review available in 22 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 (5)
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. |
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]>
…mdblist-key-redaction
…-trakt-pagination
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]>
…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]>
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…agination # Conflicts: # internal/watchsync/providers/trakt/provider.go
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.
Problem
Related issue: N/A
Validation tasks: none
Stack: builds on #1352; merge that first.
After a Trakt favorites or watchlist write, the provider matched Trakt's
not_foundechoes to the request items by comparing one derived key per side. Silo keys items IMDb-first, but the provider rebuilt show keys TVDB-first. A show sent with both ids and echoed back as missing producedtvdb:…, never matched the localimdb:…key, and was reported as sent. The item was then recorded as present on Trakt when it wasn't. Rating export, stacked on this PR, reuses the same mapping.Approach
traktIDIndexmatches an echo to an item when the two share any identifier: Trakt id, slug, IMDb, TMDB, or TVDB. Identifiers are namespaced by item kind, because TMDB and TVDB number movies and shows separately. Zero ids never match. Result pairs,(MediaItemID, key), and the handling of items without usable ids are unchanged.Two related fixes:
trakt:5) is now sent with that id. Before, it was left out of the request but still reported as sent, so a removal was recorded while Trakt kept the item.tmdb:550, so a missing movie could be counted as sent because the show was.exportItemOutcomenow decides by media item id and uses the key only when the provider names items by key alone.One limit remains: an echo that carries only an id the item lacks (for example a bare Trakt id for an item Silo knows only by IMDb) can't be matched, and the item is still reported as sent. The code comment says so.
Validation
exportItemOutcomewith a movie and show sharing a key; a show sent with IMDb and TVDB and echoed by TVDB only, against favorites and watchlist add and remove; a TMDB-only movie; a mixed batch; a movie and show sharing a TMDB number; an echo carrying only unknown ids; and a unit test for the index.go test ./internal/watchsync/...passes.make lint-changedreports 0 issues.Risks
None identified.
Checklist
AI Disclosure
🤖 Generated with Claude Code