Skip to content

fix(catalog): match TMDB ids stored in TMDB's own id-slug form - #484

Merged
Quick104 merged 2 commits into
Silo-Server:mainfrom
RXWatcher:fix/tmdb-id-slug-match
Jul 29, 2026
Merged

Quick104 merged 2 commits into
Silo-Server:mainfrom
RXWatcher:fix/tmdb-id-slug-match

Conversation

@RXWatcher

@RXWatcher RXWatcher commented Jul 26, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Attaching a TMDB id compared the stored value byte-for-byte, so a media_items row holding TMDB's id-slug form conflicted with the bare numeric id being attached, and the presence-lookup backfill failed:

WARN requests: failed to backfill tmdb id from presence lookup
  content_id=series-tvdb-76081 media_type=series tmdb_id=1931 matched_provider=tvdb
  error="media item tmdb id conflict:
         got \"1931-disney-s-adventures-of-the-gummi-bears\", want \"1931\""

That form is not corrupt data — it is how TMDB writes its own URLs (/tv/1931-disney-s-adventures-of-the-gummi-bears) — and enough of it has reached the catalog to matter. Two different series hit it within a minute on my server.

The user-visible cost: a title already in the library never gets linked, so clients keep offering to request something you already own.

Change

The numeric prefix is the identity, so compare on that. Values with no leading digits (tt0111161), or digits not followed by a separator (12ab), are not TMDB ids and still conflict exactly as before — the fix widens what counts as a match, it does not weaken the conflict check.

Applied to both comparisons in AttachTMDBID: the media_items.tmdb_id check and the media_item_provider_ids one.

Testing

Table test using the real values from the log above, plus the negative cases (different ids must still conflict; non-TMDB identifiers untouched). go test ./internal/catalog/ green.

AI-use disclosure

Written by Claude Opus 5 (Claude Code) working with @RXWatcher, who spotted the warning on his server and directed the fix.

Summary by CodeRabbit

  • Bug Fixes
    • Improved TMDB identifier matching to treat numeric IDs and their slugged (and whitespace-padded) forms as equivalent.
    • Reduced incorrect “already belongs” conflict errors when only the slug portion differs, while still rejecting truly different or invalid identifiers.
    • Kept existing TMDB ownership behavior consistent when equivalent identities are already present.
  • Tests
    • Added unit and integration coverage for TMDB ID normalization, equivalence rules, and conflict handling.

Maintainer remediation AI disclosure

  • Tool(s): T3 Code through the Codex harness
  • Model(s): gpt-5.6-sol
  • Involvement: fully AI-generated maintainer remediation, explicitly authorized by the maintainer
  • Adversarial review: The two-axis review found that equivalent slug-form TMDB ownership was checked only on the target row, allowing the bare ID to be attached to a second content row. The remediation added an index-bounded cross-record owner check and a DB-backed regression. A follow-up Standards pass found the all-nines fallback had dropped its index lower bound; that was corrected and live EXPLAIN verification confirmed the index scan. Final code Standards review found no code issue. The contributor-originated whitespace semantics remain report-only because the PR text and test conflict and a consistent indexed resolution may require a data/index decision.

Maintainer remediation verification

go test ./internal/catalog/ -count=1
ok  github.com/Silo-Server/silo-server/internal/catalog

go test -race ./internal/catalog/ -count=1
ok  github.com/Silo-Server/silo-server/internal/catalog

go test ./internal/requests/ -count=1
ok  github.com/Silo-Server/silo-server/internal/requests

go vet ./internal/catalog/ ./internal/requests/
PASS

GOWORK=off golangci-lint run --allow-parallel-runners --new-from-rev 02203d9e408c8f53ecbf8adf672d84d434180389 ./internal/catalog/...
0 issues.

make build
PASS (existing Vite font-resolution and chunk-size warnings only)

make verify-local-paths
PASS

cd web && pnpm run format:check
All matched files use Prettier code style!

Deployed to the configured dev backend under the shared backend lock.
/api/v1/ready -> {"status":"ok"}
DB-backed TestAttachTMDBIDRejectsEquivalentSlugOwner -> PASS
All-nines fallback EXPLAIN -> idx_media_items_tmdb_id, 0.186 ms, 9 shared buffers
GET /api/v1/requests/detail/series/1931 -> HTTP 200; temporary TVDB-matched target selected
Target tmdb_id remained empty; target TMDB provider rows remained 0; existing slug owner remained unchanged
Expected backfill-conflict warning persisted; temporary rows cleaned to 0
Fresh panic/fatal/migration-failure/error-loop log scan -> clean
Final /api/v1/ready -> {"status":"ok"}

Attaching a TMDB id compared the stored value byte-for-byte, so a
media_items row holding "1931-disney-s-adventures-of-the-gummi-bears"
conflicted with the bare "1931" being attached and the presence-lookup
backfill failed:

  WARN requests: failed to backfill tmdb id from presence lookup
    error="media item tmdb id conflict:
           got \"1931-disney-s-adventures-of-the-gummi-bears\", want \"1931\""

That form is not corrupt data — it is how TMDB writes its own URLs
(/tv/1931-disney-s-adventures-of-the-gummi-bears) — and enough of it has
reached the catalog to matter. The visible cost is that a title already
in the library never gets linked, so clients keep offering to request
something you own.

The numeric prefix is the identity, so compare on that. Values with no
leading digits, or digits not followed by a separator, are not TMDB ids
and still conflict as before.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01Db4dSxN9tH8yN7uUP549tK
@coderabbitai

coderabbitai Bot commented Jul 26, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

TMDB identifier handling now treats numeric slug forms and bare numeric IDs as equivalent during attachment conflict checks and ownership lookups. Tests cover normalization, invalid values, slug-form conflicts, and preservation of the target row after rejection.

Changes

TMDB identifier normalization

Layer / File(s) Summary
Normalize TMDB identifiers
internal/catalog/provider_id_repo.go, internal/catalog/provider_id_tmdb_match_test.go
Adds helpers and unit tests for trimming, slug-form matching, mismatched IDs, and non-numeric inputs.
Apply normalized conflict checks
internal/catalog/provider_id_repo.go
Uses normalized comparisons for existing media-item and TMDB provider identifiers in AttachTMDBID.
Detect slug-form owners
internal/catalog/provider_id_repo.go, internal/catalog/provider_id_tmdb_match_test.go
Adds index-friendly prefix bounds and slug-aware ownership matching, with an integration test for equivalent existing owners.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Suggested labels: v1

Suggested reviewers: quick104

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: comparing TMDB IDs by numeric prefix to handle TMDB id-slug forms.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

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

Inline comments:
In `@internal/catalog/provider_id_repo.go`:
- Line 102: Update AttachTMDBID’s cross-record ownership query to use the same
trimmed digits-then-suffix TMDB matching as sameTMDBID, rather than exact SQL
equality, so numeric and slug forms identify the existing owner. Preserve
current-row validation and add an AttachTMDBID regression test proving a numeric
ID cannot be attached when another content record owns the equivalent slug.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 1a2c3d95-0b5e-4acb-b20e-7057808a4d76

📥 Commits

Reviewing files that changed from the base of the PR and between 02203d9 and 396b523.

📒 Files selected for processing (2)
  • internal/catalog/provider_id_repo.go
  • internal/catalog/provider_id_tmdb_match_test.go

Comment thread internal/catalog/provider_id_repo.go Resolved
@Quick104
Quick104 merged commit 824d7bd into Silo-Server:main Jul 29, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

v1.0 Silo v1 scope - auto-adds to the Silo v1 project

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants