Skip to content

fix(metadata): match the personal collection key when merging duplicate items - #2360

Merged
Quick104 merged 2 commits into
Silo-Server:mainfrom
Rhainland:fix/merge-personal-collection-conflict
Oct 13, 2026
Merged

Quick104 merged 2 commits into
Silo-Server:mainfrom
Rhainland:fix/merge-personal-collection-conflict

Conversation

@Rhainland

@Rhainland Rhainland commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Closes #2299
Related issue: N/A
Validation tasks: changes #1210 C1; changes #1211 C1

Merging a duplicate media item into its canonical item always failed, so items that share a provider ID were never merged. This breaks the provider-ID integrity repair, and an Identify that picks IDs already owned by another item. This change makes the merge use the personal collection table's current key, so the merge completes, and fixes two steps that would have lost data once merges commit again.

Migration 156 added sub_item_id to the primary key of user_personal_collection_items, which is now (user_id, collection_id, media_item_id, sub_item_id). The "merge personal collection items" step in canonicalizeMediaItemReferencesTx still named the old three-column ON CONFLICT target. Postgres rejects that when it plans the statement (42P10), so every merge rolled back, even when the source item had no collection rows.

Approach

The merge step now carries sub_item_id through the insert, the grouping and the conflict target. When the source and canonical items are in the same collection with the same sub_item_id, they collapse into one entry that keeps the lower position and the earlier added_at, as before. Whole-item entries (sub_item_id = '') and podcast episode entries stay separate.

With the merge running again, two other steps would have lost data:

  • The provider-ID step inserted a copy of each source ID for the canonical item with ON CONFLICT DO NOTHING. The source row itself holds the unique (provider, provider_id, item_type) key, so every copy was skipped and the next step deleted the source IDs. The step now moves the rows for providers the canonical item has no ID for; the canonical item keeps its own ID for the rest.
  • Ebook annotations were never moved, so deleting the source item cascaded and removed its highlights, notes and bookmarks. The merge now moves them.

The new database tests run the full merge step list against a migrated schema. They cover a source with no collection rows (the reported failure), a collection both items are in, a collection only the source is in, episode entries, provider IDs, and ebook annotations. Because the no-rows test runs every merge step, it also checks that the other steps' conflict targets match real keys. The commit also removes the t.Skip that TestIdentifyConflictMergeMarksTheSurvivorPostgres carried until this issue was fixed, so the Identify conflict-merge path is tested again.

Validation

  • Go gate (build, gofmt, vet, make lint-changed, and the contract, fixture, route and docs checks) passes.
  • In make test-go the touched package passes. The failures on the test machine are in internal/apiv2, internal/jellycompat, internal/playback and internal/transcodenode (GPU and FFmpeg probe tests, macOS-specific tests) and internal/metadata/nfo (case-insensitive filesystem), and they fail the same way on main.
  • The new database tests and TestIdentifyConflictMergeMarksTheSurvivorPostgres pass against a fully migrated PostgreSQL 18 database. The new tests fail on main: the collection tests with the 42P10 error, the provider-ID and annotation tests by losing the rows. They run only when SILO_TEST_DATABASE_URL is set.
  • Web gate not run: no web files changed.

Evidence

Evidence: https://evidence.siloserver.org/r/silo-server/pr-2360/

Surface and build: web app Match Item and a personal collection at desktop and phone width, before on main at 8ddbc8d, after at 7df8f12.

Risks

Duplicate merges start committing again on existing servers. They now keep provider IDs and annotations that the old steps dropped, but every other merge step runs in production for the first time since migration 156.

Checklist

  • I read and can explain the complete diff.
  • This pull request addresses one concern.
  • The Evidence section shows every change a user can see, or says there is none.

AI Disclosure

  • Harness: Claude Code
  • Tool(s): Claude Code
  • Model(s): claude-opus-5-5
  • Involvement: Fully AI-generated, human verified
  • Adversarial review: two separate agent reviews of the diff checked the grouping and conflict behavior, the source-row cleanup, podcast episode entries, and the table's other columns, and ran the tests on a migrated database. One finding, the leftover t.Skip for this issue, was fixed.

…te items

Migration 156 added sub_item_id to the primary key of
user_personal_collection_items, but the merge step still named the old
three-column conflict target. Postgres rejected the statement at plan
time, so every duplicate-item merge rolled back, even when the source item
had no collection rows.

Carry sub_item_id through the merge so whole-item entries and episode
entries for the same collection collapse onto the canonical item
separately. Add database tests that run the full merge against a migrated
schema.

Closes Silo-Server#2299
@silo-kody

silo-kody Bot commented Oct 12, 2026 •

Copy link
Copy Markdown

Silo Kody — review complete

Review finished. Check the inline comments for findings and verify each suggestion against the code and tests.

Reviewing changes in Silo
  • Include the related issue, expected behavior, and validation steps in the PR description.
  • For API changes, describe the effect on Apple and Android clients and Jellyfin compatibility.
  • For plugin changes, identify the affected SDK contract, plugin, and catalog entry.
  • Follow this repository's AGENTS.md and CONTRIBUTING.md.
  • Request another review with @kody start-review in a PR comment.
  • React with 👍 or 👎 to give feedback on individual suggestions.
Review settings
Review Options

