You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Part of #4613 (its path 1, and the first bullet of its Expected behavior). This doesn't close the issue.
Validation tasks: none
Other clients: Apple, Android and Roku get real episode titles for the affected show after its next refresh; no client change is needed. Jellyfin-compat N/A.
When a refresh finds that an item's provider IDs belong to another confirmed item, rebindItemOnto (internal/metadata/service.go) moves the source's library memberships, file links, provider IDs and user state onto the target. Then it deletes the source only if its status is deletable. From the Process path, a source with durable provider IDs reaches the rebind only while it is provisional, and the delete keeps it only if its status has turned matched since. A kept source has no library, no files and no provider ID rows. Its episodes keep their tmdb_id, tvdb_id and imdb_id, which are unique across all episodes (idx_episodes_tmdb_id and the like). So the target's episode upserts fail on those IDs, and the real episodes keep their scanner placeholders (Episode 1…). The issue saw 47 such items, one holding 13 episodes' TMDB IDs for ten days.
Approach
One new step in rebindItemOnto, after the source delete: it sets tmdb_id, tvdb_id and imdb_id to '' (the columns' empty default) on the source's episodes that still hold any. A deleted source took its episodes with it (ON DELETE CASCADE), so the step only affects a kept source. The target's next refresh can then store the IDs.
It runs in the rebind's transaction, after the user-state reattribution, which maps episodes by season and episode number and doesn't read these IDs.
Not in this PR, from the same issue:
a periodic cleanup of series items with no membership, files or user state, whatever their status;
path 2: items held during the file-removal grace keep their IDs.
Both need their own design, so the issue stays open for them.
Validation
New TestRebindKeptSourceReleasesEpisodeIDsPostgres sets up two matched series, the source with an episode holding TMDB, TVDB and IMDb IDs. It rebinds the source onto the target the way Process does, with a matched source not deletable. It checks that the source is kept, that its episode's IDs are released, and that the target can then store an episode with the same IDs. Added to scripts/ci/db-contracts.txt.
With main's service.go, the kept source still holds the IDs (output under Evidence).
With this change: go test -count=1 ./internal/metadata/ passes against a local Postgres 18. lint-changed: 0 issues.
In ./internal/catalog/, TestEpisodeCatalogRefreshSerializesFileChangesPostgres fails here with a deadlock, on this branch and on clean main alike (two runs each). CI runs it in its own environment.
Not tested: a live rebind across two libraries, as in the issue.
Evidence
No screen changes until the target's next refresh, which then shows its episodes' real titles. Results of go test -count=1 -v -run TestRebindKeptSourceReleasesEpisodeIDsPostgres ./internal/metadata/ against a local Postgres 18.
--- PASS: TestRebindKeptSourceReleasesEpisodeIDsPostgres
ok github.com/Silo-Server/silo-server/internal/metadata
Risks
The kept source's episodes lose their external IDs. The source has no library, files or provider IDs, so nothing shows or plays it. Items already left like this before the change keep their IDs until another rebind or the cleanup the issue asks for.
No API, schema or config change.
Checklist
I read and can explain the complete diff.
This pull request addresses one concern.
Each test this pull request adds meets "Decide what to test" in CONTRIBUTING.md.
The Evidence section shows every change a user can see, or how I checked a change nobody sees.
AI Disclosure
Harness: Claude Code in the Claude desktop app
Tool(s): Claude Code
Model(s): claude-opus-5-5
Involvement: Fully AI-generated, not yet human verified
Release kept rebind source's episode external IDs in rebindItemOnto
When a rebind keeps the source series (allowMatchedSource=false), its episodes retain TMDB, TVDB, and IMDb IDs. This blocks other episodes from storing those IDs due to uniqueness constraints. MetadataService.rebindItemOnto now clears those provider IDs and bumps updated_at for remaining source episodes in a new transaction step, added in service.go. Also adds a PostgreSQL integration test, TestRebindKeptSourceReleasesEpisodeIDsPostgres, in rebind_kept_source_episode_ids_db_test.go, and registers it in db-contracts.txt.
Behavioral Change: kept source episodes lose their TMDB, TVDB, and IMDb IDs after a rebind
A rebind that keeps its source (a matched item with durable provider
IDs) moved the source's memberships, files and provider IDs, but its
episodes kept their TMDB, TVDB and IMDb IDs. Those are unique across
episodes, so the target's episodes could not store them and stayed
placeholders. The rebind now clears them on the source's episodes.
Part of Silo-Server#4613
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
No actionable comments were generated in the recent review.
Walkthrough
When a rebind keeps the source series, the operation clears TMDB, TVDB, and IMDb IDs from its episodes. A PostgreSQL integration test checks that a target episode can then use those IDs.
Changes: Kept source rebind
Layer / File(s)
Summary
Clear and verify episode IDs internal/metadata/service.go, internal/metadata/rebind_kept_source_episode_ids_db_test.go, scripts/ci/db-contracts.txt
After attempting to delete the source item, rebindItemOnto clears external IDs from episodes still associated with the source. The PostgreSQL test checks that the source remains, its episode IDs are cleared, and a target episode can be inserted with those IDs. The CI database-contract list includes the test.
Issue 4613 — The change clears episode IDs that block target episode upserts when a rebind keeps its source. It does not address orphan cleanup or the grace-period hold path.
Suggested reviewers:quick104, rhainland
Merge Risk: Minimal · up to 51d45
When a rebind keeps the source series, its episodes now release their TMDB, TVDB, and IMDb IDs so the target can reuse them. The change is small and covered by a database test. It does not clean up existing orphans, which the linked issue still tracks. No merge-blocking risk was found.
Security architecture risk: Minimal · up to 51d45
The change releases episode identifiers from the old series as part of the same operation that moves its library links and user state. The destination can then claim those identifiers on its next refresh. The reviewed change did not establish a new security issue or weaken ownership controls.
Security review details
Security Blast Radius
observed — The write can affect every episode with a nonempty external ID on the retained source series, not just episodes present on the destination. Its direct database scope is one source series per rebind, while the existing uniqueness rules apply across all episodes.
Trust Boundaries and Controls
observed — The new database write inherits the existing rebind authority. Explicit curation checks the items through the curation guard before mutation; automatic metadata processing continues to use its existing path without that explicit-curation check.
Resilience and Maintainability Implications
inferred — The database enforces at most one holder of each nonempty provider ID, but the clear does not reserve IDs for the destination. If an existing source writer can repopulate an ID before the destination refresh writes it, the previous conflict can recur. That writer ordering was not established end to end.
Pre-merge checks: 4
Check name
Status
Explanation
Title check
The title names the main change: a fix in the metadata package that clears external IDs (TMDB, TVDB, IMDb) from a kept rebind source's episodes. The raw summary shows the new step in rebindItemOnto th…
Description check
The description states the problem, the approach, the validation steps, and the evidence. It names the changed function (rebindItemOnto), the new test, and the db-contracts.txt entry. These match the …
Linked Issues check
Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check
Check skipped because no linked issues were found for this pull request.
Full details: Title check
Explanation
The title names the main change: a fix in the metadata package that clears external IDs (TMDB, TVDB, IMDb) from a kept rebind source's episodes. The raw summary shows the new step in rebindItemOnto that does this, and the objectives describe the same change. The title is specific and concise.
Full details: Description check
Explanation
The description states the problem, the approach, the validation steps, and the evidence. It names the changed function (rebindItemOnto), the new test, and the db-contracts.txt entry. These match the raw summary and the objectives. It is not off-topic.
Finishing Touches
Generate unit tests (beta)
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info
Run configuration
Source mode: Auto
Repository: Unavailable
Branch: Unavailable
File: No configuration file from this repository applied
Commit: Unavailable
Layers: Organization UI
Review profile: CHILL
Plan: Advanced
Run ID: 5651e13a-7a18-44b8-bb64-64dc980c5f59
Commits
Reviewing files that changed from the base of the PR and between dc85466 and 51d45fc.
Files selected for processing: 1
scripts/ci/db-contracts.txt
Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 2 remain after this review.
Process rebinds a source with durable provider IDs only while it reads
the source as provisional, so the rebind keeps a matched source only when
its status turned matched since. The comments described a steady state.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The reason will be displayed to describe this comment to others. Learn more.
🤖 Claude Code (claude-opus-5-5)
Review of d3fdeff. One finding: the SQL step is correct, but the description of when it runs doesn't match the code. Details are inline. The summary comment covers verification and the open question.
The reason will be displayed to describe this comment to others. Learn more.
Medium: the trigger this comment and the PR description give doesn't happen on a steady state.
Process only rebinds when isProvisionalOwnershipStatus(existingItem.Status) || len(durableIDs) == 0 (service.go:2898), and it passes allowMatchedSource = len(durableIDs) == 0:
A source with no durable IDs gets true, so a matched source is deleted.
A source with durable IDs reaches the rebind only if it was pending, unmatched or ambiguous when Process read it (service.go:2862). Those statuses are deletable.
The other callers (service.go:3557, :3678 and :9688, merge_items.go:102, canonicalize.go:112) all pass true.
So the delete keeps a matched source only when the source's status turned matched after Process read it. One way that can happen is a second pass on the same item under a different provider-ID dedup key: the dedup lock is in-memory and keyed by provider IDs. A matched item with durable IDs never enters the rebind from Process.
Impact: the step is still correct whenever the delete keeps a source, and the new test fails on the base for the stated reason. But the story in the comment and the PR body isn't how a deployment reaches this state, and #4613's 47 orphans may have come another way.
Repair: I'm rewording this comment and the test's comment to describe the real condition in a commit on this branch, so there's no need to change it yourself. Whether this explains #4613's orphans is left for the maintainers.
The reason will be displayed to describe this comment to others. Learn more.
🤖 Claude Code (claude-opus-5-5)
Reworded in dc85466, comments only. The step's comment and the test's comment now say a source is kept when its status turned matched after Process read it as provisional. go build, go vet and lint-changed are clean. I'm leaving this thread open: whether this race explains #4613's orphans is still for the maintainers to decide.
Reviewed head: dc85466 (the PR's d3fdeff plus one comment-only commit from this review).
The new step is correct and safe. When the rebind keeps its source, it frees the IDs that the target's episodes need, and when the source is deleted it does nothing. What doesn't match the code is the trigger the PR described. Process keeps a matched source only when that source's status turns matched after Process read it as provisional, so the state comes from a race, not a steady path. The 47 orphans in #4613 may have come from that race or from another path; this review couldn't tell which.
Addressed
The step's code comment, the test's comment and the PR body's Problem section now describe the real condition (dc85466, comments and description only).
TestRebindKeptSourceReleasesEpisodeIDsPostgres failed on the base (bc17dc0) for the reported reason: the kept source's episode still held all three IDs. It passes on the head. Both runs used a throwaway Postgres 18.
Not reproduced live. The kept-source state needs two concurrent passes on one item, which a sandbox can't stage on demand.
Considered and not counted against this PR:
A lock-order concern: the step locks the source item and then its episodes, which is the same order the existing cascade delete uses.
An in-flight refresh of the source taking the IDs back: a narrow race, and the base never frees them at all.
Validated features: no passed case on the v1.0 board changes. The Identify and duplicate-series cases (#1210 and #1211, C1 and C2) reach rebindItemOnto, but none of them checks the kept source's episode IDs. Validation tasks: none is correct.
User manual: unaffected; this is internal catalog repair. Other clients: N/A. Clients see the real episode titles after the target's next refresh, and none of them needs a change. Jellyfin-compat needs no change either.
All three members independently flagged the trigger mismatch, and that is now fixed in the comments and body. Sol's low score rested mainly on that mismatch and on the two races above. The follow-up commit changes only comments, so no second round ran.
Fit: 9/10 · Readiness: 7/10 — conditional
Fit: a small correctness fix where the rebind already cleans up after its source, with no new surface.
The reason will be displayed to describe this comment to others. Learn more.
Architecture findings (1)
Advisory architecture findings (1)
Trivial — The rebind commits the release of every set provider ID on the retained source's episodes without reserving those IDs for the target. If processing stops after commit, or the target episode write fails, the release is not rolled back. A later successful refresh can repopulate IDs it receives, but the rebind itself does not ensure that recovery.
Review info
Run configuration
Source mode: Auto
Repository: Unavailable
Branch: Unavailable
File: No configuration file from this repository applied
Commit: Unavailable
Layers: Organization UI
Review profile: CHILL
Plan: Advanced
Run ID: f522b5e2-1fa5-4f88-a7a5-0140d819a784
Commits
Reviewing files that changed from the base of the PR and between bc17dc0 and dc85466.
Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 0 remain after this review.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bugSomething isn't workinggoPull requests that update go codepriority: P2Limited scope, workaround exists, or polishsize/M50–199 added + deleted lines (all files); change volume, not priority.
2 participants
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Depends on: none. Merge order: none.
Problem
Part of #4613 (its path 1, and the first bullet of its Expected behavior). This doesn't close the issue.
Validation tasks: none
Other clients: Apple, Android and Roku get real episode titles for the affected show after its next refresh; no client change is needed. Jellyfin-compat N/A.
When a refresh finds that an item's provider IDs belong to another confirmed item,
rebindItemOnto(internal/metadata/service.go) moves the source's library memberships, file links, provider IDs and user state onto the target. Then it deletes the source only if its status is deletable. From the Process path, a source with durable provider IDs reaches the rebind only while it is provisional, and the delete keeps it only if its status has turnedmatchedsince. A kept source has no library, no files and no provider ID rows. Its episodes keep theirtmdb_id,tvdb_idandimdb_id, which are unique across all episodes (idx_episodes_tmdb_idand the like). So the target's episode upserts fail on those IDs, and the real episodes keep their scanner placeholders (Episode 1…). The issue saw 47 such items, one holding 13 episodes' TMDB IDs for ten days.Approach
rebindItemOnto, after the source delete: it setstmdb_id,tvdb_idandimdb_idto''(the columns' empty default) on the source's episodes that still hold any. A deleted source took its episodes with it (ON DELETE CASCADE), so the step only affects a kept source. The target's next refresh can then store the IDs.Validation
TestRebindKeptSourceReleasesEpisodeIDsPostgressets up two matched series, the source with an episode holding TMDB, TVDB and IMDb IDs. It rebinds the source onto the target the way Process does, with a matched source not deletable. It checks that the source is kept, that its episode's IDs are released, and that the target can then store an episode with the same IDs. Added toscripts/ci/db-contracts.txt.service.go, the kept source still holds the IDs (output under Evidence).go test -count=1 ./internal/metadata/passes against a local Postgres 18.lint-changed: 0 issues../internal/catalog/,TestEpisodeCatalogRefreshSerializesFileChangesPostgresfails here with a deadlock, on this branch and on clean main alike (two runs each). CI runs it in its own environment.Evidence
No screen changes until the target's next refresh, which then shows its episodes' real titles. Results of
go test -count=1 -v -run TestRebindKeptSourceReleasesEpisodeIDsPostgres ./internal/metadata/against a local Postgres 18.Before (
service.gofrom main bc17dc0):After (this branch, d3fdeff):
Risks
Checklist
AI Disclosure
🤖 Generated with Claude Code
Note
Release kept rebind source's episode external IDs in
rebindItemOntoWhen a rebind keeps the source series (
allowMatchedSource=false), its episodes retain TMDB, TVDB, and IMDb IDs. This blocks other episodes from storing those IDs due to uniqueness constraints.MetadataService.rebindItemOntonow clears those provider IDs and bumpsupdated_atfor remaining source episodes in a new transaction step, added in service.go. Also adds a PostgreSQL integration test,TestRebindKeptSourceReleasesEpisodeIDsPostgres, in rebind_kept_source_episode_ids_db_test.go, and registers it in db-contracts.txt.Macroscope summarized 51d45fc.