Skip to content

fix(collections): fill an import's item limit with titles its owner can access - #1874

Merged
Quick104 merged 7 commits into
feat/collections-revampfrom
fix/personal-import-owner-access
Oct 4, 2026
Merged

Quick104 merged 7 commits into
feat/collections-revampfrom
fix/personal-import-owner-access

Conversation

@Quick104

@Quick104 Quick104 commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Related issue: #1615, #1612
Validation tasks: unblocks #193 S7

When a profile with content restrictions imports a personal collection from MDBList, TMDB or Trakt with an item limit, the sync fills the limit with the first titles on the list that the server has, whether or not that profile can open them. The profile then sees only a few of them, and later titles on the list that it could open are never reached. The sync summary ("Matched X of Y entries") also counts titles outside the profile's access, which tells a restricted profile how many of those the server has. This change limits an import's members to titles its owner profile can access, so the limit fills with titles the owner can open and the summary counts only those.

This is the import side of #1615's rule that a personal collection carries its owner's limits. It builds on the change this pull request is stacked on, which limits what other profiles see in a shared collection to what its owner can access.

Approach

  • Each sync resolves the owner profile's access the same way reads of a shared collection do: the owner's libraries and rating limit. Per the maintainer's decision on Personal collections: owner-only management and a single share-with-all-profiles switch #1615, libraries the owner hides from its own browsing still count as access. If the import names libraries, both limits apply.
  • The sync matches the fetched source list against the catalog, checks every match against the owner's access in one query, then walks the list in source order until the limit is full. A title outside the owner's access counts as unmatched, the same as a title the server doesn't have.
  • A scheduled sync has no request, so the owner comes from the collection's creator profile. cmd/silo/main.go builds the resolver next to the sync service, before the task manager starts scheduled syncs, with the same resolver choice the router makes. Nothing is cached between syncs, so the next scheduled or manual sync on any node follows a change to the owner's access. Existing imports change at their next sync.
  • It fails closed. If the owner's access can't be resolved, the sync stops before fetching the source, records a failed status and message on the collection, keeps the current members and logs an error. A manual sync answers the existing 500 "Sync failed: ..." response. The sync never falls back to the whole catalog.
  • The /api/v2 description of library_ids on the four import request schemas now says the owner's access limits it. Only the description changes; openapi.json, the web types and the system-info fixture digest are regenerated.

Validation

  • Go build, gofmt, go vet ./... and make lint-changed against the base branch: clean.
  • make test-go: pass.
  • DB-backed tests on a freshly migrated PostgreSQL database for usercollections, api, api/handlers, apiv2 and cmd/silo: pass, except TestAdminSubtitleListPageDB and TestCatalogTransferPersistsJobsAndSignedLink, which fail the same way on the base branch (timezone comparisons). The usercollections DB tests also pass under -race.
  • The new DB test uses the production policy resolver and runs the scheduled sync path over a TMDB list with a limit. It covers an owner limited by library and by rating, the next sync after the owner's access widens, a library the owner hides from its own browsing, and chosen libraries combined with the owner's access. It fails if the owner's access check is removed. Unit tests cover a resolver error, a missing resolver and a collection without an owner profile: the source isn't fetched, the members stay and the failed status is recorded.
  • make test-db-pins: every pin passes. No pin was added.
  • Contract and generated artifacts: verify-apiv2-openapi, verify-apiv2-contract (no change against the base or feat/collections-revamp), verify-apiv2-fixtures, verify-apiv2-web-types, TestCommittedArtifactMatchesRouter, verify-route-inventory, verify-migration-ledger, verify-scenario-catalogs, verify-offline-routes, verify-settings-bindings-all, verify-playback-fixtures and verify-local-paths: pass.
  • Web, where only comments in the generated types change: pnpm run lint (no errors), format:check, build, budget:check and make test-web: pass.
  • Not run: nobody has synced a real MDBList, TMDB or Trakt list on a running server or walked Collections — Web #195 W3; the tests use stubbed sources. No test covers the resolver wiring in main.go.

Risks

  • Migration: none.
  • Compatibility:
    • The /api/v2 schema is unchanged apart from one field description. Shipped Apple and Android builds need no update.
    • /api/v1 and /api/v2 share the import and sync handlers, so imports created or synced through either change the same way.
    • At its next sync, an import owned by a restricted profile drops members outside the owner's access and fills the limit from later entries. Its item_count and sync summary change with it.
    • No Jellyfin-compatible route exposes personal collections.
  • Security: an import's stored members stay within its owner's access, and the summary no longer counts titles outside it. Each viewer's own access still applies on read. As decided on Personal collections: owner-only management and a single share-with-all-profiles switch #1615, titles from a library the owner hides from its own browsing can fill the limit; profiles that can access that library see them, and the owner doesn't.
  • Operational:
    • A sync with a limit now checks every matched title from the fetched list (at most 500 entries) in one query instead of stopping at the limit, and resolving the owner adds a few queries per sync. Neither cost was measured.
    • If owner resolution fails, for example during a database fault, imports record a failed sync and keep their members until it recovers.
    • If the main.go wiring were lost, every import sync would fail the same visible way. No test catches that.

