Skip to content

fix(catalog): scope media versions to the requested library - #1109

Closed
raiden202 wants to merge 1 commit into
Silo-Server:mainfrom
raiden202:fix/catalog-item-library-scope
Closed

raiden202 wants to merge 1 commit into
Silo-Server:mainfrom
raiden202:fix/catalog-item-library-scope

Conversation

@raiden202

@raiden202 raiden202 commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Related issue: #1032

GET /api/v2/catalog/items/{id}?library_id=... (and the v1 route the web client uses) returned media files from every library the profile could access, not just the one being browsed. When the same movie exists in two movie libraries, the detail page showed both versions and both media locations regardless of which library the viewer opened it from. The handler parsed library_id into AccessFilter.PresentationLibraryID and validated membership, but FilterMediaFilesByAccess never applied it.

Approach

Apply the presentation library scope inside FilterMediaFilesByAccess, including its unrestricted fast path, so every caller that supplies a presentation library gets narrowed results. Every current caller that sets it (catalog detail, jellycompat direct content, watch-together selection, playback) wants that narrowing; audiobooks never sets it. FileAllowedByAccess is unchanged, so direct file authorization still follows access policy and cross-library playback of an explicitly selected file keeps working. Requests without library_id behave exactly as before.

Fixing the one filter every path routes through was smaller and safer than patching the catalog handler alone, which would have left the other scoped callers inconsistent. No web or client contract changes are needed; the web client already sends library_id.

Validation

  • New TestFilterMediaFilesByAccessPresentationLibrary (seven cases: scoped and unscoped reads; the scope cannot bypass the allowlist, disabled libraries, quality ceiling, or a selected file outside the scope) fails on main and passes here.
  • go test passes for internal/catalog, internal/jellycompat, internal/watchtogether, internal/audiobooks. internal/apiv2 has two failures (TestAdminResourceCapabilitiesAndScope, TestContractFixtures) that fail identically on untouched main.
  • gofmt clean. Local golangci-lint could not run against the Go 1.27 toolchain (typecheck errors in the standard library), so changed-line lint is left to CI.
  • Manual check on a real deployment with one movie present in two movie libraries: before the fix, the item endpoint returned both files for every library_id; with this build it returns only the requested library's file for each library_id and both files when library_id is omitted.

Risks

Callers that set PresentationLibraryID now receive fewer files when an item spans libraries. All current callers were read and want this. If an item is a member of the library but has no files there, the response has an empty version list, matching existing detail behavior. No migration or contract change.

Checklist

  • I read and can explain the complete diff.
  • This pull request addresses one concern.

AI Disclosure

  • Harness: Claude Code (orchestration) and Codex CLI (implementation and review)
  • Tool(s): Claude Code, Codex CLI (codex exec)
  • Model(s): claude-fable-5-1 (orchestration, verification, PR text); gpt-6-astra, reasoning effort xhigh (implementation); gpt-5.6-terra (independent review)
  • Involvement: Fully AI-generated, human verified
  • Adversarial review: independent read-only Codex review of the full diff and every FilterMediaFilesByAccess caller, checking for callers that must not be narrowed, zero-file behavior after membership validation, the fast-path change, and test gaps. No findings.

Note

Fix catalog.FilterMediaFilesByAccess to scope media versions to selected PresentationLibraryID

  • When a PresentationLibraryID is set, FilterMediaFilesByAccess now requires each file's MediaFolderID to match that library, preventing media versions from other libraries from appearing in results.
  • Existing access predicates (FileAllowedByAccess, allowlists, disabled-library checks, quality ceilings, and SelectedFileID handling) still apply on top of the library scope.
  • Behavior is unchanged when no presentation library is selected; the unrestricted fast path remains only in that case.
  • Adds table-driven tests in access_filter_test.go covering scoping, allowlist interaction, disabled libraries, quality ceilings, and SelectedFileID.
  • Behavioral Change: callers that previously received media files across all libraries when a PresentationLibraryID was set will now only see files from that library.

Macroscope summarized 684174b.

Summary by CodeRabbit

  • Bug Fixes
    • File access filtering now limits results to the selected presentation library when one is specified.
    • Existing access restrictions, disabled libraries, quality limits, and file selections continue to be enforced without bypass.

Item details returned versions from every accessible library even when
library_id selected one library, so the web UI showed files and media
locations from libraries the viewer was not browsing.

Apply the presentation library scope in FilterMediaFilesByAccess,
including its unrestricted fast path, so every caller that supplies a
presentation library gets narrowed results. FileAllowedByAccess stays
unchanged so direct file authorization still follows access policy.
Unscoped reads keep returning all accessible versions.

