Skip to content

fix(catalog): keep titles in no library out of admin listings - #3114

Merged
Quick104 merged 1 commit into
Silo-Server:mainfrom
Rhainland:fix/ghost-unmatched-items
Oct 27, 2026
Merged

Quick104 merged 1 commit into
Silo-Server:mainfrom
Rhainland:fix/ghost-unmatched-items

Conversation

@Rhainland

@Rhainland Rhainland commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Closes #2818
Related issue: N/A
Validation tasks: none (no passed case is reachable). The unmatched-items list (#198), rescans and unmatched visibility (#197), search and browse (#199) and the Series admin list (#1251) change for titles in no library; none of these tasks has a recorded result yet.

After a movie's file is renamed to point at another title, an administrator keeps seeing a broken copy of it for a day. The copy shows up in Admin → Libraries → Unmatched items with no library and no file paths to match, and in search and cross-library browse next to the real movie, without a poster. This change keeps titles that belong to no library out of those listings for every viewer, not just restricted ones.

To reproduce: scan Atlas (2024)/Atlas (2024).mkv, which stays unmatched (local-…) because several 2024 films are called Atlas. Rename it Radarr-style to Atlas (2024) {tmdb-614933}/Atlas (2024) {tmdb-614933} [WEBDL-1080p].mkv and run a full scan. The new path gets a new, matched movie-tmdb-614933 item. The old item loses its library membership and its file is marked missing, but reconciliation keeps it for the scanner's file removal grace (24 hours by default) so a replacement file can still relink to it. That hold is intended for arr upgrades. The listings were the problem: a viewer with no library restriction got no membership check, so the held item was listed.

Approach

Listings that name no library now require the title to belong to one. Restricted viewers already had this rule, and #2695 applied it to Home rows. It is one predicate, catalog.InSomeLibraryWhere, used by:

  • the catalog query executor (v2 browse and the lists built on it) and the offset browse that v1 and source-order lists use
  • browse filter values, so no offered genre or letter comes only from a hidden title
  • Postgres search, its fuzzy fallback, and the hydration of Meilisearch hits
  • GET /api/v2/libraries/unmatched-items and its frozen v1 counterpart

Reads by ID are unchanged, so an administrator can still open a held title from a link. The scanner and reconciliation are untouched: a replacement file that arrives within the grace still relinks to the held item with its metadata, and a full scan after the grace deletes it.

This is server-only. Web, Apple and Android clients read these endpoints and need no change. Jellyfin-protocol search shares the same search code and gets the same behavior. Two scanner problems from the report stay open as follow-ups. A file renamed to add a provider tag still gets a new item instead of rebinding to its existing local- item. A scan scoped only to the new folder (autoscan or a webhook) leaves the old item with its membership and an unmarked file until the next full library scan.

Validation

  • New database tests, listed in scripts/ci/db-contracts.txt: the unmatched-items list and total, search (full text, fuzzy fallback and Meilisearch hydration), and browse (cursor, offset and genre values) each leave out a title in no library and keep one in a library. Each failed on main before its fix.
  • Three existing database fixtures that seeded titles in no library to test unrelated counts, totals and search plans now give those titles a library.
  • Local server with the TMDB plugin and generated files, end to end: on main the reproduction above leaves the old Atlas in the unmatched list, in search and in GET /api/v2/catalog?type=movie. With this branch it appears in none of them, and the matched Atlas still does. Deleting a matched movie's only file, scanning, and adding a replacement file within the grace brought back the same movie-tmdb-949 item, hidden in between.
  • go build, gofmt, go vet, make lint-changed, make lint-router-recovery, make verify-local-paths, make verify-size-ratchet, make verify-bidi, make verify-apiv2-openapi, make verify-apiv2-contract, make verify-v1-route-freeze: pass.
  • make test-db-contracts: all 367 pass. make test-db-pins: all pass except TestLogPartitionsMatchPartmanOnNonUTCServer, which fails the same way on main in the same environment.
  • make test-go: fails only TestPlaybackInfoWithoutStripOrToneMapStillHasNoRoute and TestPlaybackInfoSkipsStripWhenRPUCannotBeStripped in internal/jellycompat, which fail the same way on main.
  • Web gate not run: no web files changed.

Evidence

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

Surface and build: web admin Libraries page (Unmatched items) and web search for "Atlas", desktop and phone width, signed in as an administrator, local dev server with a generated test library. Before is main at 8b84639, after is this branch. The page also has the API responses for the unmatched list, search and cross-library browse (the web app has no page that browses movies across libraries), and the removal-grace check.

Risks

An administrator no longer sees titles in no library in lists, search and filter values. Outside the removal grace, reconciliation already deletes such titles, so this only hides items that are held or under an unreachable library root. Each listing gains an EXISTS lookup on the leading content_id column of the media_item_libraries primary key.

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 (Claude Agent SDK) running in T3 Code
  • Tool(s): Claude Code; Codex CLI for the second review
  • Model(s): claude-opus-5-5; gpt-6.1-sol (review only)
  • Involvement: Fully AI-generated, human verified
  • Adversarial review: two independent reviews of the full diff (claude-opus-5-5 and gpt-6.1-sol, correctness, standards and spec), then a gpt-6.1-sol review of the fixes. Findings: browse filter values still counted hidden titles (fixed), the offset browse still listed them (fixed), and the membership check was repeated in several places (moved into one predicate). The second round found nothing.

Note

Exclude items in no library from catalog listings, search, and unmatched items

Adds an EXISTS predicate on the library-membership table so items with no library membership no longer appear in catalog browse, search (full-text, fuzzy fallback, and hydration), preview pages, and the unmatched-items listing. The new InSomeLibraryWhere and appendListedLibraryAccessConditions helpers in access_filter.go apply the predicate only when no library restrictions are given; restricted queries keep the old conditions. Reads by ID are unchanged.

  • Adds database tests for browse, search, unmatched items, and mixed-catalog counts; existing tests gain library memberships for their fixtures.
  • Documents the behavior in missing-files.md and the v2 unmatched-items section of libraries-api.md.
  • Behavioral Change: an item held during the scanner's file-removal grace period with no library is now hidden from listings; administrators also see only library members in listings.

Macroscope summarized 213e37c.

A movie whose file is renamed to another title (for example a Radarr
rename that adds a TMDB tag) gets a new item on the next full scan. The
old item loses its library membership but is kept for the scanner's file
removal grace, so a replacement file can still relink to it. Until then
an unrestricted administrator still saw it: in the unmatched-items list
(with no library and no file paths to match), in search, and in browse
and filter values that name no library.

Listings that name no library now require the item to belong to one, as
they already did for restricted viewers and for Home rows. The rule is
one predicate, catalog.InSomeLibraryWhere, applied by the catalog query
executor, the offset browse, browse filter values, Postgres search and
its fuzzy fallback, Meilisearch hit hydration, and the unmatched-items
list. Reads by ID are unchanged, and the removal grace still relinks a
replacement file to the held item.
@silo-triage silo-triage Bot added the size/L 200–499 added + deleted lines (all files); change volume, not priority. label Oct 26, 2026
@silo-kody

silo-kody Bot commented Oct 26, 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 26, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent 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: 15f7869f-3606-4f52-85c1-a56d178cf083
Commits

Reviewing files that changed from the base of the PR and between 8b84639 and 213e37c.

Files selected for processing: 15
  • docs/architecture/missing-files.md
  • docs/libraries-api.md
  • internal/api/handlers/libraries_service.go
  • internal/api/handlers/libraries_unmatched_ignore_db_test.go
  • internal/catalog/access_filter.go
  • internal/catalog/browse.go
  • internal/catalog/catalog_library_scope_db_test.go
  • internal/catalog/item_repo.go
  • internal/catalog/manga_counts_db_test.go
  • internal/catalog/query_executor.go
  • internal/catalog/query_executor_total_db_test.go
  • internal/catalog/search_cursor_test.go
  • internal/catalog/search_optimization_db_test.go
  • internal/catalog/search_postgres_mixed.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; 3 remain after this review.

Walkthrough

Catalog, search, and unmatched-item listings now exclude items without library membership. Database tests cover these listing paths, and documentation describes the filtering behavior.

Changes: Library membership listing filters

Layer / File(s) Summary
Catalog and search filtering
internal/catalog/*, scripts/ci/db-contracts.txt, docs/architecture/missing-files.md
Catalog browse, facets, and search now filter out items without a library association. Database tests cover catalog results, genres, search results, and hydration, including unrestricted and disabled-library access filters.
Unmatched-item API filtering
internal/api/handlers/libraries_service.go, internal/api/handlers/libraries_unmatched_ignore_db_test.go, docs/libraries-api.md
The unmatched-items API excludes items without library membership while retaining its manga-chapter and ignored-state filters. A database test and API documentation cover the behavior.

Priority: Normal

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

Change: Bug fix · Severity of issue fixed: Medium

Possibly related issues

Suggested labels: bug, go, api-v2, impact: usability, size/XL

Suggested reviewers: quick104, blurbery

Merge Risk: Minimal · up to 213e3

Listings exclude titles with no library membership, and no issue requiring a change before merge was established.

Security architecture risk: Low · up to 213e3

The change narrows which titles appear in listings without broadening permissions. Existing library restrictions and direct-access rules remain intact. Residual uncertainty concerns broader integration behavior and validation, not an identified authorization bypass.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The effective change spans media-listing consumers, including unrestricted viewers and administrators. The inspected changes reduce returned title metadata; they do not grant additional library access or mutation authority.

Trust Boundaries and Controls

  • observed — Both unmatched-item HTTP routes retain acting-admin enforcement. The v1 handler accepts search and pagination inputs, not a caller-selected library authorization scope; the service adds membership eligibility unconditionally. The inspected route-to-service relationship therefore does not expose a new scope-based bypass.

Resilience and Maintainability Implications

  • observed — The documented lifecycle separates hiding a title from deleting it: reconciliation removes membership, a removal grace can preserve the item for relinking, and later reconciliation can delete it. The inspected listing changes consume membership through read predicates rather than introducing a new hold, cleanup, or recovery transition.
Pre-merge checks: Passed 3 · Failed 2

Failed Failed checks: 2 warnings

Check name Status Explanation Resolution
Linked Issues check Warning The changes satisfy the listing part of #2818. They exclude items with no library membership from catalog browse, search, filter values, and unmatched-item results, including during the retention peri… Implement the #2818 unavailable-item detail behavior. When a retained item has no indexed playable file, show its unavailable state and do not offer the failing metadata-refresh action. Add automated coverage for this behavior.
Docstring Coverage Warning Docstring coverage is 60.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 15 functions across 12 files. (3 skipped:… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 3 passed
Check name Status Explanation
Title check Passed The title clearly and concisely describes the main change: excluding titles with no library from catalog listings, including administrator listings.
Description check Passed The description is directly related to the changeset. It explains the problem, implementation, affected listing surfaces, validation, risks, and out-of-scope scanner follow-ups.
Out of Scope Changes check Passed The changed production code, documentation, database tests, fixture updates, and CI test registration support the #2818 listing-visibility behavior. The changes do not modify unrelated scanner reconci…
Full details: Out of Scope Changes check

Explanation

The changed production code, documentation, database tests, fixture updates, and CI test registration support the #2818 listing-visibility behavior. The changes do not modify unrelated scanner reconciliation or client functionality. The reported scanner follow-ups remain outside this pull request.

Full details: Linked Issues check

Explanation

The changes satisfy the listing part of #2818. They exclude items with no library membership from catalog browse, search, filter values, and unmatched-item results, including during the retention period. The issue also requires an opened unavailable item to explain its state instead of offering a metadata refresh that cannot succeed. The PR states that reads by ID remain unchanged and makes no client or item-detail change. That requirement is not implemented or covered by an automated test.

Resolution

Implement the #2818 unavailable-item detail behavior. When a retained item has no indexed playable file, show its unavailable state and do not offer the failing metadata-refresh action. Add automated coverage for this behavior.

Full details: Docstring Coverage

Explanation

Docstring coverage is 60.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 15 functions across 12 files. (3 skipped: 3 unsupported.)

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

Finishing Touches: 💡 1
🛠️ Fix failing CI checks: 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

@silo-triage silo-triage Bot added bug Something isn't working go Pull requests that update go code priority: P2 Limited scope, workaround exists, or polish labels Oct 26, 2026
@macroscopeapp

macroscopeapp Bot commented Oct 26, 2026

Copy link
Copy Markdown

Evidence: EVIDENCE_LINK is a placeholder, so the described captures and API responses are not available to review.

  • internal/api/handlers/libraries_service.go: The Unmatched items list drops entries with no library; provide before-and-after captures of the same list (desktop and phone-width) and, if available, the same request's response excerpts.
  • internal/catalog/item_repo.go, internal/catalog/search_postgres_mixed.go: Search results drop items with no library; provide before-and-after captures of the same search on desktop and phone-width.
  • internal/catalog/browse.go, internal/catalog/query_executor.go: Cross-library browse results and browse filter values exclude items with no library; provide before-and-after excerpts for the same browse and filter-values requests, or captures of the same screen where available.

Suggested fix: replace the placeholder with the actual evidence URL or attach the requested before-and-after captures and response excerpts.

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

The placeholder came from the first version of the body. It now links the published page: https://evidence.siloserver.org/r/silo-server/pr-3114/

What the page has:

  • Unmatched items list: before and after captures of the same list, desktop and phone width, plus the GET /api/v2/libraries/unmatched-items responses.
  • Search for "Atlas": before and after captures, desktop and phone width, plus the GET /api/v2/catalog?q=Atlas responses.
  • Cross-library browse: before and after GET /api/v2/catalog?type=movie responses. The web app has no page that browses movies across libraries, so there is no screen to capture.
  • Filter values: no capture. The left-behind item in this repro is unmatched, so it has no genres or other filter values. Filter values only change when a held item carries a value no other title has. TestCatalogQueryWithoutLibraryLeavesOutItemsInNoLibraryDB covers that case.

@coderabbitai coderabbitai Bot added api-v2 API v2 / Huma migration program (epic #135); long-running, stacked by phase impact: usability Core flow broken or severely blocked size/XL 500–999 added + deleted lines (all files); change volume, not priority. labels Oct 26, 2026
@Rhainland

Copy link
Copy Markdown
Contributor Author

ci / Go DB pins failed only on TestLogPartitionsMatchPartmanOnNonUTCServer/America/New_York ("operational_logs_default holds 1 rows inside the partitioned window"). The other pins and all other jobs passed. That test inserts hourly log rows from now() to eight days ahead under a New York session time zone, so whether it passes depends on the time of day. It fails the same way on main at 8b84639 against a local database at this hour, while main's own CI passed at 20:03 UTC. This PR doesn't touch log partitioning. Could a maintainer re-run the failed job?

@silo-triage silo-triage Bot removed the size/XL 500–999 added + deleted lines (all files); change volume, not priority. label Oct 27, 2026
@Quick104
Quick104 merged commit 73a6ae6 into Silo-Server:main Oct 27, 2026
14 of 16 checks passed
Quick104 added a commit to Rhainland/silo-server that referenced this pull request Nov 1, 2026
Main's Silo-Server#3114 added catalog.InSomeLibraryWhere for listings that name no
library, and keeps reads by ID open for an unrestricted viewer. Use it for the
audiobook listing predicates, and drop the membership check from the single
GetAudiobookByID read, so progress sync for a book between a rename's two scans
isn't rejected. Batch hydration for the in-progress shelf and the progress list
still leave out books in no library.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api-v2 API v2 / Huma migration program (epic #135); long-running, stacked by phase bug Something isn't working go Pull requests that update go code impact: usability Core flow broken or severely blocked priority: P2 Limited scope, workaround exists, or polish size/L 200–499 added + deleted lines (all files); change volume, not priority.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug] Renamed movie files leave visible, unplayable cards despite missing files and removed library memberships

2 participants