Skip to content

fix(watchsync): match Trakt not_found echoes by any shared id - #1353

Merged
Quick104 merged 21 commits into
mainfrom
fix/watchsync-trakt-not-found-ids
Sep 24, 2026
Merged

Quick104 merged 21 commits into
mainfrom
fix/watchsync-trakt-not-found-ids

Conversation

@Quick104

Copy link
Copy Markdown
Contributor

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_found echoes 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 produced tvdb:…, never matched the local imdb:… 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

traktIDIndex matches 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:

  • An item known only by its Trakt id (key 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.
  • The service decided an export by checking whether the item's media item id or its provider key appeared in the sent list. A movie and a show can share a key such as tmdb:550, so a missing movie could be counted as sent because the show was. exportItemOutcome now 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

  • New tests: an item known only by its Trakt id; exportItemOutcome with 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.
  • The show and mixed-batch tests fail against the old matching.
  • go test ./internal/watchsync/... passes. make lint-changed reports 0 issues.

Risks

None identified.

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 P1–P4 read-only. For this PR it found that items known only by a Trakt id were reported sent without being sent, and that the service's key-based lookup could credit a missing movie with a same-key show's result. Both are fixed here with tests.

🤖 Generated with Claude Code

Quick104 and others added 4 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]>

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

@coderabbitai

coderabbitai Bot commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

Next included review available in 22 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: 7c229c72-4f83-4bf5-8956-4196f1bcabbe

📥 Commits

Reviewing files that changed from the base of the PR and between 091478c and 11bfac7.

📒 Files selected for processing (5)
  • internal/watchsync/lists.go
  • internal/watchsync/providers/trakt/provider.go
  • internal/watchsync/providers/trakt/provider_test.go
  • internal/watchsync/service.go
  • internal/watchsync/service_test.go

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.

@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:38:21.767072Z 11bfac7 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 16 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]>
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]>
…-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]>
…agination

# Conflicts:
#	internal/watchsync/providers/trakt/provider.go
@Quick104
Quick104 deleted the branch main September 24, 2026 18:33
@Quick104 Quick104 closed this Sep 24, 2026
@Quick104 Quick104 reopened this Sep 24, 2026
@Quick104
Quick104 changed the base branch from fix/watchsync-trakt-pagination to main September 24, 2026 18:34

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

@Quick104
Quick104 merged commit de0f070 into main Sep 24, 2026
10 checks passed
@Quick104
Quick104 deleted the fix/watchsync-trakt-not-found-ids branch September 24, 2026 18:45
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