Skip to content

fix(catalog): hold curator-chosen provider IDs to the curator's libraries - #3932

Merged
Quick104 merged 11 commits into
Silo-Server:mainfrom
blurbery:fix/curation-scope-refresh-jobs
Nov 14, 2026
Merged

Quick104 merged 11 commits into
Silo-Server:mainfrom
blurbery:fix/curation-scope-refresh-jobs

Conversation

@blurbery

@blurbery blurbery commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Closes #2801
Related issue: N/A
Validation tasks: none (#1210 C1 and C2 are run as an administrator, and administrator edits, identifies and refreshes behave as before)

A metadata curator limited to some libraries could still merge an item onto a title in a library they can't curate. #2777 checks the destination when a curator runs match, split or merge, but that check only lives on the request. A curator could write another library's TMDB, IMDb or TVDB ID onto an in-scope item with PATCH /admin/items/{id}/metadata, and work that runs later without the check would act on it:

  • the item refresh job the curator queues (POST /admin/items/{id}/refresh-metadata) runs on the job runner's context, so its re-anchor merges the item onto whichever item sits at the anchor the new ID derives;
  • a refresh refused for curation scope (for example the source or merge-target refresh after a split or merge) was recorded as refresh debt, and the debt retry runs as automatic work with no curator scope;
  • a plain scheduled refresh of a local- item, or of an item with no durable provider IDs, merges it onto the item holding the stored ID without any refresh request.

The merge moves the item's files, library memberships and user state onto the other library's title. This change holds all of these to the curator's libraries. Administrator and automatic work are unchanged, and so is curation inside the curator's scope.

Approach

The check moves to where the curator makes the choice, because the stored IDs outlive the request:

  • When a curator's metadata edit changes tmdb_id, imdb_id or tvdb_id, the same transaction locks and authorises every other item that sits at the anchor the resulting IDs derive or already holds a newly chosen ID (in the item columns or media_item_provider_ids), using the request's curation authoriser. An out-of-scope item refuses the edit with the existing 403 ("Item is outside your assigned libraries" on v1, permission_denied on v2). IDs an edit form resends unchanged aren't re-checked. A split that creates a new target from chosen provider IDs gets the same check.
  • Both curation gates (the legacy one and the policy one) now also record the curator's assigned libraries on the request as a plain value. CreateItemMetadataRefresh, shared by v1 and v2, copies it into the item refresh job's payload as curation_scope, and the executor runs the job's metadata refresh under an authoriser built from it. That survives the job being claimed on another node. Acting administrators record no scope, so their jobs run as before.
  • A refresh that fails with the curation-scope refusal records no refresh failure and no refresh debt, the same as a cancelled refresh.

The queued job checks a snapshot of the curator's libraries taken when the job was queued, not a fresh policy decision: the job can't rebuild the request's device, client IP and time inputs. I didn't add a column or migration, since the job payload is already JSON and refresh debt now never carries curator work.

jellycompat has no item metadata write or refresh route, and library refresh is acting-admin only, so neither needs a matching change. No client change is needed: the 403 already exists for match and split.

Validation

  • New Postgres tests (added to scripts/ci/db-contracts.txt): curator provider-ID edits are refused when they name a title in another library (by anchor and by a durable IMDb row) and allowed inside the curator's libraries, from an acting administrator and from automatic writes; a curator-scoped re-anchor is refused onto another library's title without moving anything, and still merges or renames inside the curator's libraries. Both pass locally against a migrated database. The edit test fails with the check removed.
  • New unit tests: a curator refresh job's scope survives the JSON payload and refuses an out-of-scope merge (admin and unrestricted jobs don't); a curation-scope refusal records no refresh failure.
  • Focused runs of the touched packages' existing tests (internal/api/middleware, internal/api/handlers curation, split, merge and metadata tests, internal/adminjob item refresh, internal/metadata identify tests) pass. make lint-changed, the full Go suite and the db-contracts job were not run locally; they run in CI on this PR. These ran on 39711821a; the head commit only renames constants and was built and vetted.
  • Maintainer review (399fd8131, 2ff2684f2, 0fa214e52): main merged in, with the curator's scope also covering Reset to Provider (a reset-mode row in the job test). The check now derives the anchor from the IDs a refresh keeps, and it locks the edited item before comparing its IDs. The new TestCuratedProviderIDEditsStayInCurationScopeDB row (TMDB set to "0" over a library B IMDb anchor) fails on 399fd8131 and passes on 2ff2684f2. Kept IDs are trimmed before the anchor is derived, and a row with a padded kept TMDB ID fails on 2ff2684f2 and passes on 0fa214e52. With a plain authorizer in place of the new scope type, the edit test's out-of-scope rows and TestCurationScopeRefusalLeavesNoRefreshDebt fail on main.

