Skip to content

fix(jellycompat): answer Limit=0 on BoxSet children with the count only - #3259

Merged
Quick104 merged 4 commits into
Silo-Server:mainfrom
blurbery:fix/jellycompat-boxset-limit-zero
Oct 30, 2026
Merged

Quick104 merged 4 commits into
Silo-Server:mainfrom
blurbery:fix/jellycompat-boxset-limit-zero

Conversation

@blurbery

@blurbery blurbery commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

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=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.
  • CI: every ci job passed on 3e66729 (https://github.com/Silo-Server/silo-server/actions/runs/40980461336), including Go lint and Go DB pins, where the Postgres test with the first two Limit=0 rows ran and passed. Later commits only add test coverage; their run is pending.
  • 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.

Macroscope summarized 7b0ef3a.

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.
@silo-triage silo-triage Bot added the size/M 50–199 added + deleted lines (all files); change volume, not priority. label Oct 30, 2026
@silo-kody

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

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Walkthrough

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.

Changes: BoxSet count-only response

Layer / File(s) Summary
Count-only response handling
docs/jellycompat-api.md, internal/jellycompat/handlers_collections.go
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.
Count-only coverage
internal/jellycompat/handlers_collections_db_test.go, internal/jellycompat/handlers_collections_test.go, internal/jellycompat/smart_boxset_test.go
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.

Priority: Normal

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

Change: Bug fix · Severity of issue fixed: Medium

Possibly related issues

Suggested reviewers: rhainland, quick104

Merge Risk: Low · up to f77ed

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: Passed 5
Check name Status Explanation
Title check Passed The title clearly and concisely describes the main change: making BoxSet children respond to Limit=0 with count-only results.
Linked Issues check Passed 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 Passed 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 Passed 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 Passed 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=&lt;BoxSet&gt;&amp;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.

@silo-triage silo-triage Bot added bug Something isn't working go Pull requests that update go code impact: compat Breaks a supported client or server path priority: P2 Limited scope, workaround exists, or polish labels Oct 30, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nitpick comments: 2
internal/jellycompat/handlers_collections_test.go: 1

311-372: Trivial · Functional Correctness · Quick win

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.

Suggested fix
 		{"&Limit=0", []string{}},
 		{"&StartIndex=2&Limit=0", []string{}},
+		{"&SortBy=SortName&SortOrder=Ascending&Limit=0", []string{}},
 		{"", []string{"Title G", "Title F", "Title D", "Title B", "Title A"}},
internal/jellycompat/handlers_collections_db_test.go: 1

133-140: Trivial · Functional Correctness · Quick win

Assert StartIndex on the Limit=0 case.

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.

Files selected for processing: 5
  • docs/jellycompat-api.md
  • internal/jellycompat/handlers_collections.go
  • internal/jellycompat/handlers_collections_db_test.go
  • internal/jellycompat/handlers_collections_test.go
  • internal/jellycompat/smart_boxset_test.go

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.
@silo-kody

silo-kody Bot commented Oct 30, 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 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Follow-up Comments

Nitpick Keep the default-offset count case.

365-366: Trivial · Functional Correctness · Quick win

Keep the default-offset count case.

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.

Open the source location

Nitpick Add filtered count-only cases for BoxSet children.

348-357: Trivial · Functional Correctness · Quick win

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.

Open the source location


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: 8998d8e6-8b20-4609-9dcc-2bea26314801
Commits

Reviewing files that changed from the base of the PR and between 3e66729 and f77edf4.

Files selected for processing: 2
  • internal/jellycompat/handlers_collections_db_test.go
  • internal/jellycompat/handlers_collections_test.go

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 0 remain after this review.

@macroscopeapp

macroscopeapp Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

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.

Posted via Macroscope — v1 validation impact

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.
@silo-kody

silo-kody Bot commented Oct 30, 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 merged commit 3cd9e48 into Silo-Server:main Oct 30, 2026
16 checks passed
@blurbery
blurbery deleted the fix/jellycompat-boxset-limit-zero branch November 6, 2026 00:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working go Pull requests that update go code impact: compat Breaks a supported client or server path 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.

jellycompat: Limit=0 on a BoxSet's children returns every member instead of only the count

2 participants