Checklist

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

AI Disclosure

  • Harness: Claude Code (in T3 Code)
  • Tool(s): Claude Code subagents (implementer, independent reviewer)
  • Model(s): claude-opus-5-5[1m]
  • Involvement: Fully AI-generated, human review pending
  • Adversarial review: an independent reviewer agent checked the diff against the Personal collections: owner-only management and a single share-with-all-profiles switch #1615 implementation plan and Personal collection imports fill the item limit with titles the creator can't see #1612. It traced every caller of the sync service, checked owner access with both resolvers, ran the unit and DB tests, and tested by mutation. It reported two minor issues and two nits:
    • Fixed: the /api/v2 description of library_ids on the import request schemas still said "every library when omitted". It now names the owner's access, and the generated artifacts are regenerated.
    • Fixed: two Trakt sync failure messages had been reworded to satisfy a lint rule. They can be stored as a collection's sync message, so the original wording is back with a targeted lint exception.
    • Left as is: no test covers the resolver wiring in main.go. Losing it fails closed (see Risks).
    • Changed in this description: the reviewer asked for Closes #1612. This pull request targets an integration branch, so it lists Personal collection imports fill the item limit with titles the creator can't see #1612 as related; the merge into main needs to close it.

🤖 Generated with Claude Code

Note

Fill personal collection import item limits with owner-accessible titles

Wires an owner-access resolver into the personal collection sync service in main.go. When the policy system is available, it uses the policy viewer resolver with the configured unrated-content policy; otherwise it falls back to the legacy access resolver. The resolver is wrapped in a personal-collection access wrapper when the sync service is constructed. Behavioral Change: collection imports and scheduled syncs now filter titles by the owner's access profile instead of the previous resolver behavior.

Macroscope summarized 3071a8a.

Quick104 and others added 3 commits October 3, 2026 20:03
…an access

A restricted profile's imported collection used its item limit on titles
it couldn't see, and its sync summary counted them, so the collection
stayed mostly empty and the summary revealed how many hidden titles the
server holds. Sync now checks every matched title against the owner
profile's access (allowed libraries and maturity limits, not its hidden
libraries) before the limit applies, and counts titles outside that
access as unmatched. The next sync follows the owner's current access.

Scheduled syncs have no request, so the sync service resolves the owner
with the same resolver as the request gates. It is wired in main.go
before the task manager starts. If the owner's access can't be resolved,
the sync records a failed status with a clear message and leaves the
members as they were; it never falls back to the whole catalog.

Related #1612

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…'s access

Imports now match only titles the collection's owner can access, so the
library_ids description no longer said what an omitted or chosen list
does. Description-only change; the regenerated contract digest moves the
system info fixture.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
The sync refactor reworded two messages to satisfy ST1005. They are stored
as a collection's sync status and returned to clients, so keep the wording
users saw before and that library collections still use.

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

coderabbitai Bot commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 76ead61f-e528-490c-9a2d-37156bc1f900

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
  • Autopilot · 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.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 4, 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-10-04T06:10:54.777972Z 3071a8a New commits
ℹ️ 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.

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 424528ae6a

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

IsShared *bool `json:"is_shared,omitempty" nullable:"false" example:"false"`
PosterURL *string `json:"poster_url,omitempty" nullable:"false" doc:"A bundled template poster path or an image URL" example:""`
LibraryIDs *[]ID `json:"library_ids,omitempty" nullable:"false" doc:"Libraries the sync matches against; every library when omitted" example:"[\"1\"]"`
LibraryIDs *[]ID `json:"library_ids,omitempty" nullable:"false" doc:"Libraries the sync matches against, limited to the libraries the collection's owner can access; every library the owner can access when omitted" example:"[\"1\"]"`

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Update the catalog API guide for owner-limited imports

This changes client-visible collection membership, item-limit, and sync-summary behavior, but only the generated OpenAPI description was updated; the collection import section in docs/catalog-api.md still does not document that imports are restricted by the owner's access. Update that API guide so the durable contract documentation matches the new behavior.

