Skip to content

fix(metadata): store and show each production country once - #1996

Merged
Quick104 merged 1 commit into
Silo-Server:mainfrom
Rhainland:fix/dedupe-item-countries
Oct 7, 2026
Merged

Quick104 merged 1 commit into
Silo-Server:mainfrom
Rhainland:fix/dedupe-item-countries

Conversation

@Rhainland

@Rhainland Rhainland commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Related issue: #1249
Validation tasks: changes Silo-Server/silo-apple#337 C2

Series matched by both TMDB and TVDB list their country twice, for example "countries": ["US", "US"] for Breaking Bad, so clients show "US, US".

TMDB reports origin countries as alpha-2 (US) and TVDB as lowercase alpha-3 (usa). The metadata merge keeps both because they differ, and lang.CanonicalCountries then maps both to US without removing the repeat.

Approach

  • CanonicalCountries drops repeats after canonicalizing and keeps the first occurrence, so refreshed items are stored with one entry per country.
  • Rows already saved with repeats are cleaned on read: catalog item details and cards, and the jellycompat ProductionLocations field, pass countries through the new lang.UniqueCountries. It removes exact repeats without rewriting hand-entered values.

No migration; the next metadata refresh rewrites stored rows.

Validation

  • go build, go vet, gofmt, make lint-changed: pass.
  • make test-go: the only failures are the hardware-acceleration, transcode and probe tests that also fail on main on the test machine (macOS, no VAAPI, QSV or NVIDIA devices). A few timing tests that failed once while the machine was loaded passed on three reruns.
  • make verify-settings-bindings-all, the other verify-* targets in CONTRIBUTING, and the router artifact test: pass.
  • Tests cover the canonical dedupe, the read-side helper, a TMDB plus TVDB merge into a stored item, and ProductionLocations on the jellycompat list and detail paths.
  • Manual: on a server built from this branch, Breaking Bad's item detail returns countries: ["US"], and the iPad detail page shows "US" once.

The internal card detail builder also deduplicates countries, but the public CatalogItem projection used by the Watch Together picker has no countries field. There is no separate visible card-country output; the detail and Jellyfin comparisons cover the public fields.

Evidence

The web detail page does not show production countries, so these are API excerpts. The test series "Harbor Lights" was stored with countries = ["US", "US"], as a TMDB plus TVDB merge leaves it. Same requests both times:

GET <server>/api/v2/catalog/items/<Harbor Lights>

Before

{ "title": "Harbor Lights", "type": "series", "countries": ["US", "US"] }

After

{ "title": "Harbor Lights", "type": "series", "countries": ["US"] }

Jellyfin compatibility, GET <server>/Users/<user>/Items/<Harbor Lights> (the /Users/<user>/Items?searchTerm=Harbor&Fields=ProductionLocations list gives the same values)

Before

{ "Name": "Harbor Lights", "ProductionLocations": ["US", "US"] }

After

{ "Name": "Harbor Lights", "ProductionLocations": ["US"] }

