Skip to content

fix(sections): load rule rows that use the viewer's watch state - #3156

Merged
Quick104 merged 1 commit into
Silo-Server:mainfrom
Rhainland:fix/3143-section-rule-groups
Oct 29, 2026
Merged

Quick104 merged 1 commit into
Silo-Server:mainfrom
Rhainland:fix/3143-section-rule-groups

Conversation

@Rhainland

@Rhainland Rhainland commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Closes #3143
Related issue: N/A
Validation tasks: changes #1140 C1; changes #1142 C1

A Home or library row fails to load when its rules or sort depend on the viewer's state, such as "Watched is No", favorites, or plays. The items request returns HTTP 500 because the row query lacks the requesting account and profile. Catalog-only rules continue to work.

Approach

Pass the requesting account and profile to the existing rule query when the definition is personalized. These rows already bypass the shared cache. The same path fixes personal smart collections shown as rows when they have no display filter. Existing library, maturity, and collection-owner access restrictions are retained.

Native API and Jellyfin wire contracts do not change. Apple and Android receive the restored rows through their existing API calls; no client implementation change is required. The fix restores documented behavior, so no user-manual change is needed.

Validation

Verified on rebased head 28cfbe4614ed8c7bb3db0cb607eb3a24e4282659, against main 793b9fc15fa20d01b2b7a94597ddb9547e9382cc:

  • TestRuleRowsReadTheViewersWatchStatePostgres fails on main with the profile-scope error and passes on the PR. All internal/sections/... tests pass with a disposable PostgreSQL database.
  • On a live isolated deployment with the same synthetic library, the reported rule, a personal smart-collection row, and a plays-sorted row change from HTTP 500 to HTTP 200. The watched title is excluded for the primary profile and included for the second profile. The catalog-only control returns the same titles before and after.
  • go build ./..., go vet ./internal/sections/..., make lint-changed, router recovery lint, local-path checks, and case-collision checks pass.
  • The review's make test-go run fails in TestRunStatsWithRealFFmpeg and the fmp4/seek and mpegts/seek cases of TestCopyRemuxSubtitleRenditionRealFFmpeg. The same failures reproduce on clean main with the local FFmpeg. Database tests were run separately as described above.
  • Source review covers Apple/Android coordination and Jellyfin callers. Native and Jellyfin client runtime validation remains outstanding. Web unit/type checks were not rerun because no web source changed.
  • Validation cases Curated home sections — Server #1140 C1 and Curated home sections — Web #1142 C1 are affected and recorded as Not run. No passed case was identified as regressed; this review does not mark acceptance cases passed.

The branch was rebased to resolve an additive conflict in the database-contract test list, preserving every entry. The fetcher patch and regression test are unchanged.

Evidence

Before-and-after Home captures at desktop and phone widths use the same data. The evidence also includes build identities, personal smart-collection API results, profile isolation, and the catalog-only control. Before: 793b9fc1; after: 28cfbe46.

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

Risks and follow-up

An admin preview of a personalized row now evaluates the admin's own profile, where it previously failed.

A personal smart collection with a nonempty display filter still executes its base query without the viewer's profile. It fails on both main and this branch and is tracked in #3216. Its repair should follow this PR because it touches the same function.

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.
  • Desktop and phone-width web behavior is shown with the same data and identified builds.

AI Disclosure

  • Harness: Claude Code (via T3 Code); Codex CLI for code review
  • Tool(s): Claude Code; Codex CLI
  • Model(s): claude-opus-5-5; gpt-6.1-sol (code review)
  • Involvement: Fully AI-generated, human verified
  • Adversarial review: independent reviews by claude-opus-5-5 and gpt-6.1-sol of the full branch diff for correctness, repo standards, and the issue's expected behavior, then reconciled. GPT found nothing. Claude found one problem outside this change: a personal smart collection with a display filter still misses the viewer's profile. It was left for a follow-up and is listed under Risks. Claude also made a low-severity note that the new test lives in a file named for another behavior. That was kept, because the repo prefers adding to an existing file. Both confirmed that rows with personal rules never reach the shared cache.

Review update: Codex through T3 Code (gpt-6.1-sol) reviewed and verified the rebased head. An independent Claude Code review through T3 Code (claude-opus-5-5) checked caller identity, access constraints, cache isolation, and regression coverage. Neither found an introduced defect. The display-filter omission was reproduced on main and the PR and is tracked in #3216. The review changed only the additive test-list conflict during rebase; the implementation and regression test are unchanged. Human acceptance of validation cases is not claimed.

Note