The following review options are enabled or disabled:

Options Enabled
Bug ✅
Performance ✅
Security ✅
Business Logic ❌

@coderabbitai

coderabbitai Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 4d80cbaa-508f-442d-a31d-bbbe22f0ca74

📥 Commits

Reviewing files that changed from the base of the PR and between d0ea735 and f5f16e9.


📒 Files selected for processing (3)
  • internal/metadata/identify_sticky_db_test.go
  • internal/metadata/provider_id_integrity.go
  • internal/metadata/provider_id_integrity_db_test.go

💤 Files with no reviewable changes (1)
  • internal/metadata/identify_sticky_db_test.go

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.



📝 Walkthrough
📝 Walkthrough
📝 Walkthrough
📝 Walkthrough

Walkthrough

The personal-collection merge now preserves sub-item IDs and handles conflicts using a key that includes the sub-item ID. PostgreSQL integration tests cover canonicalization with and without collection rows. A duplicate-merge identity test now runs instead of being skipped.

Changes

Media item canonicalization

Layer / File(s) Summary
Preserve sub-item keys during merge
internal/metadata/provider_id_integrity.go
The personal-collection merge carries sub_item_id into canonical rows and groups and resolves conflicts using the user, collection, and sub-item IDs.
Verify canonicalization in PostgreSQL
internal/metadata/provider_id_integrity_db_test.go, internal/metadata/identify_sticky_db_test.go
PostgreSQL tests cover canonicalization with and without collection rows, including duplicate resolution, positions, and timestamps. The duplicate-merge identity test is no longer skipped.

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Suggested reviewers: quick104


Merge Risk: ⚪ Minimal · up to f5f16

No merge-blocking issue was established. The collection merge can proceed through normal checks.

Pre-merge checks · Passed 4 · Failed 1

Failed Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks (4 passed)
Check name Status Explanation
Linked Issues check Passed Issue #2299 requires the personal-collection merge to complete on the migrated key and to carry sub_item_id through selection and grouping. The reviewed change updates the insert, grouping, and `ON …
Out of Scope Changes check Passed The changes are limited to the personal-collection merge SQL and tests for canonicalization and Identify conflict merging. The test changes directly verify the issue behavior and the migrated schema. …
Description check Passed The description directly explains the personal-collection merge fix, related data-loss fixes, tests, validation, and risks.
Title check Passed The title clearly and concisely identifies the main change: matching the personal-collection key when merging duplicate metadata items.

  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

@silo-triage silo-triage Bot added bug Something isn't working evidence-required Needs before-and-after evidence before the Evidence check passes go Pull requests that update go code impact: usability Core flow broken or severely blocked priority: P1 Core-path bug; painful workaround — next after P0 triaged High-confidence review completed; does not mean fixed, validated, or accepted for release. labels Oct 12, 2026
@silo-triage

silo-triage Bot commented Oct 12, 2026

Copy link
Copy Markdown

This restores duplicate consolidation and changes which items remain in collections, so Evidence: none, no user-visible change does not fit the collection/metadata evidence policy. Please add before-and-after captures of the same collection and data for an Identify that merges a duplicate, showing the surviving entry, and name the builds. For web captures, include desktop and phone width or explain why mobile is unaffected.

…uplicates

With the merge running again, two of its steps lost data. The provider-ID
step inserted a copy of each source ID for the canonical item with ON
CONFLICT DO NOTHING, but the source row itself holds the unique
(provider, provider_id, item_type) key, so every copy was skipped and the
next step deleted the source IDs. Move the rows for providers the
canonical item has no ID for instead.

Ebook annotations were never moved, so deleting the source item cascaded
and removed its highlights, notes, and bookmarks. Move them to the
canonical item.
@silo-kody

silo-kody Bot commented Oct 12, 2026 •

Copy link
Copy Markdown

Silo Kody — review complete

Review finished. Check the inline comments for findings and verify each suggestion against the code and tests.

Reviewing changes in Silo
  • Include the related issue, expected behavior, and validation steps in the PR description.
  • For API changes, describe the effect on Apple and Android clients and Jellyfin compatibility.
  • For plugin changes, identify the affected SDK contract, plugin, and catalog entry.
  • Follow this repository's AGENTS.md and CONTRIBUTING.md.
  • Request another review with @kody start-review in a PR comment.
  • React with 👍 or 👎 to give feedback on individual suggestions.
Review settings
Review Options

The following review options are enabled or disabled:

Options Enabled
Bug ✅
Performance ✅
Security ✅
Business Logic ❌

@Rhainland

Copy link
Copy Markdown
Contributor Author

Evidence added: before-and-after captures of Match Item merging a duplicate on desktop and phone width, the personal collection showing the surviving entry, and the matching API responses. Builds: main at 8ddbc8d and this branch at 7df8f12. The link is in the Evidence section.

@Quick104
Quick104 merged commit 11a197d into Silo-Server:main Oct 13, 2026
24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working evidence-required Needs before-and-after evidence before the Evidence check passes go Pull requests that update go code impact: usability Core flow broken or severely blocked priority: P1 Core-path bug; painful workaround — next after P0 triaged High-confidence review completed; does not mean fixed, validated, or accepted for release.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug] Merging duplicate items fails at the personal collection step

2 participants