Repository navigation
fix(metadata): prevent stale cross-provider IDs - #480
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThis PR adds actionable stale provider-ID detection, owning-provider conflict resolution, and propagation of recorded stale IDs and replacements through metadata refresh, persistence, API filtering, quick refresh, and refresh-debt evaluation. ChangesProvider ID refresh handling
Estimated code review effort: 4 (Complex) | ~60 minutes Sequence Diagram(s)sequenceDiagram
participant MetadataService
participant StaleMediaIDRepository
participant ProviderSearch
participant MetadataPersistence
MetadataService->>StaleMediaIDRepository: load recorded stale provider IDs
MetadataService->>ProviderSearch: refresh with stale IDs suppressed
ProviderSearch->>MetadataService: return confirmed IDs or 404 results
MetadataService->>MetadataPersistence: apply replacements and persist
Possibly related PRs
Suggested labels: Suggested reviewers: 🚥 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.
Actionable comments posted: 1
🧹 Nitpick comments (1)
internal/metadata/types.go (1)
263-265: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winDocument the three provider-ID bookkeeping maps.
quarantinedProviderIDKeys,replacedProviderIDKeys, andrecordedStaleProviderIDsnow drive reanchoring, merge deletion, and suppression with distinct semantics; a one-line comment each prevents future misuse.🤖 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/metadata/types.go` around lines 263 - 265, Document the three bookkeeping fields near quarantinedProviderIDKeys, replacedProviderIDKeys, and recordedStaleProviderIDs with one-line comments describing their distinct roles in reanchoring, merge deletion, and suppression, respectively.
🤖 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/metadata/service.go`:
- Line 1594: Update hasProviderIDRefreshDebt to retain provider_id_incomplete
only when an item has no provider IDs at all or has confirmed provider-ID data
indicating a missing refresh target. Treat items containing only TVDB/IMDB, and
TMDB-only detail responses with no TVDB, as missing-only cross-provider siblings
after dropUnconfirmedCrossProviderIDs, so they do not create permanent debt.
---
Nitpick comments:
In `@internal/metadata/types.go`:
- Around line 263-265: Document the three bookkeeping fields near
quarantinedProviderIDKeys, replacedProviderIDKeys, and recordedStaleProviderIDs
with one-line comments describing their distinct roles in reanchoring, merge
deletion, and suppression, respectively.
🪄 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: 514de3b1-09b8-4e2e-a1c1-e312a257cd55
📒 Files selected for processing (13)
internal/api/handlers/libraries.gointernal/contentid/contentid.gointernal/contentid/contentid_test.gointernal/metadata/id_consensus_test.gointernal/metadata/match_candidates.gointernal/metadata/match_candidates_test.gointernal/metadata/provider_id_persistence_test.gointernal/metadata/service.gointernal/metadata/service_test.gointernal/metadata/stale_media_id_repo.gointernal/metadata/stale_media_id_repo_test.gointernal/metadata/target_refresh_test.gointernal/metadata/types.go
ReviewThe problem this targets is real and the general shape — provenance on provider IDs, don't let a dead ID get restored by durable merge — is the right direction. But as written the diff regresses several behaviours well outside the stale-ID case, and a couple of them are load-bearing for identity. I don't think this is mergeable as-is. Reviewed at Blocking1. Native confirmation is keyed off the provider's capability id, so only providers literally slugged Probe result: initial match of a movie through a single provider with capability id The provenance signal you want is "did the provider that owns this namespace return it", which isn't the same as "is the provider's capability id equal to the namespace". A 2. Content-ID re-anchoring is no longer gated on manual refresh — background jobs can now rename a client-visible Probe: item 3. Same change breaks the documented contract of 4. Search-phase cross-references and detail-phase cross-references aren't the same trust problem — the detail response came from a provider you already resolved an identity with. 5. A single provider 404 now permanently deletes the canonical provider ID, including a 404 from the image phase. Should fix6. 7. 8. The predicate isn't applied to the SQL that actually drives the repeated work. 9. Case-sensitivity split in Minor
Happy to take another pass once 1/2/4/5 have a direction. My suggestion on #2 and #3 specifically: keep re-anchoring gated on an explicit user action and treat "anchor is stale" as a reason to surface the item, not to rename it behind the user's back. Review performed with Claude Code (claude-opus-5); findings 1 and 2 confirmed by running probe tests against this branch and |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
internal/metadata/stale_media_id_repo.go (1)
109-120: 🚀 Performance & Scalability | 🔵 TrivialUnbounded retention of rejected provider-ID values.
Each distinct rejected
(provider, provider_id)pair is now persisted forever with no cap or expiry. For items that get repeatedly (mis)matched over time (e.g. successive manual identify attempts with different candidate IDs),stale_media_idsrows per(content_id, provider)can grow without bound, inflating table size and the correlated subqueries inListLibraryItems/refresh-debt sync that scan bycontent_id.Consider capping retained values per
(content_id, provider)(e.g. keep only the N most-recently-seen) or adding a periodic cleanup job for very old, no-longer-anchored rejections.🤖 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/metadata/stale_media_id_repo.go` around lines 109 - 120, Update StaleMediaIDRepository.Upsert to prevent unbounded stale_media_ids growth per (contentID, provider), retaining only a bounded number of the most recently seen provider IDs or applying the established expiry/cleanup mechanism. Ensure the cleanup preserves the newly upserted rejection and does not remove current anchored entries.
🤖 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 `@migrations/sql/20260726090943_allow_multiple_stale_provider_ids.sql`:
- Around line 1-22: Update the migration’s Up and Down paths to use concurrent
unique-index creation followed by attaching each index with ALTER TABLE ... ADD
CONSTRAINT ... PRIMARY KEY USING INDEX, preserving the existing key columns and
rollback deduplication. Add the Goose NO TRANSACTION directive so CREATE UNIQUE
INDEX CONCURRENTLY executes outside a transaction, and ensure obsolete
primary-key constraints are dropped appropriately before attaching the
replacement indexes.
---
Nitpick comments:
In `@internal/metadata/stale_media_id_repo.go`:
- Around line 109-120: Update StaleMediaIDRepository.Upsert to prevent unbounded
stale_media_ids growth per (contentID, provider), retaining only a bounded
number of the most recently seen provider IDs or applying the established
expiry/cleanup mechanism. Ensure the cleanup preserves the newly upserted
rejection and does not remove current anchored entries.
🪄 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: 8a965843-4a79-45ee-9095-118e95559507
📒 Files selected for processing (15)
internal/adminjob/library_refresh.gointernal/adminjob/library_refresh_language_test.gointernal/api/handlers/libraries.gointernal/metadata/identify_stale_id_test.gointernal/metadata/match_candidates.gointernal/metadata/match_candidates_test.gointernal/metadata/provider_404_test.gointernal/metadata/provider_id_integrity.gointernal/metadata/provider_id_persistence_test.gointernal/metadata/service.gointernal/metadata/service_test.gointernal/metadata/stale_media_id_repo.gointernal/metadata/stale_media_id_repo_test.gointernal/metadata/types.gomigrations/sql/20260726090943_allow_multiple_stale_provider_ids.sql
🚧 Files skipped from review as they are similar to previous changes (4)
- internal/api/handlers/libraries.go
- internal/metadata/types.go
- internal/metadata/stale_media_id_repo_test.go
- internal/metadata/service.go
ALTER TABLE ... ADD PRIMARY KEY builds the index under ACCESS EXCLUSIVE, blocking reads and writes on stale_media_ids for the whole build. Create the wider unique index with CREATE UNIQUE INDEX CONCURRENTLY and attach it with ADD CONSTRAINT ... PRIMARY KEY USING INDEX instead; all three key columns are already NOT NULL, so the attach is metadata-only. Same treatment on the rollback path, plus the repo's INVALID-remnant cleanup so a failed concurrent build is not silently accepted by IF NOT EXISTS. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Re-review at
|
…er#480) Bring in Silo metadata stale-ID prevention (contentid + multi-row stale provider IDs). Resolve import conflicts to prairie-server module paths. Co-authored-by: Jonah May <[email protected]>
Summary
Root cause
Provider results could contribute cross-provider IDs without provenance. A TVDB response could therefore supply a numeric TMDB cross-reference that was accepted as canonical even though TMDB had never confirmed it. When that value later returned 404, durable merge paths could restore it, and the stale-ID list treated the secondary cross-reference failure as if the matched item itself were stale.
Refresh candidate selection also compared replacement candidates against the raw stored item in one season/episode path, allowing the stale ID being repaired to veto its own replacement.
Impact
Matched items keep only provider identities confirmed by the provider that owns the namespace. Stale secondary cross-references no longer make otherwise healthy items appear stale, and scheduled refresh can safely repair a stale provider anchor without weakening ordinary identity protections.
Part of #268 (follow-up stale-ID hardening).
Validation
go test ./internal/metadata ./internal/contentid ./internal/api/handlers— passgo run github.com/golangci/golangci-lint/v2/cmd/golangci-lint@latest run --new-from-rev=origin/main—0 issuescd web && pnpm run lint— pass with 158 existing warnings and 0 errorscd web && pnpm run format:check— passmake verify-local-paths— passgit diff --check— passmake lintremains red on the repository baseline with 305 findings across unrelated packages. The changed-code lint above is clean.Adversarial review
The final review found four material issues: image-phase 404s were not reaching persistence guards, provider-native replacement did not always re-anchor provider-derived content IDs, target series refresh used the raw stale identity during candidate selection, and a candidate-finalization loop ended with a dead
continue. All four were corrected and covered by regression tests. No material findings remain in the final diff review.AI Disclosure
Summary by CodeRabbit