Skip to content

feat(access): let a profile hide titles with no advisory age - #1441

Merged
Quick104 merged 1 commit into
mainfrom
t3code/advisory-age-strict
Sep 25, 2026
Merged

Quick104 merged 1 commit into
mainfrom
t3code/advisory-age-strict

Conversation

@Quick104

Copy link
Copy Markdown
Contributor

Problem

The advisory-age limit from #1429 fails open. A title with no advisory age passes it, and the content-rating ceiling alone decides that title.

That default is deliberate. Advisory ages come from a rate-limited provider (1,000 lookups a day on MDBList's free tier), so right after a library enables it almost no title has one. A limit that hid every unrated title would empty the library. But it leaves the limit weak for a young child. Until lookups finish, it restricts nothing on its own. And titles no advisory service covers are never limited by it at all. A parent who wants a profile to see only titles an advisory service has vetted can't express that today.

Solution

A profile can set require_advisory_age. With a limit set, a title with no advisory age is hidden too, so the profile sees only titles rated at or under the limit. The web editor shows it as a switch under Maximum advisory age: "Hide titles without an advisory age".

  • Per profile. One household can want this for a 6-year-old and not a 15-year-old.
  • Off by default. Every existing profile keeps today's behavior.
  • Needs a limit. Without max_advisory_age it does nothing. Both resolvers fold it to false, so a stored flag with no limit changes no predicate, cache key or cursor digest. The web editor also clears it when the limit is removed, so a later limit doesn't come back strict without warning.
  • Both advisory sources count, as they do for the limit itself.
  • Same reach as the limit. The predicate goes through ApplyMaturityLimits, so it applies to browse, search, detail, episodes, sections, progress, recommendations and jellycompat.
  • Same authority as the limit. Only a household manager can set or clear it, a restricted profile can't change its own, and changing it bumps access_policy_revision.
  • Not in the scope policy. Both resolvers read the flag straight from the profile, the way AllowUnratedContent comes from the server setting. It only ever hides more, so no override needs to loosen it. It applies to whatever limit the policy settles on, including one an override lowered.

Index

The strict predicate is at its most selective right after a library enables the provider, when almost no title has an age. A browse sorted by title then walks the whole sort index for matches that barely exist and falls back to a full scan. The migration adds partial indexes on media_items and episode_catalog_entries over rows that have an age.

Measured on 150,000 titles:

Titles with an age With the index Without
5 5 ms (bitmap scan on the new index) 46 ms (parallel sequential scan)
4,545 1.8 ms (planner uses the type, sort_title index) 1.0 ms (same plan)

The indexes hold only rows that have an age, so they stay small. The lenient predicate can't use them and doesn't need to.

Contract

  • v1 is frozen. The field rides the shared Go structs with json:"-". A test checks that a v1 body can neither set it nor read it back.
  • v2 profiles. Profile.require_advisory_age is a boolean, always present. createProfile and updateProfile take it as optional, and null is rejected because it isn't a clearing member.
  • Feature detection. listProfiles returns require_advisory_age_supported. It's separate from max_advisory_age_supported because a server can support the limit without this. The profile operations reject unknown members, so clients must check the flag before sending the field.
  • The OpenAPI diff is 7 changes, all additive.

Validation

  • Catalog DB test. The existing advisory-limit test now runs a strict pass over the same fixture and reads: FilterAccessibleContentIDs, EnsureAccessible, browse, BrowseEpisodes, mixed search, the episode_catalog_entries read model, and ANDing with the ceiling. Under a strict limit of 12 only the title rated 10 survives. I also disabled the strict predicate on purpose, and all seven strict subtests failed.
  • Unit tests cover:
    • the SQL predicate;
    • HidesUnadvised;
    • the cursor digest;
    • both resolvers, which must agree, including folding the flag without a limit;
    • v2 set, omit and invalid-value handling;
    • handler authorization and the v1 wire;
    • both profile stores, including the revision bump in Postgres;
    • the SQLite v28 migration;
    • the web draft, request and summary logic and the editor switch.
  • Migration applies, rolls back (column and both indexes removed) and re-applies with no invalid index.
  • Gates. The full pre-PR gate from CONTRIBUTING.md passes, including make test-db-pins (20/20) and the web suite (5,175/5,175). Three DB-backed tests fail against the shared test database, and they fail the same way on main: TestOrphanCleanupAfterPlexTableDropPostgres, TestAdminSubtitleListPageDB and TestCatalogTransferPersistsJobsAndSignedLink. This branch touches none of their files.
  • By hand, on an isolated sandbox with 32 movies, two of them with advisory ages (10 and 16), and a kid profile with a limit of 12:
    • Lenient: the profile saw 31 movies, and an unrated movie opened normally.
    • I turned the switch on through the web editor. The profile summary changed to "Advisory age 12 max, rated titles only", and the server stored the flag.
    • Strict: the profile saw 1 movie, the one rated 10, and the unrated movie returned 404.
    • After a reload the editor showed the switch on, read back from the server. No console errors in the editor flow.

Risks

  • A strict profile starts nearly empty. On a library that hasn't been looked up yet, it sees almost nothing and fills in as lookups finish, the opposite of the default, where titles disappear as ages arrive. The switch's help text says so, and the docs describe both behaviors.
  • The editor doesn't show coverage. advisory_titles from the admin dashboard would explain an empty strict profile, but it's admin-only and a household manager usually isn't a server admin. Showing it in the editor needs a new endpoint, left for later.
  • The SQLite profile store doesn't bump access_policy_revision for this flag. It never has for any access field, including the limit from feat(access): limit a profile by advisory age #1429, so this matches existing behavior. The default Postgres store bumps it.

Follow-up

  • silo-apple and silo-android: a switch gated on require_advisory_age_supported, and make apiv2-fixtures-sync for the moved profile fixtures. I'll add this to silo-apple#416 and silo-android#375.
  • storetest.RunSuite isn't called by any test, so the profile-store assertions in it, including feat(access): limit a profile by advisory age #1429's, have never run. Its Progress section fails on SQLite today. This PR adds direct store tests instead. Wiring the suite in is separate work.

Related issue: N/A
Validation tasks: reaches #1180 C2, #1181 C1 and C4, #1250 C4, #1246 C2. Profiles without require_advisory_age behave as before; this adds an opt-in restriction and changes no passed case.

AI disclosure

Written by Claude Opus 5.5 (model identifier claude-opus-5-5[1m]) running in Claude Code as the agent harness, driven interactively by the maintainer. No other AI tooling was used. The maintainer chose to make the option per profile and to count every advisory source.

🤖 Generated with Claude Code

A profile's advisory-age limit from #1429 fails open: a title with no
advisory age passes, and the content-rating ceiling alone decides it. That
keeps the limit from emptying a library the provider has not reached yet, but
it makes the limit weak for a young child. Until lookups finish, it restricts
nothing on its own, and titles no advisory service covers are never limited
by it at all.

A profile can now set require_advisory_age. With a limit set, a title with no
advisory age is hidden too, so the profile sees only titles rated at or under
the limit. It is per profile because one household can want this for a young
child and not a teenager. Both advisory sources count. It defaults off, so
every existing profile keeps today's behavior, and it has no effect without a
limit: the resolvers fold it to false, so a stored flag with no limit changes
no predicate, cache key or cursor digest.

The predicate goes through ApplyMaturityLimits, so it reaches every read the
limit already covers. The flag comes straight from the profile in both
resolvers, the way AllowUnratedContent comes from the server setting, rather
than through the scope policy: it only ever hides more, so no override needs
to loosen it. Changing it bumps the access policy revision like the limit.

A strict profile's predicate is most selective right after a library enables
the provider, when almost no title has an age. A browse sorted by title then
falls back to a full scan, so the migration adds partial indexes over rows
that have an age. On 150,000 titles with 5 rated, that took the query from
46 ms to 5 ms. With dense coverage the planner uses the sort index instead.

/api/v1 stays frozen. v2 profiles gain require_advisory_age and
listProfiles reports require_advisory_age_supported, separate from
max_advisory_age_supported because a server can support the limit without
this. The web profile editor shows the switch once a limit is set and sends
the field only to a server that reports support.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@coderabbitai

coderabbitai Bot commented Sep 25, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

Next included review available in 17 minutes.

Check out review usage here.

View limit details

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

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Advanced

Run ID: ebe701ac-4eb2-4fef-8bba-3fc331637380

📥 Commits

Reviewing files that changed from the base of the PR and between 6d55cdf and f613ae8.

📒 Files selected for processing (42)
  • contracts/api/v2/fixtures/create_profile_created.json
  • contracts/api/v2/fixtures/get_system_info_ok.json
  • contracts/api/v2/fixtures/list_profiles_ok.json
  • contracts/api/v2/fixtures/update_profile_ok.json
  • contracts/api/v2/fixtures/upload_profile_avatar_ok.json
  • contracts/api/v2/openapi.json
  • docs/catalog-api.md
  • docs/settings-api.md
  • internal/access/resolver.go
  • internal/access/types.go
  • internal/access/types_test.go
  • internal/api/handlers/profiles.go
  • internal/api/handlers/profiles_advisory_age_test.go
  • internal/apiv2/cursor.go
  • internal/apiv2/cursor_scope_digest_test.go
  • internal/apiv2/profiles.go
  • internal/apiv2/profiles_test.go
  • internal/catalog/access_cache_key.go
  • internal/catalog/access_filter.go
  • internal/catalog/advisory_age_limit_db_test.go
  • internal/policy/viewer_resolver.go
  • internal/policy/viewer_resolver_test.go
  • internal/recommendations/engine.go
  • internal/userdb/migrate.go
  • internal/userdb/migrate_v28_test.go
  • internal/userdb/profile_require_advisory_test.go
  • internal/userdb/profiles.go
  • internal/userdb/schema.go
  • internal/userstore/pgstore/profile_advisory_age_test.go
  • internal/userstore/pgstore/profiles.go
  • internal/userstore/types.go
  • migrations/sql/20260925025333_profile_require_advisory_age.sql
  • web/src/api/types.ts
  • web/src/api/v2/schema.ts
  • web/src/components/profiles/ProfileEditorDialog.test.tsx
  • web/src/components/profiles/ProfileEditorDialog.tsx
  • web/src/hooks/queries/profiles.ts
  • web/src/lib/profile-management.test.ts
  • web/src/lib/profile-management.ts
  • web/src/pages/HouseholdSetup.tsx
  • web/src/pages/Profiles.tsx
  • web/src/pages/settings/ProfilesSettings.tsx

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 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Quick104 has reached the 50-credit limit for trial accounts. To continue receiving code reviews, upgrade your plan.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 25, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-25T03:49:34.943887Z f613ae8 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@Quick104
Quick104 merged commit 1aa1eb2 into main Sep 25, 2026
11 checks passed
@Quick104
Quick104 deleted the t3code/advisory-age-strict branch September 25, 2026 03:50
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.

1 participant