Skip to content

fix(sections): cut curated lists to item_limit on capped aggregate reads - #3419

Merged
Quick104 merged 2 commits into
Silo-Server:mainfrom
dannyshafer:fix/curated-list-item-limit
Nov 4, 2026
Merged

Quick104 merged 2 commits into
Silo-Server:mainfrom
dannyshafer:fix/curated-list-item-limit

Conversation

@dannyshafer

@dannyshafer dannyshafer commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Closes #3301
Related issue: #3276
Validation tasks: changes #1140 C1, #1145 C1, Silo-Server/silo-apple#305 C1, Silo-Server/silo-apple#306 C1, Silo-Server/silo-android#315 C1, Silo-Server/silo-android#316 C1, Silo-Server/silo-apple#309 C1, Silo-Server/silo-apple#310 C1, Silo-Server/silo-android#319 C1, Silo-Server/silo-android#320 C1, Silo-Server/silo-apple#337 C1, Silo-Server/silo-apple#338 C1, Silo-Server/silo-android#347 C1, Silo-Server/silo-android#348 C1, Silo-Server/silo-apple#339 C1, Silo-Server/silo-apple#340 C1, Silo-Server/silo-android#349 C1, Silo-Server/silo-android#350 C1

listHomeSections and listLibrarySections with item_limit can answer more cards than the cap for an admin curated list row. The cap lowers each row's limit before the fetch, but the curated list fetcher returns every configured item, so a client that asks for 10 cards per row gets the whole list for a curated row. This change cuts each row back to its capped limit after the fetch, so the reads answer at most item_limit cards per row as the contract says.

Approach

The aggregate reads now cut each fetched row to its effective (capped) limit, the same cut homeSectionRow already applies to getHomeSectionItems and getHomeLayout since #3276. The cut runs before the cross-row diversity filter, so that pass works from the capped rows, and total_count keeps its meaning. The API contract doc now says so. It only runs when item_limit is sent, so uncapped reads, including every /api/v1 read, are unchanged. Limiting the curated list query itself would also change uncapped reads, which answer the whole list today.