AGENTS.md reference: AGENTS.md:L146-L154

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added a "Personal collection imports" section to docs/catalog-api.md (2e8822b, 4338412): imports keep only titles the owner can access, library_ids are limited to the owner's access, summaries count only accessible titles, and a sync whose owner access can't be resolved fails visibly and keeps existing members.

Quick104 and others added 3 commits October 4, 2026 00:43
…r's access

Imports now fill their item limit only with titles the collection's owner
can access, and sync summaries and library_ids follow that access, but the
API guide still described the old behavior. Record the owner-access rule,
the hidden-library exception, and the failed-sync behavior that keeps
existing members.

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

Collection reads report item_count as the members the reading profile can
see, so it can differ from items_matched; only the stored count returned
with the import matches it. The owner limits now name access.unrated_content
and require_advisory_age, and the section notes the bounded source window
and that entries outside library_ids count as unmatched.

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

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: cb8563b0bf

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread internal/usercollections/sync.go Outdated
Comment on lines +313 to +314
if len(cfg.LibraryIDs) > 0 && s.libraryItems != nil {
inLibraries, err := s.libraryItems.GetItemsInFolders(ctx, ids, cfg.LibraryIDs)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Intersect selected libraries with the owner's allowlist

When an owner can access library A, library_ids selects inaccessible library B, and a title belongs to both, these two independent title-level checks retain it: EnsureAccessibleIDs succeeds through A while GetItemsInFolders succeeds through B. This violates the documented rule that selected libraries are limited to the owner's access and can occur after access restrictions change even if the original selection was valid. Intersect cfg.LibraryIDs with owner.AllowedLibraryIDs before checking membership so a title must belong to a library that is both selected and owner-accessible.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 3071a8a. The chosen library_ids are narrowed to the owner's allowed libraries before GetItemsInFolders, so a title must sit in a library that is both chosen and owner-accessible. A new DB subtest puts a title in both libraries, allows the owner only the first and chooses only the second; it was imported before the fix and isn't now.

@macroscopeapp

macroscopeapp Bot commented Oct 4, 2026

Copy link
Copy Markdown

This PR adds the missing owner-access filtering for imported collections in the #1615 stack. Collections #193 S7 (Server/API) and #195 W7 (Web browser) are both recorded as “Not run: needs #1615”; once this stack is available, re-test owner/viewer-limited membership and counts, including imported collections. Do not treat these cases as passed. #195 W3 is already listed for the #1612 finding and has no recorded result to invalidate.

The current Validation tasks: line omits S7 and W7. Suggested replacement:

Validation tasks: changes #195 W3; unblocks #193 S7; unblocks #195 W7

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

Posted via Macroscope — v1 validation impact

@macroscopeapp

macroscopeapp Bot commented Oct 4, 2026

Copy link
Copy Markdown

#193 S7 is currently not run because it needs #1615. This PR adds the owner-scoped import/scheduled-sync path, so S7 is ready for human re-test after the stacked owner-access branch merges; it is not passed.

The current Validation tasks: changes #195 W3 entry is not aligned with W3's stated steps, which cover the manual picker/add and collection-link read paths, not import/sync. #1612 is a non-blocking related finding. Please replace the line with:

Validation tasks: unblocks #193 S7

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

Posted via Macroscope — v1 validation impact

Base automatically changed from feat/personal-collections-owner-access to feat/collections-revamp October 4, 2026 06:03
…ccess

An import kept a title when the owner could reach it through one library
and the collection's chosen libraries included it through another, so a
chosen library the owner can't access still added titles. The chosen
libraries are now narrowed to the owner's allowed libraries before the
membership check.

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

Quick104 commented Oct 4, 2026

Copy link
Copy Markdown
Contributor Author

Validation line updated to unblocks #193 S7, per the later check: W3 covers the manual picker and collection-link reads, not import or sync.

@Quick104
Quick104 merged commit 4d08203 into feat/collections-revamp Oct 4, 2026
14 checks passed
@Quick104
Quick104 deleted the fix/personal-import-owner-access branch October 4, 2026 06:21
Quick104 added a commit that referenced this pull request Oct 4, 2026
Brings in login-wide personal collection sharing (#1875), the scrobble
lock fix (#1887), and the import owner-access fix (#1874).

Conflict resolution keeps both sides: the capabilities test expects
login_sharing and create_description, the fixture list keeps
collection_order_foreign_id before this branch's appended cases, and the
create-description DB test no longer sets the removed AllowedProfileIDs.
The OpenAPI document, fixtures, and web types are regenerated.

Co-Authored-By: Claude Opus 5.5 (1M context) <[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.

1 participant