Related issue: Silo-Server#1032

Validation: TestFilterMediaFilesByAccessPresentationLibrary failed before
the change and passes after. go test passes for internal/catalog,
internal/jellycompat, internal/watchtogether, and internal/audiobooks.
internal/apiv2 has two failures (TestAdminResourceCapabilitiesAndScope,
TestContractFixtures) that fail identically on main before this change.
gofmt is clean. No web or client contract changes are needed.

Harness: Codex CLI orchestrated by Claude Code
Model: gpt-6-astra (xhigh) implementation; claude-fable-5-1 orchestration and review
Involvement: Fully AI-generated, human verified.
@coderabbitai

coderabbitai Bot commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

Review Change StackReview 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: b38add9f-e163-4499-877a-de6f40eab4ca

📥 Commits

Reviewing files that changed from the base of the PR and between 395f5e9 and 684174b.

📒 Files selected for processing (2)
  • internal/catalog/access_filter.go
  • internal/catalog/access_filter_test.go

Included review availability: Your plan provides up to 2 included reviews per hour; 1 remains after this review.


📝 Walkthrough

Walkthrough

FilterMediaFilesByAccess now limits results to the requested presentation library while preserving existing access restrictions. New table-driven tests cover library scope and its interaction with allowlists, disabled libraries, playback quality, and selected files.

Changes

Presentation library filtering

Layer / File(s) Summary
Filter and validate presentation library scope
internal/catalog/access_filter.go, internal/catalog/access_filter_test.go
FilterMediaFilesByAccess no longer uses the unrestricted fast path when PresentationLibraryID is set. The per-file filter requires matching MediaFolderID. Tests verify that presentation library scope does not bypass existing access, disabled-library, quality, or selected-file constraints.

Priority: ⬇️ Low

Estimated code review effort: 1 (Trivial) | ~5 minutes

Change: Bug fix

Suggested reviewers: quick104

Merge Risk: ⚪ Minimal · up to 68417

The library-specific media filtering change is covered without an identified current-head regression and is ready to merge after normal checks.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.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 checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: scoping catalog media versions to the requested library.
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.
  • Fix all pre-merge checks with AI
✨ 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.

@greptile-apps

greptile-apps Bot commented Sep 16, 2026

Copy link
Copy Markdown

RetriggerConfidence Score: 5/5

The PR appears safe to merge; the shared filter now consistently enforces the requested presentation-library scope without weakening access checks.

Reviews (1) · Last reviewed commit: "fix(catalog): scope media versions to th..."

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

The code does what the description says and the new test is honest. My concern is the premise. This turns library_id into a file-visibility filter for every caller of FilterMediaFilesByAccess, unconditionally, and that changes behavior well outside the detail page #1032 is about. I'd like a decision on the product question before this merges.

The premise

Silo merges the same movie across libraries by content ID on purpose: one item, many versions. library_id has meant "which library am I browsing" — it picks the metadata-language fallback (internal/catalog/detail.go:815) and validates item membership (internal/catalog/detail.go:1003). This makes it also decide which files exist. Four consequences worth deciding on explicitly:

  • Results depend on how you got there. web/src/pages/ItemDetail/index.tsx:167 reads libraryId from the URL, so it is present when you arrive from a library page or a library-scoped section and absent from Home, search, and direct links. After this change the same movie shows one version from the library grid and two from Home, with nothing in the UI explaining the difference.
  • The "Movies" + "Movies 4K" layout loses its point. Opening the shared title from "Movies" hides the 4K file entirely. That split-library setup is the case version merging was built for.
  • The admin curation view narrows too. "Media locations" (web/src/pages/ItemDetail/MovieContent.tsx:322, EpisodeContent.tsx:403, gated on canCurateMetadata) exists to show every file backing an item. Scoping it by browse path removes the signal an admin needs to spot a cross-library duplicate.
  • It reaches playback, not just presentation. GetWatchDetail (internal/catalog/detail.go:2890, :2947) and watch-together selection run through the same filter. internal/watchtogether/selection_resolver.go:73 takes detail.Versions[0].FileID and :55 returns ErrInvalidSelection on an empty list, so the file a room plays now depends on whether the host's client sent library_id.

The reporter isn't wrong to want per-library scoping. Both behaviors are defensible, which is the argument for making it the operator's call rather than a silent server-wide change. Options:

  1. A server setting under admin → Libraries, default off. Server-wide rather than per-library: an item that lives in two libraries would otherwise have two conflicting answers.
  2. Apply the scope at the catalog detail seam only, leaving GetWatchDetail and watch-together on the full set, so presentation narrows but playback never loses a version.
  3. Close #1032 as working as intended and document that versions are unified by content ID.