Validation

  • Focused tests: go test ./internal/api/handlers/ passes. The new test covers the cut itself (capped, default-limit and uncapped rows); it does not drive the two call sites, since the aggregate reads use the concrete sections.Fetcher and would need Postgres.
  • Gate: go build ./..., gofmt -l ., go vet ./..., make lint-changed, make lint-router-recovery, make test-go: all pass except make test-go: 199 packages pass; the failures are in packages this change does not touch and fail the same way on unmodified main in this environment (TestPersonalPosterSourceRefusesLocalAddresses needs IPv6 sockets, TestRunStatsWithRealFFmpeg and TestCopyRemuxSubtitleRenditionRealFFmpeg need this container's ffmpeg), plus three hardware-probe timing tests in internal/playback that pass when rerun.
  • Not run: the web gate (no web change) and a manual check against a running server.

Evidence

Surface and build: native API listHomeSections and listLibrarySections with item_limit. The iOS, tvOS, Android and Android TV apps send item_limit (20) to these reads once the server advertises section_item_limit_max; web Home uses getHomeLayout and getHomeSectionItems, which already cut.

Captured on a local build with dummy data: one movie library of 8 generated test clips, a home admin curated list and a library admin curated list each holding all 8. Before: upstream main at 07f0ae2; after: this branch at a1215a1, same database and requests. Each excerpt is the curated row only, trimmed to the fields that matter, with item titles in place of the full item objects.

GET /api/v2/home/sections?item_limit=5

BeforeAfter
{
  "section_type": "admin_curated_list",
  "title": "Editor's Picks",
  "item_limit": 5,
  "total_count": 8,
  "items": [
    "Test Movie 01",
    "Test Movie 02",
    "Test Movie 03",
    "Test Movie 04",
    "Test Movie 05",
    "Test Movie 06",
    "Test Movie 07",
    "Test Movie 08"
  ]
}
{
  "section_type": "admin_curated_list",
  "title": "Editor's Picks",
  "item_limit": 5,
  "total_count": 8,
  "items": [
    "Test Movie 01",
    "Test Movie 02",
    "Test Movie 03",
    "Test Movie 04",
    "Test Movie 05"
  ]
}

GET /api/v2/library/1/sections?item_limit=5

BeforeAfter
{
  "section_type": "admin_curated_list",
  "title": "Library Picks",
  "item_limit": 5,
  "total_count": 8,
  "items": [
    "Test Movie 01",
    "Test Movie 02",
    "Test Movie 03",
    "Test Movie 04",
    "Test Movie 05",
    "Test Movie 06",
    "Test Movie 07",
    "Test Movie 08"
  ]
}
{
  "section_type": "admin_curated_list",
  "title": "Library Picks",
  "item_limit": 5,
  "total_count": 8,
  "items": [
    "Test Movie 01",
    "Test Movie 02",
    "Test Movie 03",
    "Test Movie 04",
    "Test Movie 05"
  ]
}

The same request without item_limit answers all 8 curated items on both builds (item_limit 100), so uncapped reads are unchanged.

Risks

The native apps' Home and library pages change: an admin curated list longer than 20 items now shows its first 20 cards instead of the whole list, and items past the cap no longer take part in the cross-row duplicate filter. That is the documented item_limit behavior, and the affected validation cases (listed above) have not been run. Uncapped reads, including web Home and /api/v1, are untouched.

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 (cloud session)
  • Tool(s): Claude Code
  • Model(s): claude-opus-5-5
  • Involvement: Fully AI-generated, human verified
  • Adversarial review: A separate Claude Code agent reviewed the diff against the hide-watched path, the diversity filter, total_count, shared slices, unset limits and /api/v1, and found no correctness problems. It noted that the contract doc did not mention the post-fetch cut (added) and that the test covers the helper rather than the call sites (stated above).

Note

Fix curated section lists to truncate to item_limit on capped reads

Aggregate section reads could return more items than a row's effective limit when the viewer had an item-limit cap set, because the source (e.g. an admin-curated list) returned all configured items and the cross-row duplicate filter ran first.

  • Adds cutCappedSectionItems in library_views_service.go; it truncates each row's Items to that row's effective limit and leaves TotalCount unchanged. Uncapped reads (non-positive cap) return rows unchanged.
  • SectionHandler.HomeSections and SectionHandler.LibrarySections call the helper after watched-item filtering and before the diversity filter.
  • Updates the API contract doc to state that curated sources are truncated to their effective row limit before the duplicate filter.
  • Behavioral Change: capped aggregate reads now show fewer items per row than before; TotalCount is unaffected. Covered by TestCutCappedSectionItems in sections_home_watched_test.go.

Macroscope summarized a1215a1.

listHomeSections and listLibrarySections lower each row's limit to
item_limit before fetching, but the admin curated list fetcher returns
every configured item, so a curated row answered more cards than the
cap. Cut each row back to its capped limit after the fetch, as
homeSectionRow does for one row. Uncapped reads, including /api/v1,
are unchanged.

Closes Silo-Server#3301
@silo-kody

silo-kody Bot commented Nov 2, 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 ❌

@silo-triage silo-triage Bot added the size/M 50–199 added + deleted lines (all files); change volume, not priority. label Nov 2, 2026
@coderabbitai

coderabbitai Bot commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent 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: 12665d95-b091-4f44-a319-aa9e5eb3f380
Commits

Reviewing files that changed from the base of the PR and between baf9d42 and a1215a1.

Files selected for processing: 4
  • docs/architecture/api-contract.md
  • internal/api/handlers/home_views_service.go
  • internal/api/handlers/library_views_service.go
  • internal/api/handlers/sections_home_watched_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.

Walkthrough

Home and library section reads now trim fetched items to each row’s effective item limit before cross-row duplicate filtering. The trimming preserves the source total_count. A test covers capped and uncapped reads, including a row with an unset limit.

Changes: Aggregate section limits

Layer / File(s) Summary
Trim fetched rows before diversity filtering
internal/api/handlers/library_views_service.go, internal/api/handlers/home_views_service.go, internal/api/handlers/sections_home_watched_test.go, docs/architecture/api-contract.md
cutCappedSectionItems trims fetched items to effective limits when a cap is set and leaves rows unchanged for a non-positive cap. HomeSections and LibrarySections apply the trim before diversity filtering. Tests cover limit handling and preservation of TotalCount; the API contract documents the behavior.

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

Change: Bug fix · Severity of issue fixed: Medium

Possibly related issues

Suggested labels: bug, go, api-v2, priority: P2, size/M

Suggested reviewers: quick104

Merge Risk: Minimal · up to a1215

Capped reads trim section items while preserving totals. No merge-blocking issue was found.

Security architecture risk: Low · up to a1215

The change narrows returned card lists while retaining the inspected access checks. No new security issue was identified in those paths, but the complete before-and-after comparison could not be verified.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The inspected response change is confined to profile-scoped Home rows and authorized Library rows. Shortening fetched item lists does not itself grant access to another profile, library or service.

Trust Boundaries and Controls

  • observed — At the inspected head, the Library operation validates viewer identity and library visibility before fetching. Home resolution derives profile identity and library, disabled-library and maturity scope from context. Both aggregate fetch calls pass identity and access filters before the new truncation step.

Resilience and Maintainability Implications

  • inferred — Truncation introduces no durable transition or cleanup obligation. FetchAll allocates request-local result rows and waits for every worker; errors and recovered panics become empty rows. The helper only shortens item slice headers, is idempotent for a fixed effective limit, and does not mutate pointed-to media objects or shared resolved configuration.
Pre-merge checks: Passed 5
Check name Status Explanation
Title check Passed The title names the main change: capped aggregate section reads (listHomeSections and listLibrarySections) now cut curated lists to item_limit. It is specific, short, and matches the diff summary and …
Linked Issues check Passed Issue #3301 requires that listHomeSections and listLibrarySections return at most item_limit cards per section for admin curated lists when item_limit is set. Total_count must stay unchanged. Uncapped…
Out of Scope Changes check Passed The changed files in the whole-PR diff are internal/api/handlers/library_views_service.go, internal/api/handlers/home_views_service.go, internal/api/handlers/sections_home_watched_test.go, and docs/ar…
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 pull request description directly explains the changes to truncate curated section rows to item_limit on capped aggregate reads, preserve total_count, update the API contract, and validate the beh…
Full details: Title check

Explanation

The title names the main change: capped aggregate section reads (listHomeSections and listLibrarySections) now cut curated lists to item_limit. It is specific, short, and matches the diff summary and PR objectives. No web search was needed because the check depends only on the supplied context.

Full details: Linked Issues check

Explanation

Issue #3301 requires that listHomeSections and listLibrarySections return at most item_limit cards per section for admin curated lists when item_limit is set. Total_count must stay unchanged. Uncapped reads must keep the full list.

The diff from merge base 07f0ae2 to head a1215a1 adds cutCappedSectionItems in internal/api/handlers/library_views_service.go. For a positive limit, it truncates each row's Items to effectiveHomeItemLimit(row.ItemLimit). It does not change TotalCount. For a non-positive limit, it returns the rows unchanged.

The helper is called in two places:

  • HomeSections (home_views_service.go): after the hide-watched filter and before applyDiversityFilter.
  • LibrarySections (library_views_service.go): after FetchAll and before applyDiversityFilter.

Both paths receive the capped viewer.ItemLimitCap. The capSectionItemLimits call that lowers each row's ItemLimit runs before FetchAll, so a curated row whose fetcher returns every configured item is cut to the capped limit. This matches the homeSectionRow behavior described for #3276.

Uncapped reads pass ItemLimitCap = 0, so the helper returns early and the behavior is unchanged. This covers /api/v1 reads.

TestCutCappedSectionItems in sections_home_watched_test.go covers a cap below every row limit, a cap above an unset row's default, and an uncapped read. It checks that Items are cut and TotalCount is preserved. It tests the helper and not the two call sites. The call-site wiring was confirmed by reading the diff, not by running a test.

Not verified in this review: the body of effectiveHomeItemLimit and the sections.SectionWithItems type were not read directly. The helper's use of effectiveHomeItemLimit matches its existing use in capSectionItemLimit in the same file.

All coding requirements of #3301 are implemented at the reviewed head.

Full details: Out of Scope Changes check

Explanation

The changed files in the whole-PR diff are internal/api/handlers/library_views_service.go, internal/api/handlers/home_views_service.go, internal/api/handlers/sections_home_watched_test.go, and docs/architecture/api-contract.md.

  • library_views_service.go: adds cutCappedSectionItems and calls it in LibrarySections. This implements #3301.
  • home_views_service.go: adds one call to cutCappedSectionItems in HomeSections. This implements #3301.
  • sections_home_watched_test.go: adds TestCutCappedSectionItems for the new helper. This supports the objective.
  • docs/architecture/api-contract.md: states that curated sources are truncated to the effective row limit before the duplicate filter. This documents the new behavior.

No change alters uncapped reads, the fetcher, the diversity filter's logic, or the watched-item logic. The PR description's mention of #3276 and #1140 is context only and does not add code.

No unrelated change was found in the reviewed diff.

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 2 functions across 3 files. (1 skipped: 1 unsupported.)

Full details: Description check

Explanation

The pull request description directly explains the changes to truncate curated section rows to item_limit on capped aggregate reads, preserve total_count, update the API contract, and validate the behavior with tests and evidence.

Finishing Touches
Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

@macroscopeapp

macroscopeapp Bot commented Nov 2, 2026

Copy link
Copy Markdown

The PR changes the items in the native API's capped aggregate responses:

  • listHomeSections (GET /home/sections?item_limit=...): curated-list rows now return at most their capped item limit; no before-and-after response excerpts are provided.
  • listLibrarySections (GET /library/{id}/sections?item_limit=...): the same change applies; no before-and-after response excerpts are provided.

Suggested fix: Add before-and-after response excerpts for each endpoint using the same request and data, and identify the surface and commit. The current Evidence: none, no user-visible change does not cover this API response change.

Automated check: Macroscope check run agent (gpt-6-luna). Evidence was not reviewed for correctness.

Posted via Macroscope — Visible change evidence

@silo-triage silo-triage Bot added bug Something isn't working evidence-required Needs before-and-after evidence before the Evidence check passes go Pull requests that update go code priority: P2 Limited scope, workaround exists, or polish labels Nov 2, 2026
@coderabbitai coderabbitai Bot added the api-v2 API v2 / Huma migration program (epic #135); long-running, stacked by phase label Nov 2, 2026
@macroscopeapp

macroscopeapp Bot commented Nov 2, 2026

Copy link
Copy Markdown

Validation tasks: none is inaccurate. The native clients send item_limit=20 to both aggregate endpoints after capability discovery, and admin-curated rows are allowed on library scope. This change trims those rows before cross-row deduplication, which can change Home/library row contents and recommendation IDs. The affected C1 cases are all Not run, so no prior pass is invalidated; the PR must explain this intended output change, and these cases need human validation on a post-merge build.

Suggested fix — replace the line with:

Validation tasks: changes #1140 C1, #1145 C1, Silo-Server/silo-apple#305 C1, Silo-Server/silo-apple#306 C1, Silo-Server/silo-android#315 C1, Silo-Server/silo-android#316 C1, Silo-Server/silo-apple#309 C1, Silo-Server/silo-apple#310 C1, Silo-Server/silo-android#319 C1, Silo-Server/silo-android#320 C1, Silo-Server/silo-apple#337 C1, Silo-Server/silo-apple#338 C1, Silo-Server/silo-android#347 C1, Silo-Server/silo-android#348 C1, Silo-Server/silo-apple#339 C1, Silo-Server/silo-apple#340 C1, Silo-Server/silo-android#349 C1, Silo-Server/silo-android#350 C1

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

Posted via Macroscope — v1 validation impact

@Quick104
Quick104 merged commit 4e3020a into Silo-Server:main Nov 4, 2026
16 checks passed
@dannyshafer
dannyshafer deleted the fix/curated-list-item-limit branch November 8, 2026 18:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api-v2 API v2 / Huma migration program (epic #135); long-running, stacked by phase bug Something isn't working evidence-required Needs before-and-after evidence before the Evidence check passes go Pull requests that update go code 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.

[bug] Admin curated list sections ignore item_limit on listHomeSections and listLibrarySections

2 participants