You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(jellycompat): answer Limit=0 on BoxSet children with the count only - #3259
Closes#2841
Related issue: N/A
Validation tasks: may change #1246 C1, since Jellyfin clients browse collections through this handler. Paged BoxSet children responses and their totals don't change; only Limit=0 responses lose their items.
Jellyfin clients send Limit=0 when they only want to know how many items a listing has. On a BoxSet's children, Silo ignored that and returned every member the viewer can see, fully built, with detail DTOs when Fields=MediaSources was sent. For a big collection that's the cost of the whole membership for a request that wants one number. With this change, GET /Items?ParentId=<BoxSet>&Limit=0 returns Items: [] and the same TotalRecordCount a paged request reports.
parseItemsQuery marks Limit=0 as count-only and leaves the limit at 0, but handleBoxSetChildren never checked it, and every children path read the zero limit its own way. The stored collection page in SQL and the in-memory pages (slicePage, used by Play all, the episode-scoped smart sort and the no-pool fallback) read it as no cap, so they returned every member. A smart collection's query executor read it as its default page of 20. Requests with an explicit SortBy or a filter go through the catalog browse, and its count shortcut already returned no items, except when a played, favourite or resumable filter made it skip the shortcut; those got a page of members as well.
Approach
handleBoxSetChildren now turns a count-only request into a one-row page before it picks a path, and writeListItemsPage, where every children path with members ends, drops that row and writes only the total. That's what handleBrowseItems already does for Limit=0 on library listings. Each path still works out its total the same way it does for a real page, so hidden members, Play all's series expansion and episode-scoped smart collections count as they did before. The paths that page in SQL now read the total and one row. Paths whose total already needs the whole membership (Play all, the episode-scoped sort, the fallback without a database pool) still load it, but no longer build an item for every member.
The episode browse also calls writeListItemsPage, but it already asks the catalog for no rows on Limit=0, so its responses don't change.
Only jellycompat changes. silo-apple and silo-android use the native API, so neither needs a follow-up. docs/jellycompat-api.md now says what Limit=0 returns in the BoxSet section.
Validation
Go unit test: one table test drives Limit=0 through four children paths (stored collection in curated order without a database pool, smart collection in query order, Play all leaves, and an episode-scoped smart collection with SortBy). All four returned every member on main at 0225a05 and pass here. Each case counts at StartIndex 0 and 1, checks the response keeps that StartIndex, and checks the total matches a paged request. The existing smart paging test now also checks that a count request asks the executor for one row; it fails if the one-row change is removed, which the empty Items alone would hide.
Go database test: three Limit=0 rows added to the existing Postgres test of a stored collection, which scripts/ci/db-contracts.txt already selects: two in curated order (one at StartIndex=2) and one with SortBy, which counts through the catalog browse. I didn't run them against a local database, so they run only in CI.
Not covered by a test: Limit=0 with a played, favourite or resumable filter that skips the catalog's count shortcut, which the shared writer now fixes.
Local: on 38338f7, go test ./internal/jellycompat/ passes (database tests skip without Postgres), and gofmt -l and go vet are clean on the package. golangci-lint wasn't run locally; CI's Go lint covers it. On 3e66729, which only changes tests, the BoxSet and collection tests pass.
Benchmarks: not run. The change only removes work from Limit=0 requests (see Approach), and paged requests run the same queries as before.
Evidence
Surface and build: jellycompat /Items responses served in process by HandleItems with the unit-test fixtures (a three-member stored collection, and a collection holding two movies and a series with four playable episodes). I had no local dev stack, so these aren't from a running server. Before: main at 0225a05. After: 38338f7. Responses trimmed to item names and the paging fields.
GET /Items?ParentId=<BoxSet>&Limit=0
Before: {"Items":[{"Name":"Movie One"},{"Name":"Movie Two"},{"Name":"Movie Three"}],"TotalRecordCount":3,"StartIndex":0}
After: {"Items":[],"TotalRecordCount":3,"StartIndex":0}
GET /Items?ParentId=<BoxSet>&StartIndex=1&Limit=0
Before: {"Items":[{"Name":"Movie Two"},{"Name":"Movie Three"}],"TotalRecordCount":3,"StartIndex":1}
After: {"Items":[],"TotalRecordCount":3,"StartIndex":1}
GET /Items?ParentId=<BoxSet>&Filters=IsNotFolder&Recursive=true&Limit=0 (Play all)
Before: {"Items":[{"Name":"Movie One"},{"Name":"S1E1"},{"Name":"S1E2"},{"Name":"S2E1"},{"Name":"Special"},{"Name":"Movie Two"}],"TotalRecordCount":6,"StartIndex":0}
After: {"Items":[],"TotalRecordCount":6,"StartIndex":0}
Risks
A client that read a BoxSet's members from a Limit=0 response would now get none. Jellyfin returns none for Limit=0, and so do Silo's other listings. Open #2728 edits other functions in handlers_collections.go; I don't expect a conflict.
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.
The Evidence section shows every change a user can see, or says there is none.
AI Disclosure
Harness: Claude Code (desktop app)
Tool(s): Claude Code, GitHub CLI
Model(s): claude-opus-5-5
Involvement: AI-assisted with Claude Opus. I directed the task and designed the work.
Adversarial review: a separate Claude Code agent (claude-opus-5-5) reviewed the fix commit read-only. It checked every route out of handleBoxSetChildren for Limit=0 (including StartIndex past the end, SortBy=Random, user-state filters and a missing collection), the episode browse that shares the writer, and the tests. It found no defect in the handler change. It found that no test would catch the one-row change being removed, and that the test comment claimed more paths than it covers; the second commit fixes both.
Note
Fix ItemsHandler.handleBoxSetChildren to return count only when Limit=0
Count-only BoxSet children requests (Limit=0) now return an empty Items array with the correct TotalRecordCount and StartIndex, instead of being treated as an uncapped query. The handler sets a query limit of one before the collection-member or leaf paths run, and writeListItemsPage short-circuits the item hydration path for count-only requests. Adds tests across stored, smart, Play all, and episode collection paths, and documents the behavior in jellycompat-api.md.
Behavioral Change: Jellyfin clients using Limit=0 to fetch only totals now receive no Items; previously they could receive the full item list.
Limit=0 marks a Jellyfin request as count-only, but handleBoxSetChildren
never checked it. Each children path read the zero limit as no cap or as
the smart query executor's default page, so a BoxSet's members came back
in full instead of only TotalRecordCount.
Read a one-row page for the total and drop it in writeListItemsPage, as
the library browse already does, so every path keeps its own total.
Assert the smart page asks the executor for one row on Limit=0, which the
early return in writeListItemsPage would otherwise hide, and name the
paths the count-only table covers.
BoxSet child requests with Limit=0 now return an empty Items list while preserving TotalRecordCount. Tests cover stored, smart, and Play All collections, and the API documentation describes the response.
The handler sets a positive paging limit for count-only requests and returns an empty item list with the supplied total and start index before processing items. The API documentation describes the empty Items response and preserved TotalRecordCount.
Tests check empty items and preserved totals for stored, smart, Play All, and sorted episode collections. Database tests also cover StartIndex=2. The smart executor test fake uses a default page for nonpositive limits and checks that count-only requests pass a limit of 1.
The implementation appears sound, but focused tests should cover the remaining count-only request variants before or shortly after merge.
Security architecture risk: Minimal · up to f77ed
The change suppresses unwanted item details while preserving the existing viewer-scoped count. The reviewed paths retain their authentication and visibility controls, with no identified increase in privileges or data exposure.
Retained concerns
No architecture-level concerns identified.
Security review details
Security Blast Radius
inferred — The changed exposure is limited to count-only responses on the existing authenticated collection-listing path. It removes returned member details rather than introducing a new caller, resource scope, or authority.
Trust Boundaries and Controls
observed — Stored collection totals and page IDs come from the same library- and maturity-filtered SQL relation. The database fixture asserts a total of five for count-only requests while excluding library-hidden and rating-hidden members; its unrestricted ordinary-page control sees seven.
observed — Alternate smart-query and catalog-browse paths retain session-derived access scope. Smart queries intersect collection library scope with the viewer filter; catalog browse constructs user, profile, allowed-library, disabled-library, and maturity filters before its count shortcut or page execution.
Resilience and Maintainability Implications
observed — The stored collection path retains its single-statement snapshot for total and page consistency during concurrent membership replacement. The PR changes the page size, not that consistency mechanism.
Pre-merge checks: 5
Check name
Status
Explanation
Title check
The title clearly and concisely describes the main change: making BoxSet children respond to Limit=0 with count-only results.
Linked Issues check
Issue #2841 requires GET /Items?ParentId=<BoxSet>&Limit=0 to return Items: [] with the correct TotalRecordCount, including stored collections in curated order. handleBoxSetChildren changes cou…
Out of Scope Changes check
The changed handler code, tests, smart-executor test double, and API documentation directly support issue #2841. The shared writer change prevents item hydration for count-only BoxSet responses. The a…
Docstring Coverage
Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat…
Description check
The description directly explains the BoxSet children Limit=0 behavior change, implementation approach, tests, validation, documentation, and risks. It is clearly related to the changeset.
Full details: Linked Issues check
Explanation
Issue #2841 requires GET /Items?ParentId=<BoxSet>&Limit=0 to return Items: [] with the correct TotalRecordCount, including stored collections in curated order. handleBoxSetChildren changes count-only requests to a one-row page before path selection. writeListItemsPage removes that row and preserves TotalRecordCount and StartIndex before item hydration. Tests cover the stored, smart, Play all, and episode-sorted children paths. The database test covers curated and sorted stored-collection paths. The implementation meets the linked coding requirement.
Full details: Out of Scope Changes check
Explanation
The changed handler code, tests, smart-executor test double, and API documentation directly support issue #2841. The shared writer change prevents item hydration for count-only BoxSet responses. The added tests verify totals, empty items, start-index preservation, and the one-row executor request. No unrelated change is demonstrated.
Full details: Docstring Coverage
Explanation
Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 3 functions across 4 files.
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.
Cover count-only catalog browsing for BoxSet children.
The new count-only cases use local or smart-collection paths. TestBoxSetChildrenPageVisibleMembersDB covers the catalog path only for paged sorted requests. Add one sorted Limit=0 case to assert that the catalog path returns both Items: [] and the filtered total.
The added StartIndex=2&Limit=0 case checks only the item list and TotalRecordCount. Nothing in the package asserts that a Limit=0 response keeps its StartIndex. A regression that resets StartIndex to zero on count-only responses would pass the tests.
Suggested fix
}
}
++ // Count-only requests keep the requested StartIndex.+ counted := performItemsRequest(t, h, "/Items?ParentId="+url.QueryEscape(parentID)+"&StartIndex=2&Limit=0")+ if len(counted.Items) != 0 || counted.TotalRecordCount != 5 || counted.StartIndex != 2 {+ t.Errorf("StartIndex=2&Limit=0: got %d items, total %d, StartIndex %d; want 0 items, total 5, StartIndex 2",+ len(counted.Items), counted.TotalRecordCount, counted.StartIndex)+ }+
// A viewer without restrictions sees every member.
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: 4029744e-955c-4631-b81f-0a1c67d1d0e1
Commits
Reviewing files that changed from the base of the PR and between 0225a05 and 3e66729.
Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 2 remain after this review.
Add a sorted Limit=0 row to the BoxSet database test, which counts
through the catalog browse, and count at StartIndex=1 in the unit table
so a count-only response must echo the requested StartIndex.
This change replaces the previous Limit=0 assertion instead of adding a second offset case. (github.com) Keep both Limit=0 and StartIndex=1&Limit=0 requests. The current test no longer checks default-offset behavior for the smart, Play-all, and episode paths.
Add filtered count-only cases for BoxSet children.
When IsPlayed, IsFavorite, or IsResumable is present on a BoxSet child request, the handler uses the filtered BrowseItems path. The current count-only table does not exercise these filters. Add cases that assert the filtered total, an empty Items array, and the requested StartIndex. A regression in filtered totals or count-only response writing could otherwise pass the existing unfiltered cases.
Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 0 remain after this review.
Validation tasks: none omits the Jellyfin compatibility smoke task. This diff changes the count-only response for BoxSet browsing on GET /Items?ParentId=…&Limit=0, which falls within #1246 C1. That case is currently Not run, so no prior recorded result is invalidated; the native /api/v2 Collections results are unaffected.
Suggested fix: Replace the PR body line with: Validation tasks: changes #1246 C1 (not yet run); no recorded case result changes.
Automated check: Macroscope check run agent (gpt-6-luna). No validation was performed.
Run each count-only case at StartIndex 0 as well as 1, so the table keeps
the plain Limit=0 request from Silo-Server#2841 alongside the StartIndex check.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bugSomething isn't workinggoPull requests that update go codeimpact: compatBreaks a supported client or server pathpriority: P2Limited scope, workaround exists, or polishsize/M50–199 added + deleted lines (all files); change volume, not priority.
2 participants
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Closes #2841
Related issue: N/A
Validation tasks: may change #1246 C1, since Jellyfin clients browse collections through this handler. Paged BoxSet children responses and their totals don't change; only
Limit=0responses lose their items.Jellyfin clients send
Limit=0when they only want to know how many items a listing has. On a BoxSet's children, Silo ignored that and returned every member the viewer can see, fully built, with detail DTOs whenFields=MediaSourceswas sent. For a big collection that's the cost of the whole membership for a request that wants one number. With this change,GET /Items?ParentId=<BoxSet>&Limit=0returnsItems: []and the sameTotalRecordCounta paged request reports.parseItemsQuerymarksLimit=0as count-only and leaves the limit at 0, buthandleBoxSetChildrennever checked it, and every children path read the zero limit its own way. The stored collection page in SQL and the in-memory pages (slicePage, used by Play all, the episode-scoped smart sort and the no-pool fallback) read it as no cap, so they returned every member. A smart collection's query executor read it as its default page of 20. Requests with an explicitSortByor a filter go through the catalog browse, and its count shortcut already returned no items, except when a played, favourite or resumable filter made it skip the shortcut; those got a page of members as well.Approach
handleBoxSetChildrennow turns a count-only request into a one-row page before it picks a path, andwriteListItemsPage, where every children path with members ends, drops that row and writes only the total. That's whathandleBrowseItemsalready does forLimit=0on library listings. Each path still works out its total the same way it does for a real page, so hidden members, Play all's series expansion and episode-scoped smart collections count as they did before. The paths that page in SQL now read the total and one row. Paths whose total already needs the whole membership (Play all, the episode-scoped sort, the fallback without a database pool) still load it, but no longer build an item for every member.The episode browse also calls
writeListItemsPage, but it already asks the catalog for no rows onLimit=0, so its responses don't change.Only jellycompat changes. silo-apple and silo-android use the native API, so neither needs a follow-up.
docs/jellycompat-api.mdnow says whatLimit=0returns in the BoxSet section.Validation
Limit=0through four children paths (stored collection in curated order without a database pool, smart collection in query order, Play all leaves, and an episode-scoped smart collection withSortBy). All four returned every member onmainat 0225a05 and pass here. Each case counts atStartIndex0 and 1, checks the response keeps thatStartIndex, and checks the total matches a paged request. The existing smart paging test now also checks that a count request asks the executor for one row; it fails if the one-row change is removed, which the emptyItemsalone would hide.Limit=0rows added to the existing Postgres test of a stored collection, whichscripts/ci/db-contracts.txtalready selects: two in curated order (one atStartIndex=2) and one withSortBy, which counts through the catalog browse. I didn't run them against a local database, so they run only in CI.Limit=0with a played, favourite or resumable filter that skips the catalog's count shortcut, which the shared writer now fixes.go test ./internal/jellycompat/passes (database tests skip without Postgres), andgofmt -landgo vetare clean on the package.golangci-lintwasn't run locally; CI'sGo lintcovers it. On 3e66729, which only changes tests, the BoxSet and collection tests pass.cijob passed on 3e66729 (https://github.com/Silo-Server/silo-server/actions/runs/40980461336), includingGo lintandGo DB pins, where the Postgres test with the first twoLimit=0rows ran and passed. Later commits only add test coverage; their run is pending.Limit=0requests (see Approach), and paged requests run the same queries as before.Evidence
Surface and build: jellycompat
/Itemsresponses served in process byHandleItemswith the unit-test fixtures (a three-member stored collection, and a collection holding two movies and a series with four playable episodes). I had no local dev stack, so these aren't from a running server. Before:mainat 0225a05. After: 38338f7. Responses trimmed to item names and the paging fields.Risks
A client that read a BoxSet's members from a
Limit=0response would now get none. Jellyfin returns none forLimit=0, and so do Silo's other listings. Open #2728 edits other functions inhandlers_collections.go; I don't expect a conflict.Checklist
AI Disclosure
handleBoxSetChildrenforLimit=0(includingStartIndexpast the end,SortBy=Random, user-state filters and a missing collection), the episode browse that shares the writer, and the tests. It found no defect in the handler change. It found that no test would catch the one-row change being removed, and that the test comment claimed more paths than it covers; the second commit fixes both.Note
Fix
ItemsHandler.handleBoxSetChildrento return count only when Limit=0Count-only BoxSet children requests (Limit=0) now return an empty Items array with the correct TotalRecordCount and StartIndex, instead of being treated as an uncapped query. The handler sets a query limit of one before the collection-member or leaf paths run, and
writeListItemsPageshort-circuits the item hydration path for count-only requests. Adds tests across stored, smart, Play all, and episode collection paths, and documents the behavior in jellycompat-api.md.Macroscope summarized 7b0ef3a.