Fix section rule rows to use viewer's watch state in sections.Fetcher.fetchFiltered

  • Rule rows with viewer-state filters (watched, favorited, progress) were evaluated without the requesting user, so they returned wrong results
  • fetchSection and fetchUserCollection now pass userID and profileID to fetchFiltered, which sets filter.UserID and filter.ProfileID only when def.IsPersonalized() is true
  • Adds a PostgreSQL test (TestRuleRowsReadTheViewersWatchStatePostgres) proving watched-state rules use the requesting profile's history; registered in db-contracts.txt
  • Risk: personalized rows bypass the shared cache per the new comment in fetcher.go; non-personalized definitions are unchanged

Macroscope summarized 6e549a9.

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

silo-kody Bot commented Oct 27, 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 27, 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: df832ab4-b074-4149-84e3-ca7ed6bf14d0
Commits

Reviewing files that changed from the base of the PR and between 62b1a6e and 6e549a9.

Files selected for processing: 3
  • internal/sections/fetcher.go
  • internal/sections/orphan_items_db_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; 3 remain after this review.

Walkthrough

Section fetching now passes user and profile identifiers to personalized custom filters. A PostgreSQL integration test checks that watch-state rules return different results for profiles. The test is also added to the database-contract test list.

Changes: Custom-rule section filtering

Layer / File(s) Summary
Pass identity into personalized filters
internal/sections/fetcher.go
The genre/custom-filter and smart user-collection paths pass user and profile identifiers to fetchFiltered. Personalized queries add these identifiers to the access filter. Other queries keep the incoming filter unchanged.
Verify profile-specific watch filtering
internal/sections/orphan_items_db_test.go, scripts/ci/db-contracts.txt
The PostgreSQL integration test checks that a viewer with one watched item receives only the unwatched item, while another profile receives both. The test is registered in the database-contract test list.

Priority: Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Suggested labels: bug, go, priority: P2, impact: usability, size/M

Suggested reviewers: quick104, blurbery

Merge Risk: Minimal · up to 6e549

The personalized row change is ready to merge after normal checks; no actionable merge-blocking risk remains.

Security architecture risk: Minimal · up to 6e549

Viewer-specific rows use the requesting account and profile while existing access restrictions remain in force. No material new security risk was identified in the reviewed change.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The newly successful queries affect section membership and ordering using the requesting account/profile's personal state, within the retained catalog access scope. The inspected flow does not grant another account's identity or replace library restrictions.

Trust Boundaries and Controls

  • observed — Section requests remain authenticated and require profile context. The changed path forwards that context-derived identity, rather than taking account identity from rule configuration, while query execution retains its personalized-definition validation.

Resilience and Maintainability Implications

  • inferred — The existing cache gate parses the same definition used for execution and rejects personalized or unparseable custom-filter configurations; user collections are also excluded. These requests execute outside shared-cache refresh and publication, and query failures return errors. Consequently, newly successful personalized results do not introduce a shared-result lifecycle requiring cross-profile cleanup or rollback.
Pre-merge checks: Passed 4
Check name Status Explanation
Title check Passed The title clearly and concisely describes the main change: loading rule rows that depend on the viewer's watch state.
Linked Issues check Passed Issue #3143 requires custom-rule Home sections to return items instead of HTTP 500. The fix is in internal/sections/fetcher.go. fetchSection and fetchUserCollection now pass userID and profileID to fe…
Out of Scope Changes check Passed All changed code connects to #3143 and the fix. The fetcher.go change adds the viewer scope only to the rule-row path (fetchFiltered and its callers). The fetchUserCollection change applies the same f…
Description check Passed The pull request description directly explains the fix for viewer-specific rule rows, the implementation approach, validation, risks, and scope. It matches the reported changes.
Full details: Linked Issues check

Explanation

Issue #3143 requires custom-rule Home sections to return items instead of HTTP 500. The fix is in internal/sections/fetcher.go. fetchSection and fetchUserCollection now pass userID and profileID to fetchFiltered. When def.IsPersonalized() is true, fetchFiltered sets filter.UserID and filter.ProfileID. The row query can then read the viewer's own state, so the personal rule no longer fails validation with 'field "watched" requires profile scope'. The new PostgreSQL test TestRuleRowsReadTheViewersWatchStatePostgres in internal/sections/orphan_items_db_test.go covers the reported two-group 'Watched is No' rule set. It checks that the viewer sees only the unwatched title and another profile sees both. The test is registered in scripts/ci/db-contracts.txt. Catalog-only rules do not take the personal path, and the PR reports they already return 200. Limitation: I did not read the IsPersonalized definition. Coverage of Favorited and plays-sort rules rests on the author's local before and after runs, not on code I inspected.

Full details: Out of Scope Changes check

Explanation

