Skip to content

fix(collections): keep smart collection rules and limits when editing - #1851

Merged
Quick104 merged 6 commits into
feat/collections-revampfrom
fix/smart-collection-rules
Oct 4, 2026
Merged

Quick104 merged 6 commits into
feat/collections-revampfrom
fix/smart-collection-rules

Conversation

@Quick104

@Quick104 Quick104 commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Related issue: #192
Validation tasks: changes #194 A2, #195 W4, #1252 C1, #1256 C1, and the #199 Browse criterion

When someone edits a smart collection in the web app, the editor can quietly change what the collection contains: it caps the item limit and drops rules it can't display. This affects admins editing server collections and users editing their own. The catalog and library browse filters share the same code and lose rules the same way. With this change, a save keeps the stored rules and limit unless the person edits them.

The browse change is deliberate. On the catalog and library browse pages (#1252 C1, #1256 C1, #199 Browse), a toolbar sort or media change used to drop any filter the Guided view can't show, without telling the viewer. It now keeps those filters, and the filter sheet opens them in Advanced. Sorting and filtering otherwise work as before, and the cases' criteria are unchanged, so #1252 C1 (recorded in a rehearsal on an earlier build) and #1256 C1 need a re-test after merge.

  • The editors defaulted a missing item limit to 100 and capped every limit at 500. The server has left smart collections uncapped since feat(catalog): remove smart collection item limit cap #340, and it stores 10,000,000 when no limit is set. Opening and saving any uncapped collection therefore cut it to 500, and a new collection from the web got 100.
  • The Guided view rebuilds the whole definition from its own form. A toolbar sort or media change, or any edit in Guided, dropped the rules Guided can't show: "is not" rules, OR groups, watchlist rules, and a second actor or director rule. The Filters count also left those rules out.
  • The wizard disabled "Next: Details" when the rules matched nothing, so a smart collection with no matches couldn't be renamed or saved. Validation expects an empty rule result to be usable.
  • The Advanced view's Media Scope had no "Movies & Series" or "Manga" option, so collections with those scopes showed a blank scope.

Approach

  • Max items: a blank field means no limit. On load, a missing limit and the server's exact 10,000,000 default show as blank; an explicit limit above it is kept. A save leaves out a blank limit, and the server applies its default. Any other positive limit passes through unchanged. The web no longer sets a maximum; the server only requires a limit above 0. Entering 0 or a negative number keeps the current limit.
  • Rules Guided can't show: before showing a definition in Guided, the web runs it through Guided's parse and rebuild and checks that nothing changed. The check ignores rule and group order. It treats a genre "contains" rule as "is", because the server runs the same query for both on genres. It also compares numbers as text, because the catalog URL reads "7.5" back as a string. If the check fails, the collection editor and the catalog filter sheet open in Advanced with Guided disabled and the note "These rules use options the Guided view can't show." They stay in Advanced after the rules are fixed, so the view doesn't jump in the middle of an edit.
  • Toolbar: sort and media changes set only the sort and media scope and leave the rules alone. The one exception: switching to Ebooks removes narrator rules, which the server rejects for ebooks. Removing a badge and Clear All still go through Guided. That is safe, because badges appear only when Guided can show every rule. When it can't, the Filters count is the number of rules and no badges show.
  • Wizard: "Next: Details" is disabled only when an admin hasn't picked a library. The "No titles match these filters yet." message stays.
  • Advanced Media Scope lists Movies & Series and Manga. The Guided editor and the toolbar each had a copy of the mapping from media scope to sort options. The Advanced editor now needs it too, so all three share one helper.

Validation

  • Web unit tests (Vitest): new tests cover load-then-save round trips in the admin editor, the user editor and the wizard, for a missing limit, the 10,000,000 default, an explicit 250, and (in the helper's tests) an explicit 20,000,000. They also cover rules Guided can't show surviving a toolbar sort or media change and an unchanged save, filters sent through the catalog URL round trip, the Guided/Advanced switch and Filters count, and a no-match collection continuing to Details and saving. On the base branch the new tests fail for the bugs they target; the explicit-250 cases already passed there. The full web suite passes with the make test-web exclusions.
  • Web build and style: pnpm run lint reports no errors, and the warnings in changed files predate this branch. pnpm run format:check and pnpm run build pass, and pnpm run budget:check is within budget.
  • Generated code and docs hygiene: make verify-apiv2-web-types, make verify-settings-bindings-web and make verify-local-paths pass.
  • Manual: the siloserver.org collection pages say to "set an item limit if needed" and that a rule matching nothing makes an empty collection. Both remain accurate, so no manual issue is needed.
  • Not run: Go build, lint and tests, DB-backed tests and the API contract checks. This branch changes no Go, /api/v2 or OpenAPI files. There is no page-level Catalog test, because Catalog.test.tsx is on the known-failure list. No one has walked Collections — Web admin #194 A2, Collections — Web #195 W4 or the browse filters in a running app.

Risks

  • Collections that earlier web saves cut to 100 or 500 keep that limit. The limit is stored as an explicit number, and explicit limits now pass through. To lift it, someone has to clear Max items. The web can't tell a truncated 500 from one an admin chose.
  • A toolbar media change now keeps every rule except narrator rules on a switch to Ebooks. A rule Guided can't show under the new scope used to disappear silently; now it stays, and the filter sheet opens in Advanced.
  • The Guided check compares the exact form of each rule. Some definitions that mean the same thing still open in Advanced, such as a year "between" rule or an older catalog URL that puts each filter in its own group. Nothing in the web app produces those today. Merging groups to accept them would change results, because the server matches technical rules in one group against the same file.
  • On the Catalog page, once the filter sheet moves to Advanced, it opens in Advanced for the rest of the visit, even after the URL changes to rules Guided can show. The Guided button is enabled again by then.
  • Not changed here: the wizard's preview and match count still use only the first selected library. The count can read 0 for a collection whose matches are in another library. That no longer blocks "Next: Details".
  • No API change, so the Apple and Android clients and the Jellyfin-compatible API are unaffected.

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: one independent reviewer agent read the diff, ran the type check, lint, format check and focused tests, and ran the new tests against the base code, where they fail. It found one major issue. The Guided check compared value types, so on the Catalog page, where filters go through the URL, typing an IMDb minimum of 7.5 moved the sheet to Advanced and hid the badges. That was fixed by comparing numbers as text, with tests that send filters through the URL round trip. One minor issue: a toolbar switch to Ebooks kept narrator rules the server rejects. Narrator rules are now removed on that switch only. After the PR opened, an automated review found that limits above 10,000,000 were also cleared, although the server honors any explicit positive limit; only the exact default is cleared now. Two nits, both fixed: entering 0 or a negative number in Max items cleared the limit (it now keeps the current one), and countActiveFilters had no callers left (removed).

🤖 Generated with Claude Code

Note

Fix smart collection editing to preserve advanced rules and remove the 500-item limit cap

  • Editing toolbar sort or media scope in the catalog panel and wizard no longer discards advanced query rules; updates patch the query definition directly instead of rebuilding through Guided state (CatalogFiltersPanel.tsx)
  • Adds isGuidedRepresentable in guidedRepresentable.ts. It detects query definitions Guided cannot losslessly edit, opens them in Advanced, disables the Guided toggle, and shows a shared unavailable message
  • Smart collection limits are now blank-by-default. Blank removes the limit, positive values above 500 are accepted, and only the server no-limit sentinel (10,000,000) and non-positive values are stripped via normalizeSmartCollectionLimit in smartCollectionLimits.ts
  • Adds Movies & Series (video) and Manga media-scope options to the advanced rules editor, with sort normalization via the shared querySortScopeForMediaScope helper in querySortOptions.ts
  • The wizard no longer disables Next when a preview has zero matching items
  • Behavioral Change: smart collections no longer get a default limit or a 500-item cap; saved limits above 500 and previously-capped values now persist. Check createCollectionBuilderValue in CollectionBuilder.tsx and the wizard's query-change handler in SmartCollectionWizard.tsx, which no longer re-normalizes limits on every query edit

Macroscope summarized d050797.

Quick104 and others added 5 commits October 3, 2026 18:28
The web editors rewrote saved smart collections without saying so. They
defaulted the item limit to 100 and capped it at 500, although the server
has left smart collections uncapped since #340 and stores a 10,000,000
sentinel for "no limit", so saving any uncapped collection cut it to 500.
The Guided view rebuilds the definition from its own form state, so a
toolbar sort or media change, or any Guided edit, dropped the rules it
cannot show: negated rules, OR groups, repeated actor or director rules.

A blank Max items field now means no limit and is left out on save, and
an explicit limit passes through unchanged. A definition that Guided
cannot reproduce opens in Advanced with Guided switched off and a short
note, the toolbar changes only the sort and media scope, and the Filters
count includes every rule. The wizard lets a collection with no matches
continue to Details, and the Advanced Media Scope lists Movies & Series
and Manga. Collections that earlier saves already truncated stay
truncated.

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

The Catalog page rebuilds its filters from the URL on every change, and the
URL reads a decimal such as 7.5 back as text and a number-like value such as
the genre 1917 as a number. The Guided check compared value types, so typing
an IMDb minimum of 7.5 flipped the Filters sheet to Advanced, disabled Guided
and hid the badges. Compare numbers as text so a type change alone no longer
counts as a rule Guided can't show.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Toolbar media changes now patch the definition instead of rebuilding it
through Guided, which also stopped removing narrator rules on a scope
change. The server rejects narrator rules for the ebook scope, so switching
an audiobook view with a narrator filter to Ebooks returned an error. Remove
narrator rules, and any group they leave empty, only on that switch; every
other rule stays.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Entering 0 or a negative number in Max items cleared the limit, which made
the collection uncapped without saying so. Only a blank field means no
limit now; any other entry that isn't a positive number keeps the current
limit.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
The Filters button count now comes from the badges or the rules, so
nothing calls countActiveFilters.

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

coderabbitai Bot commented Oct 3, 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: 2726ffe0-23fa-4ef8-afb0-75feb17e8545

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 3, 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-03T22:52:53.452677Z d050797 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.

@macroscopeapp

macroscopeapp Bot commented Oct 3, 2026 •

Copy link
Copy Markdown

Major change — #1252 C1 (Series — Web, build 4a0cff41f): The 2 October rehearsal records that sort and filters were exercised on the shared browse path. This PR changes CatalogFiltersPanel, used by both Catalog and LibraryBrowse: toolbar updates now patch the query definition directly, and rules the Guided editor cannot represent open in Advanced with Guided disabled. That earlier run predates these changes and does not establish the behavior of the changed sort/filter path. The PR must explain why this validated behavior is changing, and C1 needs re-validation after merge. The rehearsal is not an RC certification.

The Validation tasks: line also omits #1256 C1 (Audiobooks — Web), which uses the same browse filter panel; that case is currently Not run.

Suggested replacement:
Validation tasks: changes #194 A2, #195 W4, #1252 C1, #1256 C1, and #199 Browse

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

Posted via Macroscope — v1 validation impact

@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: f250a6830d

ℹ️ 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 on lines +17 to +19
return limit > 0 && limit < SMART_COLLECTION_NO_LIMIT_SENTINEL
? query
: { ...query, limit: undefined };

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 Preserve explicit limits above the sentinel

When a stored smart collection has an explicitly chosen limit above 10,000,000, this predicate treats it as the no-limit sentinel and omits it on save. ApplySmartCollectionItemLimit in internal/catalog/query_definition.go honors every positive explicit limit but replaces an omitted limit with 10,000,000, so editing a collection limited to 20,000,000 silently halves its possible membership. Only the exact sentinel, nonpositive values, and absent values should be cleared.

AGENTS.md reference: AGENTS.md:L13-L18

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 d050797. Only an absent limit, a non-positive one, or exactly 10,000,000 (the value ApplySmartCollectionItemLimit fills in) now reads as blank. An explicit limit above it, such as 20,000,000, passes through and is saved unchanged. The helper test covers that case and fails on the previous commit.

…ault

The editor treated any limit at or above 10,000,000 as the server's
no-limit default and dropped it on save. The server honors every explicit
positive limit and only fills in 10,000,000 when none is set, so a
collection limited to 20,000,000 lost its limit when edited. Only the
exact default now reads as blank.

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

Quick104 commented Oct 3, 2026

Copy link
Copy Markdown
Contributor Author

Validation line updated to changes #194 A2, #195 W4, #1252 C1, #1256 C1, and the #199 Browse criterion, and the Problem section now says why the browse behavior changes: a toolbar sort or media change used to drop filters the Guided view cannot show, and now keeps them (they open in Advanced). The cases' criteria are unchanged; #1252 C1 and #1256 C1 need a re-test after merge.

@Quick104
Quick104 merged commit 5d6b6d2 into feat/collections-revamp Oct 4, 2026
16 checks passed
@Quick104
Quick104 deleted the fix/smart-collection-rules branch October 4, 2026 05:05
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