Skip to content

fix(sections): keep titles in no library out of Home rows - #2695

Merged
Quick104 merged 2 commits into
Silo-Server:mainfrom
Rhainland:fix/2684-home-recs-orphaned-items
Oct 21, 2026
Merged

Quick104 merged 2 commits into
Silo-Server:mainfrom
Rhainland:fix/2684-home-recs-orphaned-items

Conversation

@Rhainland

@Rhainland Rhainland commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Closes #2684
Related issue: N/A
Validation tasks: none (no passed case is reachable. Row contents change for #1140, #1142, #1145, #1146, Silo-Server/silo-apple#305, #306 and Silo-Server/silo-android#315, #316, none of which has a recorded result yet.)

When a title's file is deleted and the library is rescanned, the title stays in Home rows such as Recommended for You, while the same row on the library page drops it. Every profile on every client sees the stale title on Home. Nothing removes it on its own: the rescan deletes the title's library membership but keeps its media_items row, and the orphan cleanup task is manual and only covers provisional items.

The cause: a Home row has no library scope, so buildLibraryScope added no membership check. The check was there only when a disabled library narrowed the query. This change requires the title to belong to at least one library whenever no library scopes the row.

Approach

buildLibraryScope in internal/sections now adds the "belongs to some library" check in the unscoped case, not just in the deny-only case. The catalog discovery queries (appendDiscoveryLibraryScope) had the same gap, and they feed the Home Top Rated, Hidden Gems and Forgotten Favorites rows, so they get the same check. Scoped rows, restricted profiles and disabled-library filtering are unchanged.

Every caller of both helpers selects movies, series or book titles from media_items. Episodes and seasons live in their own tables, and watch activity is rolled up to the series before the check, so nothing that should show is hidden. The check is an index lookup on the media_item_libraries primary key.

Server only. The fix applies to the native API, and so to web, Android and Apple clients, with no client change needed. jellycompat reads its Latest rows through the same fetcher but always with a library, so it is unchanged.

Validation

  • New DB-backed test, listed in scripts/ci/db-contracts.txt so the DB contracts job runs it: For You, Recently Released and Critically Acclaimed on Home, on Home with a disabled library, and on a library page, each with one title in a library and one in none. It fails on main for the Home cases and passes here. A unit test covers the unscoped discovery queries.
  • A recommendation-section test fixture used a title with no library and now gets one.
  • Local server, end to end: on main, a deleted and rescanned movie stayed in Recommended for You on Home but not on the library page. With this branch it is gone from both, and it returns to both when the file is restored and the library rescanned.
  • go build, gofmt, make lint-changed, make lint-router-recovery, make verify-local-paths: pass.
  • make test-db-pins: all 273 pins pass.
  • make test-go: fails only TestPlaybackInfoWithoutStripOrToneMapStillHasNoRoute and TestPlaybackInfoSkipsStripWhenRPUCannotBeStripped in internal/jellycompat, which fail the same way on main in the same environment.
  • Web gate not run: no web files changed.

Evidence

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

Surface and build: web app Home and Movies library page (Recommended tab), desktop and phone width, local dev server with a test library. Before is main at 365e3d4, after is this branch. The page also has the section API responses for the same requests.

Risks

None identified. Titles that belong to no library stop appearing in Home rows; any such title already does not appear on library pages.

Checklist

  • I read and can explain the complete diff.
  • This pull request addresses one concern.
  • 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: the branch diff was reviewed independently by claude-opus-5-5 and gpt-6.1-sol at medium effort, covering every caller of both scope helpers, SQL argument indexes and aliases, and query cost. Neither reported a finding.

Note

Exclude items with no library membership from unscoped Home section queries

  • Moves the positive media_item_libraries membership predicate out of the disabled-library-only branch in sections.buildLibraryScope (fetcher.go) and mirrors it in catalog.appendDiscoveryLibraryScope (discovery_repo.go) so it applies whenever no library scope is set
  • Items with at least one library membership still appear in unscoped sections, even if that library is not named in the query
  • Adds query-shape tests, a Postgres integration test (TestSectionsSkipItemsInNoLibraryPostgres) covering recommended, recently released, and critically acclaimed sections, and registers it in the DB-contract manifest (db-contracts.txt)
  • Behavioral Change: unscoped and deny-only discovery/section queries now exclude media_items rows with no media_item_libraries row; disabled-library NOT EXISTS filtering is unchanged

Macroscope summarized bc47671.

@silo-triage silo-triage Bot added the size/M 50–199 added + deleted lines (all files); change volume, not priority. label Oct 19, 2026
@silo-kody

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

Copy link
Copy Markdown
Contributor

Review in 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: e650c39e-0cc0-433f-b12b-660f23331069
📥 Commits

Reviewing files that changed from the base of the PR and between 365e3d4 and 8995beb.

📒 Files selected for processing: 6
  • internal/catalog/discovery_repo.go
  • internal/catalog/discovery_repo_test.go
  • internal/sections/fetcher.go
  • internal/sections/orphan_items_db_test.go
  • internal/sections/recommendation_section_test.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.

📝 Walkthrough

Unscoped discovery and section queries now require each media item to belong to at least one library. Tests cover unscoped and disabled-library discovery queries, multiple section types and scopes, and PostgreSQL test execution.

Changes: Library Membership Filtering

Layer / File(s) Summary
Require library membership in unscoped queries
internal/catalog/discovery_repo.go, internal/sections/fetcher.go
Both query builders require media items to have a library membership when no library scope is specified.
Test membership filtering
internal/catalog/discovery_repo_test.go, internal/sections/orphan_items_db_test.go, internal/sections/recommendation_section_test.go, scripts/ci/db-contracts.txt
Discovery tests assert membership requirements for unscoped and disabled-library queries. A PostgreSQL integration test checks section results across scopes, and the database contract list includes that test. The recommendation test fixture now associates its media item with a library.

Priority: ➖ Normal

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

Change: Bug fix · Severity of issue fixed: Medium

Suggested reviewers: quick104

Merge Risk: 🔵 Low · up to 8995b

Collection rails can show different titles depending on whether a default sort is set. This bounded inconsistency can be accepted for this narrower fix or addressed before merging.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 30.77% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 13 functions across 5 files. (1 skipped: … Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly and concisely describes the main change: excluding titles with no library from Home rows.
Linked Issues check Passed Issue #2684 requires Home recommendation rows to exclude orphaned media_items rows with no media_item_libraries membership. The PR adds an EXISTS membership check to unscoped buildLibraryScope…
Out of Scope Changes check Passed The changed production code addresses stale Home rows through the shared section and discovery scope helpers. The catalog coverage, PostgreSQL coverage, fixture update, and CI registration directly su…
Description check Passed The pull request description directly explains the changes to exclude media items without library membership from unscoped Home and catalog queries, including tests and validation.
Full details: Linked Issues check

Explanation

Issue #2684 requires Home recommendation rows to exclude orphaned media_items rows with no media_item_libraries membership. The PR adds an EXISTS membership check to unscoped buildLibraryScope queries and to unscoped discovery queries. The PostgreSQL test covers Home, disabled-library, and library scopes, and the CI contract list registers the test. The change also keeps library-associated items visible.

Full details: Out of Scope Changes check

Explanation

The changed production code addresses stale Home rows through the shared section and discovery scope helpers. The catalog coverage, PostgreSQL coverage, fixture update, and CI registration directly support this behavior. The diff contains no demonstrated unrelated production or test changes.

Full details: Docstring Coverage

Explanation

Docstring coverage is 30.77% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 13 functions across 5 files. (1 skipped: 1 unsupported.)

Resolution

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

✨ Finishing Touches: 💡 1
⚔️ Resolve merge conflicts: 💡
  • Resolve merge conflict in branch fix/2684-home-recs-orphaned-items
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

@macroscopeapp

macroscopeapp Bot commented Oct 19, 2026

Copy link
Copy Markdown

The Home section rows in internal/sections/fetcher.go now omit items without a library membership, but the Evidence link still contains pr-NUMBER instead of identifying this PR’s evidence page. Please replace it with the actual page showing the same Home queries before and after (orphaned title present before, absent after), with desktop and phone-width captures and matching API excerpts.

The Home discovery rows in internal/catalog/discovery_repo.go make the same visible change; include before-and-after results and matching API responses for those rows on that page.

Automated check: Macroscope check run agent (gpt-6-luna). Evidence was not reviewed for correctness.

Posted via Macroscope — Visible change evidence

@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 19, 2026
@macroscopeapp

macroscopeapp Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

Major change: The new unscoped membership predicates change Home row contents: buildLibraryScope filters fetcher-backed sections, and appendDiscoveryLibraryScope filters catalog discovery rows. Apple and Android Home use GET /api/v2/home/sections; Web Home uses GET /api/v2/home/layout and GET /api/v2/home/sections/{id}/items, which also reach the changed section fetcher. Recommendation cards from GET /api/v2/recommendations/discover are hydrated through Fetcher.FetchItemsByContentIDs, so orphan IDs can disappear from the card output and change row contents. These changes affect C1 for the server, Web, Apple, and Android tasks listed below.

The PR must connect the intended orphan exclusion to these C1 output changes; these cases need re-validation after merge. All corresponding result cells are currently Not run, so no recorded pass is invalidated. Recommendation ranking/background refresh and restricted-profile access filtering are unchanged.

Please replace the current Validation tasks: none with:
Validation tasks: changes #1140 C1, #1142 C1, #1145 C1, #1146 C1, Silo-Server/silo-apple#305 C1 (iPhone/iPad), Silo-Server/silo-apple#306 C1 (tvOS), Silo-Server/silo-apple#309 C1 (iPhone/iPad), Silo-Server/silo-apple#310 C1 (tvOS), Silo-Server/silo-android#315 C1 (phone/tablet), Silo-Server/silo-android#316 C1 (Android TV), Silo-Server/silo-android#319 C1 (phone/tablet), Silo-Server/silo-android#320 C1 (Android TV)

Automated check: Macroscope check run agent (gpt-6-luna). No validation was performed.

Posted via Macroscope — v1 validation impact

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

Review of 8ecd373. The fix is right for the rows built on buildLibraryScope and the discovery queries. I found no title that should stay visible and is now hidden: series, manga and podcast rows carry their own membership, and episodes take a separate path. The new DB test fails on the base for all three Home cases and passes on this head. Two findings are inline. The first is fixed in a commit on this branch. The second needs a maintainer decision.

This review was produced by an AI agent (Claude Code, claude-opus-5-5, with a gpt-6.1-sol cross-check) and checked against the source and a test database.


if libraryID == nil && libraryIDs == nil && len(configLibraryIDs) == 0 {
conditions = append(conditions,
"EXISTS (SELECT 1 FROM media_item_libraries mil_scope_any WHERE mil_scope_any.content_id = mi.content_id)",

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.

Maintainer decision: other Home rows still show titles in no library. This check covers rows built on buildLibraryScope. Rows built through catalog's QueryExecutor use buildLibraryScopeJoin / libraryAccessConditions, which add the membership check only when a library is disabled. I confirmed each of these on a test database with an orphan movie and an orphan series and no disabled library:

  • Home genre and custom_filter rows (fetchFiltered → PreviewPage) still return the orphan movie. Editorial Spotlight and live collection rails take the same path.
  • Continue Watching and Next Up still return an episode of an orphan series (fetchEpisodeTargetsByContentIDs → ApplyLibraryAccessFilter).
  • New with this PR: a collection rail with no default sort now hides the orphan, but the same collection with a default sort (QueryCollectionItemsBySort) still shows it.

The first two predate this PR. The general fix is to require membership in catalog's shared libraryAccessConditions / buildLibraryScopeJoin whenever no allow list applies. That reaches every unscoped browse and search path, which is the wider problem tracked in #2818. Whether to widen this PR or land it as is and leave the rest to #2818 is for the maintainers to settle.

@Quick104

Copy link
Copy Markdown
Contributor

Review summary

Reviewed head: 8995bebfd (the original 8ecd373 plus one test-only fix commit).

Fit: 9/10 · Readiness: 8/10 — conditional (assuming CI is green)

The change does what it says for the rows it touches. A title whose last file is removed loses its library membership but keeps its media_items row on purpose, so it can recover. Library rows already hide such titles, and this makes the Home rows built on buildLibraryScope, plus the discovery rows, hide them too. That matches what the user manual already says about deleted titles: they disappear from the apps. Fit is high because it fixes a core Home experience bug at the query layer, with no new surface. Readiness holds at 8 because of the open scope question below.

Addressed

  • The new DB test wasn't listed in scripts/ci/db-contracts.txt, so CI would always skip it. It's listed now, and it passes through the CI dbpins runner. The catalog membership assertion was also renamed so its message fits the unscoped case. Commit 8995bebfd.
  • The PR body's Validation tasks: line now reads none. No passed validation case reaches this code. The tasks it named, plus Recommendations — Server #1145 and Recommendations — Web #1146 (recommendations and discover hydrate through the same fetcher), have no recorded results yet.

Left for the maintainers

  • Maintainer decision: scope. Home rows built through catalog's QueryExecutor still show titles in no library when no library is disabled: genre and custom-filter rows, Editorial Spotlight, and live or sorted collection rails. Continue Watching and Next Up episodes of an orphan series do too. I confirmed these on a test database. All but one predate this PR. The new one: a collection rail without a default sort now hides the title, but the same rail with a default sort still shows it. The general fix is to require membership in catalog's shared libraryAccessConditions / buildLibraryScopeJoin whenever no allow list applies. That touches every unscoped browse and search path, which [bug] Renamed movie files leave visible, unplayable cards despite missing files and removed library memberships #2818 tracks. The options are to land this as is and fix the rest under [bug] Renamed movie files leave visible, unplayable cards despite missing files and removed library memberships #2818, or to widen this PR.
  • Expected side effect, not a defect: during the scanner's removal grace period, or while a protected library root is unreachable, a movie in Continue Watching now leaves Home until its membership returns, as it already did on library pages. Watch progress is kept. The design is documented on ReconcileFolderMembership.

Verification

  • TestSectionsSkipItemsInNoLibraryPostgres fails on the base for For You, Recently Released and Critically Acclaimed on Home. It passes on this head, as do the other internal/sections recommendation DB tests and the focused catalog discovery tests.
  • I traced every caller of both helpers. No title that should show is now hidden: series, manga and podcast rows carry their own membership, and episodes take a separate path. The added EXISTS is an index probe on the media_item_libraries primary key.
  • A cross-provider review round (gpt-6.1-sol) found the same unlisted test and no functional regression.

Validated features

No passed validation case is reachable. The only feature with passed cases (#1143, person browsing) shares no code with this diff.

Other checks

  • User manual: unaffected. The manual already says deleted titles disappear from the apps.
  • Apple / Android / jellycompat: server only, and clients need no change. The jellycompat rows reach this code with a library or access filter set, so the new check applies there as intended.

This review was produced by an AI agent (Claude Code, claude-opus-5-5, with a gpt-6.1-sol cross-check).

@silo-kody

silo-kody Bot commented Oct 21, 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 ❌

Rhainland and others added 2 commits October 21, 2026 11:20
A Home row has no library scope, so buildLibraryScope added no
membership check and returned media_items rows whose last file was
removed: the title stayed in Recommended for You (and Recently Released
and other rows) on Home after a rescan, while the library's own rows
dropped it. The check existed only when a disabled library was set.

Require a media_item_libraries membership whenever no library scopes
the query, in buildLibraryScope and in the catalog discovery scope
behind Top Rated, Hidden Gems and Forgotten Favorites.

Closes Silo-Server#2684
List TestSectionsSkipItemsInNoLibraryPostgres in db-contracts.txt so the
DB contracts job runs it; without a list entry it always skips in CI.
Rename the catalog membership assertion so its failure message fits the
unscoped case it now also covers.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@Quick104
Quick104 force-pushed the fix/2684-home-recs-orphaned-items branch from 8995beb to bc47671 Compare October 21, 2026 15:25
@silo-kody

silo-kody Bot commented Oct 21, 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 merged commit 614c7c9 into Silo-Server:main Oct 21, 2026
16 checks passed
@macroscopeapp

macroscopeapp Bot commented Oct 21, 2026

Copy link
Copy Markdown

The PR now links to its evidence page, but the description does not identify which changed Home rows its captures and response excerpts cover. Please ensure the page shows before-and-after results for the fetcher-backed rows (For You, Recently Released, and Critically Acclaimed) and catalog discovery rows (Top Rated, Hidden Gems, and Forgotten Favorites), with matching API excerpts and desktop/phone-width Home captures.

Automated check: Macroscope check run agent (gpt-6-luna). Evidence was not reviewed for correctness.

Posted via Macroscope — Visible change evidence

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 priority: P2 Limited scope, workaround exists, or polish size/M 50–199 added + deleted lines (all files); change volume, not priority.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug] Home recommendation sections can return stale media items

2 participants