All changed code connects to #3143 and the fix. The fetcher.go change adds the viewer scope only to the rule-row path (fetchFiltered and its callers). The fetchUserCollection change applies the same fix to personal smart collections shown as rows, which the PR states is intended. The test in orphan_items_db_test.go verifies the fix. The db-contracts.txt line registers that test. No API, client, or jellycompat contract changes appear in the summary. The PR documents a personal smart collection with a display filter as a known gap and does not change it. Non-personalized definitions keep their existing filter scope. The test is in a file named for another behavior. The author records this as a low-severity naming issue, not a scope problem.

Finishing Touches
🧪 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 evidence-required Needs before-and-after evidence before the Evidence check passes go Pull requests that update go code impact: usability Core flow broken or severely blocked priority: P2 Limited scope, workaround exists, or polish labels Oct 27, 2026
@silo-triage

silo-triage Bot commented Oct 27, 2026

Copy link
Copy Markdown

The API excerpts show the row request recovering, but the Evidence section has no captures of the affected screens. CONTRIBUTING.md’s “Show visible changes” requires before-and-after captures when a change alters which items an existing client shows; API excerpts alone cover server changes no client shows yet. Please add same-data before-and-after captures of the affected row on web (desktop and phone width, or explain why mobile is unaffected) and the affected native client surfaces, naming the builds used.

@macroscopeapp

macroscopeapp Bot commented Oct 27, 2026

Copy link
Copy Markdown

Evidence covers rule-based home sections and sorting, but not the personal smart collection row path changed via fetchUserCollection; add before-and-after API response excerpts for the same personal smart collection row.

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

Posted via Macroscope — Visible change evidence

A Home or library row built from rules that use the viewer's own state
(Watched, Favorited, In progress, a plays or progress sort) failed with
500 Internal error: the filtered fetch never passed the requesting
profile to the query, so validation refused the rule.

Pass the account and profile into the filtered fetch when the rules
need them. Such rows already skip the shared cache, so the result stays
per profile. A personal smart collection shown as a row gets the same
fix.
@Quick104
Quick104 force-pushed the fix/3143-section-rule-groups branch from 6e549a9 to 28cfbe4 Compare October 28, 2026 18:06
@silo-kody

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

Copy link
Copy Markdown
Contributor

No introduced defects found at 28cfbe4614ed8c7bb3db0cb607eb3a24e4282659.

Fit: 10/10 · Readiness: 8/10 — conditional

The fix restores personalized rows at the existing query boundary. It retains access constraints and the existing shared-cache exclusion. API contracts stay the same. Readiness remains conditional on the native before-and-after evidence required by CONTRIBUTING.md; native clients were not exercised in this review.

GitHub CI is green on the reviewed head. All 16 checks completed with success, neutral, or skipped conclusions. GitHub reports the branch as mergeable, and no new review findings were posted.

Verification

  • The PostgreSQL regression fails on main 793b9fc1 with field "watched" requires profile scope and passes on this head. All sections package tests pass with PostgreSQL.
  • Live before/after requests and desktop/phone web captures show the reported rule and personal smart-collection row recovering from 500 to 200. The primary profile excludes its watched title; the second profile includes it. Plays sorting works, and the catalog-only control is identical.
  • Build, sections vet, changed-line lint, router recovery lint, local-path checks, and case-collision checks pass. The full Go suite fails in TestRunStatsWithRealFFmpeg and the two seek cases of TestCopyRemuxSubtitleRenditionRealFFmpeg; the same failures reproduce on clean main with the local FFmpeg.

Remaining issue: #3216 tracks the disclosed smart-collection display-filter failure, reproduced on both main and this head. It is separate from this PR and should follow it because it changes the same function.

Validated features: #1140 C1 and #1142 C1 are affected; both remain recorded as Not run. No passed case was identified as regressed, and no board result was changed. Related Apple/Android cases remain unverified by this run.

Clients and manual: Apple/Android contracts and Jellyfin callers were checked from source. Existing clients receive the fix without a contract update; native and Jellyfin runtime behavior was not tested. The user-manual check found no change needed because this restores documented behavior.

The branch was rebased with a lease to resolve the additive database-test-list conflict. Every registration was preserved; the implementation and regression test are unchanged. The PR body now links the web evidence and includes the smart-collection API comparison requested in the bot feedback.

Note

AI-assisted review posted as Quick104 using Codex through T3 Code (gpt-6.1-sol). Independent review used Claude Code through T3 Code (claude-opus-5-5) to check identity propagation, access constraints, cache isolation, and regression coverage. Neither review found an introduced defect. Live checks and test results above were executed; human acceptance and native-device validation are not claimed.

@Quick104
Quick104 merged commit 3aae488 into Silo-Server:main Oct 29, 2026
16 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 evidence-required Needs before-and-after evidence before the Evidence check passes go Pull requests that update go code impact: usability Core flow broken or severely blocked 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] : Sections with custom rules not working

2 participants