Evidence

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

Surface: v1 admin catalog API, a curator limited to "Movies A", with test titles Alpha (Movies A) and Beta (Movies B, TMDB 900000101). Base build 30a6abd19, fix build 39711821a (b5850341f for the NFO run), each against its own freshly migrated database with the same data.

Request (curator) Before (30a6abd19) After (39711821a)
PATCH Alpha {"tmdb_id": "900000101"} (Beta's ID) 200, Alpha stores 900000101 403 "Item is outside your assigned libraries", nothing stored
PATCH Gamma (Movies A) to an unused TMDB ID 200, stored 200, stored
POST Alpha refresh-metadata, then the job as admin 202, request_payload has no curation_scope 202, request_payload has "curation_scope": {"library_ids": [1]}

No network metadata provider was enabled for these runs, so on the base build the refresh job failed with "no metadata found from any provider" and the merge onto Beta didn't happen. The merge itself is covered by the re-anchor database test above rather than a live capture. The evidence page also has a separate run with only the built-in NFO provider, showing the rescan behaviour described under Risks, the same on both builds.

Risks

  • Security fix to a permission boundary. A curator whose edit names a title in a library they can't curate now gets 403 where it used to succeed.
  • Where this draws the line, for a maintainer to confirm: IDs a provider adds during a later automatic refresh (TMDB X returns an IMDb ID a library B title holds) still converge as automatic work, the same as after match/apply. Identity overrides a split persists for later scans are a separate path and not covered here.
  • The split check locks the items holding the chosen IDs after the source and target, not in one content-id-ordered pass. A deadlock between two concurrent curations of the same titles would roll one back.
  • A curator refresh job whose metadata refresh would merge out of scope now fails with the scope error instead of merging.
  • The scope covers the job's metadata refresh, not the folder rescan the job runs first. That rescan is the same automatic scan a library scan runs, and it acts on file identity a curator can't write: an NFO <uniqueid> naming a title in another library still merges the two during the rescan, on this branch as on main (step 5 of the evidence).

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 says there is none.

AI Disclosure

  • Harness: Claude Code (desktop app)
  • Tool(s): Claude Code, GitHub CLI
  • Model(s): claude-opus-5-5
  • Involvement: AI-assisted with Claude Opus. I directed the task and designed the work.
  • Adversarial review: a second-model review of the design and diff during the work, which raised the refresh-debt guard and the scheduled-refresh path; both are handled above. No independent human review yet.

Note

Hold curator-chosen provider IDs to the curator's library scope

  • Adds MetadataCurationScope in metadata_curation.go, carrying the delegated curator's effective library IDs on the request context, installed by both permission middlewares
  • Curated provider-ID edits and split targets now check chosen IDs and the resulting identity against existing same-type items via catalog.LockMetadataCurationIdentity and lockCuratedProviderIDs in metadata_curation.go; unchanged (case-insensitive) IDs and automatic writes are excluded
  • Item refresh jobs serialize the curator's scope as curation_scope in the payload (item_refresh.go), and the refresh executor applies it as an authorizer so queued refresh work stays in scope
  • Curation-scope refusals no longer create refresh debt: refreshFailureLeavesNoDebt in service.go treats them like cancellation errors, and AdminHandler.UpdateItemMetadata maps them to a forbidden response
  • Behavioral Change: requests without a curation authorizer skip the new identity checks; scoped jobs that target out-of-scope or unlibraryed destinations are now refused

Macroscope summarized 0fa214e.

…ries

A delegated metadata curator could still merge an item onto a title in a
library outside their scope. They edit the item's tmdb_id, imdb_id or
tvdb_id, then work that runs later without the curation check acts on
the stored IDs: the item refresh job, a refresh-debt retry, or a
scheduled refresh of a local item. Each merges the item onto the item
already at the anchor the IDs derive or holding one of them.

- A curator's provider-ID edit, and a split target's chosen IDs, now
  lock and authorise every other item at the derived anchor or holding
  a newly chosen ID, as match/apply does for its destination. A refusal
  returns 403.
- The curator gates record the curator's library scope on the request.
  An item refresh job copies it into its payload and runs the metadata
  refresh under it, so the job's merges are held to the same libraries
  on whichever node runs it.
- A refresh refused for curation scope records no refresh failure or
  debt, since the debt retry runs as automatic work with no scope.

Admin and automatic work are unchanged.

Closes Silo-Server#2801
@coderabbitai

coderabbitai Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

Warning

Review limit reached

This organization requires a seat for paid usage-based reviews, including automatic and on-demand reviews. Ask an admin to assign a seat or enable paid usage-based reviews for users without a seat in Billing.

Next included review available in 24 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 4 included reviews currently available.

Learn how review limits work.

Review configuration:

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: cf8ec0c1-e827-43bc-9c2e-584bb0f4531e
Commits

Reviewing files that changed from the base of the PR and between 2ff2684 and 0fa214e.

Files selected for processing: 2

  • internal/catalog/metadata_curation.go
  • internal/catalog/metadata_curation_db_test.go
Walkthrough

The change carries delegated curator library scope through metadata updates and queued refresh jobs. It checks provider-identity changes and refresh re-anchoring against that scope. Scope refusals do not create refresh failure debt.

Changes: Delegated metadata curation

Layer / File(s) Summary
Define and attach curator scope
internal/access/metadata_curation.go, internal/api/middleware/permissions.go, internal/api/middleware/policy_gates.go
A MetadataCurationScope stores curator library IDs in request context and provides an authorizer for requested library sets. Middleware attaches a clone of the curator’s effective library IDs.
Check provider-identity changes
internal/catalog/metadata_curation.go, internal/catalog/item_repo.go, internal/api/handlers/admin_split.go, internal/api/handlers/admin_item_metadata_service.go, internal/catalog/metadata_curation_db_test.go
Metadata updates and newly created split targets lock matching identity owners and authorize their libraries. The metadata handler maps scope refusals to a forbidden response. Database tests cover provider-ID edits by curators, admins, and automatic writes.
Carry scope into queued refreshes
internal/adminjob/item_refresh.go, internal/adminjob/item_refresh_test.go, internal/api/handlers/admin_item_metadata_service.go
Refresh requests store an available scope, and the executor applies its authorizer when running the job. Tests cover request serialization and scoped merge authorization.
Handle refresh refusals
internal/metadata/service.go, internal/metadata/identify_sticky_db_test.go, internal/metadata/refresh_debt_test.go, docs/admin-catalog-api.md, scripts/ci/db-contracts.txt
Refresh re-anchoring tests check destination scope. Cancellation, deadline, and curation-scope errors do not create refresh failure debt. Documentation and database-contract entries describe the restrictions.

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

Change: Bug fix · Severity of issue fixed: Medium

Sequence Diagram(s)

sequenceDiagram
  participant Curator
  participant MetadataAPI
  participant RefreshJob
  participant MetadataService
  participant ScopeAuthorizer
  Curator->>MetadataAPI: Request metadata refresh
  MetadataAPI->>RefreshJob: Store curation scope in job payload
  RefreshJob->>MetadataService: Execute refresh with scoped context
  MetadataService->>ScopeAuthorizer: Authorize destination library
  ScopeAuthorizer-->>MetadataService: Return authorization result
Loading

Suggested labels: bug, go, impact: security, needs-review

Suggested reviewers: quick104

Merge Risk: Moderate · previous review 2ff26

Delegated curators are now blocked from choosing provider IDs that belong to items outside their libraries. Two curators who claim the same unused ID at the same moment can still both succeed, which could later lead to a cross-library merge. Closing this needs a per-identity lock before the owner lookup. The window is narrow, so it is a merge consideration rather than a blocker.

Security architecture risk: Moderate · up to 2ff26

The change strengthens library isolation for deferred metadata work. Residual identity-ownership gaps can still affect catalog associations and user state across libraries, but the inspected gaps predate this change; no newly reachable or broader attack path was established.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The relevant exposure is the shared catalog within the affected deployment: provider identities can cause consolidation across library boundaries, affecting catalog file associations, memberships, and associated user state rather than only the initiating curator's records. Exploitation requires curation authority over a source item; the inspected public split route additionally requires acting-administrator authority.

Security Findings and Attack Paths

  • inferred — The two retained concurrency findings describe a residual ownership race. Separate transactions choosing the same previously unowned provider ID can both pass the empty-owner branch and commit their item-column edits; later automatic identity convergence can cross their library scopes. Existing-owner locks and the late-owner recheck narrow exposure but do not reserve an absent identity. The unique provider-table constraint is not exercised by the inspected metadata-column write. This path predates the PR, whose base performed no identity-owner check, so it is not an introduced or worsened architecture concern.
  • observed — The retained split condition remains at the service boundary: caller-supplied provider IDs survive selection of an existing target and can be persisted as scan overrides, while the added identity guard runs only for a newly created target. The same existing-target persistence behavior is present at the merge base. The inspected public route requires acting-administrator access, so this inspection does not establish a newly exposed delegated-curator attack through that route.

Trust Boundaries and Controls

  • observed — Queued authority is server-derived rather than supplied as refresh-request scope. Job creation copies the authorized request's library snapshot into its payload, and execution reconstructs the authorizer for both refresh and reset. Earlier complete-refresh preparation and subtree ingestion still use the original context, so the new authorization boundary covers the metadata-refresh stage, not the entire job.

Hardening Proposals

  • proposed — For stronger identity isolation, serialize claims on a normalized provider-identity key shared by all relevant writers, or reserve ownership transactionally before committing curator-selected IDs. Preserve refusal semantics when concurrent claims belong to disjoint library scopes.
  • proposed — Before relying on queued-refresh scope enforcement operationally, account for legacy payloads without scope and ensure every worker eligible to claim new scoped jobs understands the field. Draining or revalidating legacy work would make the protection's activation explicit.
Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: curator-chosen provider IDs are now checked against the curator's libraries. It matches the changeset, which adds curator scope checks for provider-ID edits, splits, a…
Linked Issues check Passed Issue #2801 has one direct linked target. Its requirement is that curator-chosen provider IDs must not reach cross-library merges through later refresh jobs or refresh-debt retries. The change covers …
Out of Scope Changes check Passed The changes map to issue #2801 or its supporting work. Scope plumbing: access.MetadataCurationScope, its context helpers and authorizer, and the middleware that records the curator's libraries (`per…
Description check Passed The description is detailed and directly describes the changeset: curator library scope checks on provider-ID edits, splits, and refresh jobs (curation_scope payload), refresh-debt handling for scope …
Full details: Title check

Explanation

The title names the main change: curator-chosen provider IDs are now checked against the curator's libraries. It matches the changeset, which adds curator scope checks for provider-ID edits, splits, and refresh jobs. The title uses the conventional fix(catalog) prefix and stays under one line.

Full details: Linked Issues check

Explanation

Issue #2801 has one direct linked target. Its requirement is that curator-chosen provider IDs must not reach cross-library merges through later refresh jobs or refresh-debt retries. The change covers the three paths the issue names. (1) Provider-ID edits: lockCuratedProviderIDs and LockMetadataCurationIdentity in internal/catalog/metadata_curation.go check changed IDs and their derived anchor against existing owners, including durable provider-ID rows, under the request's curation authorizer. Out-of-scope owners return ErrMetadataCurationScope, which maps to 403. Split targets built from chosen IDs get the same check. (2) Refresh jobs: CreateItemMetadataRefresh stores curation_scope in the job payload, and ItemRefreshRequest.CurationScope applies it during Execute, so the job checks the curator's libraries when it runs. (3) Refresh debt: refreshFailureLeavesNoDebt excludes curation-scope refusals from failure counters and debt. The issue lists three possible directions and asks for a maintainer decision. The PR combines the first two and documents the boundary for automatic convergence. The PR description and the reported maintainer acceptance support that choice. Two items are excluded by design and disclosed: IDs added by later automatic provider refreshes, and NFO identity during the folder rescan. The issue does not require either one. Test coverage is reported as DB tests for edits, re-anchor and job scope, plus unit tests for refresh debt and payload round trip. I did not re-run these tests or re-read the full diff, so this verdict relies on the supplied summary and the author's reported results.

Full details: Out of Scope Changes check

Explanation

The changes map to issue #2801 or its supporting work. Scope plumbing: access.MetadataCurationScope, its context helpers and authorizer, and the middleware that records the curator's libraries (permissions.go, policy_gates.go). Enforcement: the metadata update and split paths, the 403 mapping in UpdateCatalogItemMetadata, and the UpdateMetadata transaction lock. Refresh path: the curation_scope payload and ItemRefreshRequest.CurationScope. Debt handling: refreshFailureLeavesNoDebt in service.go. Tests and supporting files: the DB and unit tests, the db-contracts.txt entries, and the API documentation about the boundary. No unrelated behavior change appears in the supplied summary. The documentation records the intended boundary and does not add unrelated behavior.

Full details: Description check

Explanation

The description is detailed and directly describes the changeset: curator library scope checks on provider-ID edits, splits, and refresh jobs (curation_scope payload), refresh-debt handling for scope refusals, plus tests, evidence, and risks. It is clearly related to the changes in the summary.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

@silo-triage silo-triage Bot added the size/XL 500–999 added + deleted lines (all files); change volume, not priority. label Nov 10, 2026
@silo-kody

silo-kody Bot commented Nov 10, 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 ❌

@blurbery
blurbery marked this pull request as ready for review November 10, 2026 05:22
Comment thread internal/adminjob/item_refresh.go Resolved
Comment thread internal/catalog/metadata_curation.go Resolved
Comment thread internal/catalog/metadata_curation.go Resolved
@silo-kody

silo-kody Bot commented Nov 10, 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 ❌

Comment thread internal/catalog/metadata_curation.go Resolved
@coderabbitai coderabbitai Bot added bug Something isn't working go Pull requests that update go code impact: security Auth, privacy, or permission boundary needs-review Needs maintainer review to resolve uncertain classification, scope, or changed evidence. labels Nov 10, 2026

@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: 3

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: 655675c0-642a-4f0e-8e3e-fe2d5a22512b
Commits

Reviewing files that changed from the base of the PR and between 30a6abd and 08be5e1.

Files selected for processing: 15

  • docs/admin-catalog-api.md
  • internal/access/metadata_curation.go
  • internal/adminjob/item_refresh.go
  • internal/adminjob/item_refresh_test.go
  • internal/api/handlers/admin_item_metadata_service.go
  • internal/api/handlers/admin_split.go
  • internal/api/middleware/permissions.go
  • internal/api/middleware/policy_gates.go
  • internal/catalog/item_repo.go
  • internal/catalog/metadata_curation.go
  • internal/catalog/metadata_curation_db_test.go
  • internal/metadata/identify_sticky_db_test.go
  • internal/metadata/refresh_debt_test.go
  • internal/metadata/service.go
  • 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.

Comment thread internal/metadata/service.go Resolved
@silo-kody

silo-kody Bot commented Nov 10, 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 ❌
⚠️ 4 Kody Rule(s) were not evaluated

These rules declare that they need repository context beyond this diff, and the review could not retrieve it, so they were not judged on this pull request:

  • Preserve optional store capabilities through production wrappers
  • Detach mandatory cleanup from request cancellation and bound its lifetime
  • Preserve durable media identity and share identity-evidence precedence
  • Bound decoder throughput trades and share direct-play eligibility

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

Caution

Some comments are outside the diff and can’t be posted inline due to GitHub limitations.

⚠️ Outside diff range comments (1)

Major · Compare stored IMDb IDs case-insensitively · metadata_curation.go:153-188

internal/catalog/metadata_curation.go:153-188
Major · Security & Privacy · Quick win

Compare stored IMDb IDs case-insensitively

If an out-of-scope movie stores TT123 and the edited movie has a different TMDB anchor, the owner query misses that movie when a curator selects tt123. The edit can then persist without the required owner authorization.

Nitpick comments: 1

internal/catalog/metadata_curation_db_test.go: 1

68-71: Trivial · Maintainability & Code Quality · Quick win

Assert the stored values after allowed edits.

The allowed cases check only that UpdateMetadata returns nil. A no-op could pass. Assert the stored TMDB ID or title for each allowed case; the query must also read the title.

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: 237dcf9b-7d68-4b69-b017-89cb0ecfc8ff
Commits

Reviewing files that changed from the base of the PR and between 08be5e1 and 2fe0aa4.

Files selected for processing: 3

  • internal/catalog/metadata_curation.go
  • internal/catalog/metadata_curation_db_test.go
  • internal/metadata/service.go
Files skipped from review as they are similar to previous changes: 2

  • internal/metadata/service.go
  • internal/catalog/metadata_curation.go

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

@silo-triage silo-triage Bot added the priority: P0 Fix/merge first: data-loss, security, or widespread breakage label Nov 12, 2026
@silo-kody

silo-kody Bot commented Nov 14, 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 ❌
⚠️ 4 Kody Rule(s) were not evaluated

These rules declare that they need repository context beyond this diff, and the review could not retrieve it, so they were not judged on this pull request:

  • Preserve optional store capabilities through production wrappers
  • Detach mandatory cleanup from request cancellation and bound its lifetime
  • Preserve durable media identity and share identity-evidence precedence
  • Bound decoder throughput trades and share direct-play eligibility

…ile comparing

A refresh drops provider IDs it can't use before deriving the anchor, so derive the curation check's anchor the same way, and lock the edited item before comparing its stored IDs so a concurrent edit can't make a resent ID look unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

@Quick104 Quick104 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.

Two findings in the provider-ID check, both found by a cross-provider review round (Codex gpt-6.1-sol) and verified against the source. Both need the edited item to already keep an IMDb ID anchored in another library. I'm fixing both on this branch; the summary comment follows once the fix is pushed.

🤖 Claude Code (claude-opus-5-5)

Comment thread internal/catalog/metadata_curation.go Resolved
Comment thread internal/catalog/metadata_curation.go Resolved
@silo-kody

silo-kody Bot commented Nov 14, 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 ❌

@Quick104

Quick104 commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

Reviewed head: 0fa214e52, on main at 5d6379036.

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

Fit: this closes a gap in an existing permission. A curator limited to some libraries could reach another library's title through stored provider IDs and the work that acts on them later. The change puts the check where the curator makes the choice, carries the scope on the job they queue, and leaves administrators and automatic work alone. Readiness: the edit-time check and the refresh-debt guard each fail on main and pass here, and the two holes the review found are fixed and covered.

Changes pushed during review

  • Merged main. fix(adminjob): match a complete refresh's unlinked series before resolving it #4089 and fix(metadata): reset fields the provider has no value for #3939 reworked the same refresh call in ItemRefreshExecutor.Execute, which now resets or refreshes. The curator's scope covers both, and a reset-mode row in TestItemRefreshHoldsCuratorJobsToTheirLibraries fails if the scope is dropped from the reset path (399fd8131).
  • Fixed both review findings in 2ff2684f2. The check derives the anchor from the IDs a refresh keeps, so a TMDB ID of "0" no longer hides a kept IMDb anchor in another library. It also locks the item before comparing its stored IDs.
  • Fixed Kody's follow-up in 0fa214e52. Kept IDs are trimmed before validation, as refresh does, so a stored TMDB ID with stray whitespace still anchors the check. A new test row fails on 2ff2684f2 and passes here.

Verification

  • TestCuratedProviderIDEditsStayInCurationScopeDB doesn't build on main because it uses the new MetadataCurationScope. With a plain authorizer in its place, its two out-of-scope rows fail on main (UpdateMetadata() error = <nil>, want refused=true) and pass here. The new "0" row fails on 399fd8131 and passes on 2ff2684f2. All runs used a freshly migrated Postgres.
  • TestCurationScopeRefusalLeavesNoRefreshDebt fails on main (refresh failures = 1, want 0).
  • TestCuratorRefreshReanchorStaysInScopePostgres also passes on main, because fix(catalog): authorize curation destinations before mutation #2777 already refuses a re-anchor under a request authorizer. It guards that behavior but doesn't show this change. The job payload carrying curation_scope is shown by the live capture on the evidence page, which still matches this head.
  • The concurrent-edit fix is checked by reading the source; the interleaving wasn't reproduced.
  • Review method: a multi-angle code review, a validation-impact check, and one cross-provider round (Codex gpt-6.1-sol), which raised the two findings above. The other candidates were declared in Risks, settled in the Kody threads, or not caused by this PR.

Maintainer decisions

  • The boundary in Risks is accepted as documented. IDs a provider adds during a later automatic refresh converge as automatic work, and a curator's choice is checked when it is written.

Remaining

  • Nothing blocking. The split's out-of-order locking (Risks), and the edited item's lock taken before the sorted set, can roll back one of two concurrent curations that pick each other's titles. No data is lost.

Validated features

Validation tasks: none stands. #1210 C1/C2 and #1211 C1/C2 passed as an administrator. Administrator and automatic work carry no curation scope and take the same code paths: MetadataCurationTxOptions returns the default options without an authorizer, and the executor uses the job's context unless curation_scope is set.

User manual and clients

  • Manual unaffected. The access page already says Metadata Curation lets a user correct media in the libraries they can access, and this makes the server enforce that.
  • Other clients: N/A. Only the server changes, and the 403 already exists for match and split. jellycompat has no item metadata write or refresh route.

🤖 Claude Code (claude-opus-5-5)

Comment thread internal/catalog/metadata_curation.go Resolved
Comment on lines +219 to +220
err := tx.QueryRow(ctx, `SELECT type, COALESCE(tmdb_id, ''), COALESCE(imdb_id, ''), COALESCE(tvdb_id, '')
FROM media_items WHERE content_id = $1 FOR UPDATE`, contentID).Scan(&itemType, &stored.Tmdb, &stored.Imdb, &stored.Tvdb)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

kody code-review Bug high

Source-first locking deadlocks concurrent cross-item edits

Concurrent cross-item edits can block each other and cause PostgreSQL to abort a transaction. Acquire all affected item locks in a consistent order, or retry transactions aborted by the deadlock detector.

Prompt for LLM
File internal/catalog/metadata_curation.go, lines 219-220:

Source-first locking deadlocks concurrent cross-item edits

Concurrent edits that select each other's provider identities can deadlock because each transaction locks its own item before requesting both items in sorted order. Acquire all affected item locks in a consistent order, or retry transactions aborted by PostgreSQL's deadlock detector.

Talk to Kody by mentioning @kody

Was this suggestion helpful? React with 👍 or 👎 to help Kody learn from this interaction.

​

​

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.

Not changed. The lock on the edited item is what makes the comparison safe: it stops a concurrent edit from changing the stored IDs between the read and the write. The deadlock needs two curator edits running at once where each picks an ID the other item holds or anchors. Postgres detects that, rolls one transaction back, and that edit returns an error and can be retried. Nothing is written partially and nothing merges. It is the same failure the PR already accepts for concurrent splits under Risks. Locking the edited item together with the sorted set would mean finding the owners before locking the item, which reopens the race the lock closes.

🤖 Claude Code (claude-opus-5-5)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

That’s a reasonable tradeoff. The source lock protects the ID comparison, and PostgreSQL will roll back a transaction chosen as the deadlock victim, preserving atomicity. The remaining impact is a failed request that must be retried; it is not necessarily retried automatically.

I’d treat the suggestion as an availability concern rather than a correctness or security blocker, given that this concurrency risk is accepted. The PR’s Risks section currently calls out concurrent splits specifically, so it would be helpful to mention cross-item provider-ID edits there too.

Consistent ordering is still possible in principle by reading optimistically, locking the discovered set in order, then re-reading and restarting the transaction if the identity or owner set changed—but that adds complexity and isn’t necessary if the retry tradeoff is acceptable.

Stored IDs aren't trimmed, and refresh trims them before deriving the anchor, so a kept TMDB ID with stray whitespace still anchors the refresh. Trim before validating so the check derives that same anchor.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@silo-kody

silo-kody Bot commented Nov 14, 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 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

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: 73934251-6601-4f75-82dd-d1fd745b9772
Commits

Reviewing files that changed from the base of the PR and between 77bba6b and 2ff2684.

Files selected for processing: 11

  • docs/admin-catalog-api.md
  • internal/adminjob/item_refresh.go
  • internal/adminjob/item_refresh_test.go
  • internal/api/handlers/admin_item_metadata_service.go
  • internal/api/handlers/admin_split.go
  • internal/api/middleware/policy_gates.go
  • internal/catalog/item_repo.go
  • internal/catalog/metadata_curation.go
  • internal/catalog/metadata_curation_db_test.go
  • internal/metadata/service.go
  • scripts/ci/db-contracts.txt

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

Comment thread internal/catalog/metadata_curation.go Resolved
@Quick104
Quick104 merged commit 9d15395 into Silo-Server:main Nov 14, 2026
31 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 go Pull requests that update go code impact: security Auth, privacy, or permission boundary needs-review Needs maintainer review to resolve uncertain classification, scope, or changed evidence. priority: P0 Fix/merge first: data-loss, security, or widespread breakage size/XL 500–999 added + deleted lines (all files); change volume, not priority.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug] Curator-chosen provider IDs reach cross-library merges through refresh jobs and refresh debt

2 participants