Repository navigation
fix(watchsync): correct Trakt TV episode sync payload - #254
Conversation
…argets the right show
omitempty on a struct value is a no-op in encoding/json, so the history
export sent all-zero episode ids ({tmdb:0,tvdb:0}); Trakt matched the
degenerate id to one default show, mis-recording every watched series.
Make episode IDs a *traktIDs pointer and attach it only when a real id
exists, else use the show + season/number fallback (mirroring scrobble).
Adds a debug log on the show-fallback path and payload tests.
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Episode history exports were dropped by Trakt because they were emitted into the flat episodes[] array with a bogus sibling show object plus season/number keys — a shape the Trakt API does not accept, so it silently discarded them (200/201 with no history recorded). Movies were unaffected since they always carry their own external IDs. Two coordinated changes: - watchstate/identity.go: ResolveHistoryIdentity now carries the episode's own imdb/tmdb/tvdb IDs (already stored on the episodes table) so episodes with real IDs export via the flat episodes[].ids form, matching how movies work. - watchsync/providers/trakt/provider.go: episodes without their own ID now serialize into the correct nested shows[].seasons[].episodes[] structure keyed by the show's IDs, merging episodes by show/season. Same fix applied to the history-remove payload. Empty-payload guards account for the new shows[] list. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
Warning Review limit reached
Next review available in: 48 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThis PR adds episode-specific provider IDs (IMDB/TMDB/TVDB) to watch identity resolution and extends the Trakt provider to support nested show/season/episode structures in history export/remove payloads when episode-level IDs are unavailable, merging repeated episodes under the same show/season, with expanded test coverage. ChangesEpisode Identity and Trakt Nested History Payloads
Estimated code review effort: 3 (Moderate) | ~25 minutes Sequence Diagram(s)sequenceDiagram
participant Client as watchsync Client
participant Provider as TraktProvider
participant Builder as buildHistoryPayload
participant Payload as HistoryPayload
Client->>Provider: ExportHistory(plays)
Provider->>Builder: build payload from plays
loop for each play
Builder->>Builder: playOwnIDs(play)
alt episode IDs present
Builder->>Payload: append to Movies/Episodes
else no episode IDs
Builder->>Builder: playSeriesIDs(play)
Builder->>Builder: appendNestedEpisode(show, season, episode)
Builder->>Payload: merge into Shows[]
end
end
Provider->>Provider: check Movies/Episodes/Shows all empty?
Provider->>Client: send request or skip if empty
Estimated code review effort: 3 (Moderate) | ~25 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
internal/watchstate/identity.go (1)
51-60: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick winDon't require series IDs when the episode already has its own IDs.
Line 52 still drops the entire episode identity when
seriesIDsis empty. That means episodes with a valid episode IMDb/TMDB/TVDB ID but missing series IDs never reachinternal/watchsync/service.goasLocalPlay.IMDbID/TMDBID/TVDBID, so the new flatepisodes[].idspath is skipped even though Trakt could address the episode directly. Only gate onseriesIDswhenepisodeProviderIDs(episode)is also empty and you truly need the nested show fallback.Proposed fix
- seriesIDs := providerIDMap(r.loadProviderIDs(ctx, episode.SeriesID)) - if len(seriesIDs) == 0 { + episodeIDs := episodeProviderIDs(episode) + seriesIDs := providerIDMap(r.loadProviderIDs(ctx, episode.SeriesID)) + if len(episodeIDs) == 0 && len(seriesIDs) == 0 { return userstore.WatchIdentity{} } @@ return userstore.WatchIdentity{ StableType: "episode", - ProviderIDs: episodeProviderIDs(episode), + ProviderIDs: episodeIDs, SeriesProviderIDs: seriesIDs, Season: &seasonNumber, Episode: &episodeNumber, }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@internal/watchstate/identity.go` around lines 51 - 60, In watchstate/identity.go, the WatchIdentity builder currently returns an empty identity whenever seriesIDs is empty, even if episodeProviderIDs(episode) already contains usable episode IDs. Update the logic around the WatchIdentity construction to only require seriesIDs when episodeProviderIDs(episode) is also empty and you need the nested show fallback, so episode-specific IMDb/TMDB/TVDB IDs still flow through to internal/watchsync/service.go.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In `@internal/watchstate/identity.go`:
- Around line 51-60: In watchstate/identity.go, the WatchIdentity builder
currently returns an empty identity whenever seriesIDs is empty, even if
episodeProviderIDs(episode) already contains usable episode IDs. Update the
logic around the WatchIdentity construction to only require seriesIDs when
episodeProviderIDs(episode) is also empty and you need the nested show fallback,
so episode-specific IMDb/TMDB/TVDB IDs still flow through to
internal/watchsync/service.go.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 7ff3213b-ca89-473b-915e-c855eb02d69d
📒 Files selected for processing (3)
internal/watchstate/identity.gointernal/watchsync/providers/trakt/provider.gointernal/watchsync/providers/trakt/provider_test.go
Address CodeRabbit review on PR Silo-Server#254: the episode identity builder dropped the whole identity whenever series IDs were empty, so episodes with a valid episode IMDb/TMDB/TVDB ID but no series IDs never reached the flat episodes[].ids Trakt path. Only require series IDs when the episode has no IDs of its own (nested show fallback). Co-Authored-By: Claude Opus 4.8 <[email protected]>
Address CodeRabbit review on PR Silo-Server#254: the episode identity builder dropped the whole identity whenever series IDs were empty, so episodes with a valid episode IMDb/TMDB/TVDB ID but no series IDs never reached the flat episodes[].ids Trakt path. Only require series IDs when the episode has no IDs of its own (nested show fallback). Co-Authored-By: Claude Opus 4.8 <[email protected]>
* fix(watchsync): omit empty Trakt episode ids so series mark-watched targets the right show
omitempty on a struct value is a no-op in encoding/json, so the history
export sent all-zero episode ids ({tmdb:0,tvdb:0}); Trakt matched the
degenerate id to one default show, mis-recording every watched series.
Make episode IDs a *traktIDs pointer and attach it only when a real id
exists, else use the show + season/number fallback (mirroring scrobble).
Adds a debug log on the show-fallback path and payload tests.
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
* fix(watchsync): sync TV episodes to Trakt via valid nested shows payload
Episode history exports were dropped by Trakt because they were emitted
into the flat episodes[] array with a bogus sibling show object plus
season/number keys — a shape the Trakt API does not accept, so it
silently discarded them (200/201 with no history recorded). Movies were
unaffected since they always carry their own external IDs.
Two coordinated changes:
- watchstate/identity.go: ResolveHistoryIdentity now carries the
episode's own imdb/tmdb/tvdb IDs (already stored on the episodes
table) so episodes with real IDs export via the flat episodes[].ids
form, matching how movies work.
- watchsync/providers/trakt/provider.go: episodes without their own ID
now serialize into the correct nested shows[].seasons[].episodes[]
structure keyed by the show's IDs, merging episodes by show/season.
Same fix applied to the history-remove payload. Empty-payload guards
account for the new shows[] list.
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
* fix(watchstate): keep episode identity when episode has its own IDs
Address CodeRabbit review on PR Silo-Server#254: the episode identity builder
dropped the whole identity whenever series IDs were empty, so episodes
with a valid episode IMDb/TMDB/TVDB ID but no series IDs never reached
the flat episodes[].ids Trakt path. Only require series IDs when the
episode has no IDs of its own (nested show fallback).
Co-Authored-By: Claude Opus 4.8 <[email protected]>
---------
Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
Problem
Two related defects broke Trakt TV-episode watch sync:
episodes[]array with a bogus siblingshowobject, which Trakt rejected — episodes never synced.Fix
shows[].seasons[].episodes[]payload instead of the flat array, matching Trakt's history contract.Notes
internal/watchsync/providers/trakt/plus a smallinternal/watchstate/identity.gohelper.provider_test.go;go test ./internal/watchsync/providers/trakt/passes.AI-use disclosure: authored with AI assistance.
🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
Bug Fixes