Surface and build: /api/v2/catalog/items/{id} and Jellyfin-compat ProductionLocations; before c762177 (main at this PR's base), after 49501a3 (PR head). Test library with synthetic files; the duplicate countries were written directly into the test database.

Risks

None identified. Genres, studios, networks and keywords are not canonicalized after the merge and had no repeats in the test library, so they are unchanged.

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, running in T3 Code; Codex harness in T3 Code (review cleanup)
  • Tool(s): Claude Code subagents, Go toolchain, Docker, GitHub CLI
  • Model(s): claude-opus-5-5; gpt-6.1-sol
  • Involvement: Fully AI-generated, human verified
  • Adversarial review: A separate Claude Code reviewer agent (claude-opus-5-5) read this branch's diff against main at medium effort, checking API compatibility, behaviour, tests and commit hygiene. It checked that the read-side helper keeps nil and order and that the seed import, which also uses CanonicalCountries, is covered. No findings.

Note

De-duplicate production countries across metadata and Jellyfin mappings

  • Adds lang.UniqueCountries helper that removes exact repeated country values while keeping first-occurrence order and original spelling (lang.go)
  • lang.CanonicalCountries now also collapses distinct spellings that canonicalize to the same country code
  • Applies de-duplication when building item details, item cards, and Jellyfin ProductionLocations in both list and detail mappings
  • Risk: lang.CanonicalCountries behavior changed — it now returns only the first canonical occurrence, so existing callers that relied on duplicate canonical codes will see fewer entries

Macroscope summarized 49501a3.

Series matched by both TMDB and TVDB listed their country twice, for example "countries": ["US", "US"] for Breaking Bad, so clients showed "US, US".

TMDB reports origin countries as alpha-2 ("US") and TVDB as lowercase alpha-3 ("usa"). The metadata merge treats those as different values and keeps both, and lang.CanonicalCountries then maps both to "US" without removing the repeat before the item is saved.

CanonicalCountries now drops repeats after canonicalizing, keeping the first occurrence, so refreshed items are stored with one entry per country. Rows already saved with repeats are cleaned when read: catalog item details and cards and the jellycompat ProductionLocations field pass countries through the new lang.UniqueCountries, which removes exact repeats without rewriting hand-entered values. No migration; the next metadata refresh rewrites the stored rows. Genres, studios, networks, and keywords are not canonicalized after the merge and had no repeats in the affected library.

Tests cover the canonical dedupe, the read-side helper, the TMDB plus TVDB merge into a stored item, and ProductionLocations on the jellycompat list and detail paths.
@silo-kody

silo-kody Bot commented Oct 5, 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 5, 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: afa8da66-883d-4df6-b202-ce01a23bba85
📥 Commits

Reviewing files that changed from the base of the PR and between c762177 and 49501a3.

📒 Files selected for processing (7)
  • internal/catalog/detail.go
  • internal/catalog/item_cards.go
  • internal/jellycompat/jellyfin12_fields_test.go
  • internal/jellycompat/mapping.go
  • internal/lang/lang.go
  • internal/lang/lang_test.go
  • internal/metadata/merge_countries_test.go

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


📝 Walkthrough

Walkthrough

Country handling now removes repeated values while preserving first-occurrence order. CanonicalCountries also collapses spellings that resolve to the same country code. Catalog details, cards, and Jellyfin list and detail outputs use exact-value deduplication.

Changes

Country Deduplication

Layer / File(s) Summary
Country normalization and deduplication
internal/lang/lang.go, internal/lang/lang_test.go, internal/metadata/merge_countries_test.go
CanonicalCountries removes repeated canonical codes. The new UniqueCountries function removes exact duplicates and preserves order. Tests cover both functions and metadata country conversion.
Jellyfin production locations
internal/jellycompat/mapping.go, internal/jellycompat/jellyfin12_fields_test.go
List and detail mappings deduplicate production locations. A test checks that repeated country values appear once in both outputs.
Catalog country fields
internal/catalog/detail.go, internal/catalog/item_cards.go
Catalog detail and card country fields now use UniqueCountries.

Priority: ⬇️ Low

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

Change: Bug fix

Suggested reviewers: quick104

Merge Risk: ⚪ Minimal · up to 49501

Repeated country entries are removed while output fields and distinct spellings are preserved. No concrete merge-blocking risk is evident; the change is ready for normal checks.

Security Architecture Review

Security architecture risk: ⚪ Minimal · up to 49501

The change removes duplicate country entries without changing response shapes, access checks, or privileges. The reviewed paths show no material security risk introduced or worsened by this PR.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The inspected exposure is country metadata in item storage and existing catalog, compatibility, filtering, recommendation, and scheduling consumers. No inspected item-country path uses these values to grant permissions or establish tenant identity; external consumers remain outside the available evidence.

Trust Boundaries and Controls

  • observed — The country transformation accepts strings and performs normalization and exact equality checks without I/O or privileged actions. In the inspected card entrypoint, caller-supplied IDs remain subject to the existing access and membership checks.

Resilience and Maintainability Implications

  • observed — The existing primary persistence path commits item and provider-ID writes transactionally. Its legacy fallback writes them separately and can retain an item update after a later failure. That containment limitation predates this PR; the deduplication change adds no new persistence step.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 55.56% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 9 functions across 7 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly and concisely describes the main change: deduplicating production countries in stored metadata and user-visible mappings.
Description check ✅ Passed The description directly explains the duplicate-country problem, the implementation, affected outputs, tests, validation results, and user-visible evidence.
  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autopilot · 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.

Quick104 commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

Silo's pull request guidance changed today (#2016). A PR that changes what a user sees now needs before-and-after evidence in its Evidence section, and a PR with no visible change says Evidence: none, no user-visible change. This PR was opened before the rule existed, so it hasn't had a chance to meet it yet.

Missing here: Before-and-after screenshots of a detail page showing the production countries line, or before-and-after excerpts of the countries field in the API response.

The rules are in Show visible changes, and the PR template shows the Evidence section layout. I've converted this PR to draft for now. Mark it ready for review once the Evidence section is filled in.


Generated by Claude Code

@Quick104
Quick104 marked this pull request as draft October 6, 2026 19:25
@Rhainland
Rhainland marked this pull request as ready for review October 6, 2026 20:06
@macroscopeapp

macroscopeapp Bot commented Oct 6, 2026

Copy link
Copy Markdown

The catalog item-card response also removes duplicate countries values (internal/catalog/item_cards.go), but the Evidence section shows only item-detail and Jellyfin responses. Please add before-and-after item-card API excerpts for the same item.

Automated check: Macroscope check run agent (gpt-6-luna). Evidence was not reviewed for correctness.

Posted via Macroscope — Visible change evidence

@Rhainland

Copy link
Copy Markdown
Contributor Author

Checked the item-card request against the wire projection. GetItemCardsByIDs builds internal ItemDetail values for the Watch Together picker, but catalogItemCardOf emits CatalogItem, which has no countries field. The change to item_cards.go therefore adds no separate visible country field to capture. The existing item-detail and Jellyfin excerpts cover the public country fields that change.

@Quick104

Quick104 commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

Review summary

Reviewed head: 49501a3

Fit: 9/10 · Readiness: 9/10 — ready

No defects found. The fix stores each country once after canonicalizing and cleans rows that were already saved with repeats when they're read, so nothing needs a migration.

What I checked

  • Callers. CanonicalCountries has two production callers, metadata conversion and seed import. Neither relies on the position or count of countries to line up other fields. Order (first occurrence wins), nil, and empty arrays behave as before.
  • Read paths. The only responses that list an item's countries are catalog item detail and Jellyfin ProductionLocations (list and detail). The PR covers both. Native list, browse, search and card responses have no item-level countries field. The v1 and v2 country filter lists already come from DISTINCT queries.
  • Locks and edits. Locked country fields are still skipped by both merge modes. The web metadata editor sends countries only when that field changes, so editing another field doesn't save the cleaned list.
  • Contracts and clients. No field, type, or meaning changes on /api/v2, /api/v1, or Jellyfin. Apple and Android show countries as a plain list of strings, and neither depends on repeats. No client change is needed.
  • Tests. go test on internal/lang, internal/jellycompat, internal/catalogseed, and the metadata merge tests passes at this head. CI is green.

Known limits, none of which block merge: exact-match read cleanup won't merge spellings like ["US", "USA"] in rows saved before canonicalization existed; admin metadata edits still store the submitted array as entered; and search documents and recommendation text keep stored repeats until the next refresh. None of these show duplicates to users.

Validated features

The Validation tasks: line says this changes Silo-Server/silo-apple#337 C2, but C2 is recorded as Not run on both iPhone and iPad, so no passed case is affected. That line should read Validation tasks: none, with a separate note that #337 C2 (series detail metadata) is not yet run and will see one country per entry. I couldn't read the project board, so this comes from the task's own Results table.

Other checks

  • User manual: unaffected. The manual doesn't describe production countries.
  • Jellyfin parity: covered by the ProductionLocations change.
  • Earlier feedback: I agree with the author's reply to the item-card evidence comment. catalogItemCardOf emits CatalogItem, which has no countries field, so cards have no visible change to capture.

Scores

  • Fit 9: this fixes a visible metadata error in the core series detail page. It changes the shared normalization helper, which is where the duplication comes from, rather than adding special cases. It adds no settings or API surface.
  • Readiness 9: no open concerns, CI green, and before/after API evidence for both affected responses. The only change I'd make is the Validation tasks: line.

Review method: a single-pass review of the full diff and its callers, plus one independent adversarial round from a second model. Neither found any defects.

AI-generated review (Claude Code, claude-opus-5-5; second round gpt-6.1-sol via Codex), posted by Quick104.

@Quick104
Quick104 merged commit 8c47194 into Silo-Server:main Oct 7, 2026
16 checks passed
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.

2 participants