I'd take 1 with the default off. The current shape is the one option with no way back.

Multi-repo checklist

The body says "No web or client contract changes are needed." The wire format doesn't change, but the meaning of library_id does — on /api/v1, /api/v2, and the Jellyfin surface — so CLAUDE.md's client-visible-change checklist applies, and none of its three items is addressed:

  • silo-apple / silo-android: any client sending library_id silently loses versions. No follow-up filed or ruled out.
  • jellycompat parity: internal/jellycompat/content_direct.go:267 feeds six read paths, and internal/jellycompat/handlers_items.go:2436 derives the library from the Jellyfin ParentId query parameter. In Jellyfin ParentId means "children of this folder," not "filter this item's MediaSources," so third-party clients get behavior their target server doesn't have. internal/jellycompat/handlers_playback.go:1954 passes nil, so one session sees narrowed sources in the item list and the full set at PlaybackInfo.
  • docs: no docs/*-api.md update describing what library_id now does.

Separately, /api/v1 is frozen to critical fixes that keep the bridge usable. This lands there through the shared service; worth a sentence on why it qualifies, or scoping it to v2.

Optional

MediaFileAccessSQL (internal/catalog/access_filter.go:261) carries a comment that it must stay in step with its Go counterpart. That's still literally true — FileAllowedByAccess is unchanged — but there are now two file-filtering paths with different scoping rules, and internal/sections/overlay_summaries.go:55 uses the SQL one. It agrees today only because no sections caller sets PresentationLibraryID. Either mirror the scope in SQL or note in the Go comment that the scope is deliberately Go-only.

Verified

go test ./internal/catalog/... ./internal/watchtogether/... passes at 684174b. CI is green. I found no correctness defect in the diff itself; the blocker is the product decision above.


AI disclosure: review written with Claude Code, model claude-opus-5[1m].

for _, file := range files {
if FileAllowedByAccess(file, filter) {
if FileAllowedByAccess(file, filter) &&
(filter.PresentationLibraryID == nil || file.MediaFolderID == *filter.PresentationLibraryID) {

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.

Putting the scope here applies it to every caller, including the two playback paths. GetWatchDetail (internal/catalog/detail.go:2890, :2947) and internal/watchtogether/selection_resolver.go both filter through this function, and the resolver takes detail.Versions[0].FileID at :73 and rejects an empty list at :55. The result is that which file actually plays depends on whether the client sent library_id, not on quality or user choice.

If the intent is presentation scoping, the catalog detail seam is the narrower place for it. See the review body for the broader question.

@Quick104

Copy link
Copy Markdown
Contributor

Closing this in favor of a maintainer PR that makes the scoping opt-in.

The diff itself is correct and the test is good — we're carrying the test forward. The change we can't take as-is is the premise: Silo merges the same title across libraries by content ID on purpose, and an unconditional library_id scope inside FilterMediaFilesByAccess also narrows playback and watch-together selection, hides versions from the admin "Media locations" view, and changes Jellyfin ParentId semantics. Details in the review above.

The replacement adds a server setting (catalog.scope_versions_to_library, default off), applies the scope only to /api/v2 catalog reads when it's on, and reports it through a capability endpoint. It will reference #1032 and link back here.

Thanks for the clear diagnosis in #1032 and the fix; it saved real time.

AI disclosure: comment written with Claude Code, model claude-fable-5-1[1m].

@Quick104

Copy link
Copy Markdown
Contributor

Replacement is up: #1111.

pull Bot pushed a commit to AmirulAndalib/silo-server that referenced this pull request Sep 17, 2026
Silo merges the same title across libraries by content ID on purpose,
so a detail read with library_id always listed every accessible
version. Silo-Server#1032 asked for the browsed library's files only. Doing that
unconditionally inside FilterMediaFilesByAccess (Silo-Server#1109) would also have
narrowed playback, watch-together selection, the admin Media locations
panel, and the Jellyfin ParentId reads.

Add catalog.scope_versions_to_library (default false). When on, the v2
item, versions, season, and episode reads that were given a library_id
return only the versions stored in that library. Playback, watch-
together, and jellycompat never opt in, so an item always plays from its
full version list. GET /api/v2/capabilities/catalog reports the
effective value so clients know whether a version list is the whole
item or one library's slice.

The predicate and its table test come from Silo-Server#1109.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
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