Skip to content

fix(tv): read only the Watch Next rows instead of all of Home - #775

Merged
Quick104 merged 2 commits into
Silo-Server:mainfrom
feardubin:fix/issue-624-watch-next-layout
Nov 1, 2026
Merged

Quick104 merged 2 commits into
Silo-Server:mainfrom
feardubin:fix/issue-624-watch-next-layout

Conversation

@feardubin

@feardubin feardubin commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Closes #624
Related issue: #623 (same kind of Home read; fixed in #626)
Validation tasks: none

On Android TV, the hourly Watch Next sync downloads every Home row to keep only the Continue Watching and Next Up rows. It runs in the app's process, including while a video plays. With a large Home the response is about 1 MB, read as one string and then decoded, which can exhaust the heap on a low-memory TV.

This happens on real devices. A 2018 Fire TV Stick 4K (AFTMM, Android 7.1.2) running Silo Android TV 1.0.0 (28), which already includes #626, crashed twice with java.lang.OutOfMemoryError in StringFactory.newStringFromChars. Each time, the server logged a background GET /api/v2/home/sections of about 1.02 MB to that device about 1 s before the crash, and the failed allocation (2,033,584 bytes) is that body as a UTF-16 string. The two reads were 59 minutes apart, which fits the hourly sync.

The server log does not name the caller. One of the two reads came just before a new playback started, which also fits the player's On Deck load (TvPlayerViewModel reads all of Home at playback start). This PR fixes the Watch Next path only; the player path is a separate follow-up.

I haven't had a PR merged in a Silo repository and wasn't asked for this one. I've commented on #624. If you'd rather implement it yourselves, please close this.

Approach

The sync reads GET /api/v2/home/layout, which lists each row's id and section_type without cards, then reads only the continue_watching and next_up rows through GET /api/v2/home/sections/{id}/items. It never calls GET /api/v2/home/sections.

  • HomeSectionsV2Api.layout(), SectionApi.getHomeLayout() and SectionRepository.getHomeLayout() read the layout. They live in shared/ with the rest of the section API; only the TV Watch Next sync calls them.
  • A row read answers with the row's configured limit, not the capped Home list's, so the sync keeps at most SECTION_ROW_MAX_ITEMS (20) cards per row, the same cap a Home row draws.
  • A successful empty row is accepted as empty. Hide-watched filtering can empty Next Up while total_count stays above zero, and that must not block the other rows' tiles.
  • A failed layout or row read still returns false, so existing launcher tiles stay and the sync retries. Every existing owner, borrowed-identity and gate check still runs after each request.

Android TV only: the phone app has no Watch Next sync. No server change: /api/v2/home/layout has existed since the v2 API migration.

Validation

  • ./gradlew testDebugUnitTest on f35abf9: passed, 6,657 tests, 0 failures.
  • Debug lint for android-shared, androidApp and androidTvApp, plus lintVitalRelease for both apps, on f35abf9: passed.
  • :androidTvApp:assembleDebug and :androidApp:assembleDebug on f35abf9: passed. Release bundles passed on the previous revision and were not re-run.
  • WatchNextHomeSyncTest (14 tests) fails on the old implementation: 7 of the earlier 9 fail when only WatchNextHomeSync.kt is reverted to main. The two new regression tests (row cap, empty row) fail on this PR's first revision and pass now.
  • Supply-chain scripts and fastlane lane tests: not run, because Ruby isn't installed locally (they fail the same way on main). This change touches no build or workflow files.
  • Android TV emulator: both builds signed in, loaded Home and played a title, and the Watch Next sync published the same tiles (details under Evidence). The playback crash itself was not reproduced, and nothing was run on a Fire TV device.
  • Maintainer review fix (c3902a6): the sync now returns false when a row read's section_type differs from the layout entry's, because an admin can change a section's type and keep its id. The new test aRowWhoseTypeChangedAfterTheLayoutKeepsEveryTile failed without the fix and passes with it; WatchNextHomeSyncTest is 15 tests, 0 failures, at c3902a6.

Evidence

Evidence: https://evidence.siloserver.org/r/silo-android/pr-775/

Nothing a capture can show: the launcher shows the same Continue Watching and Next Up tiles, and only the requests behind them change. Phones, tablets and foldables have no Watch Next sync. Results instead:

  • WatchNextHomeSyncTest on f35abf9: 14 tests, 0 failures. It fails if the sync requests /api/v2/home/sections. It checks that only continue_watching and next_up rows are read, in layout order, at most 20 cards per row. It checks that an empty Next Up row still reconciles the other rows, and that a failed or malformed read, or a profile change during a row read, never writes the launcher.
  • The same tests against the old WatchNextHomeSync.kt: 7 of the earlier 9 fail. The two new regression tests (row cap, empty row) fail on this PR's first revision.
  • Full testDebugUnitTest on f35abf9: 6,657 tests, 0 failures, 0 skipped.
  • Response sizes from a production server over 24 hours (logged body_bytes, HTTP 200): listHomeSections median 973,940 bytes (p95 1,021,683); getHomeLayout median 56,788; getHomeSectionItems median 28,526 (all row types mixed, so this is indicative, not a paired measurement).
  • Android TV emulator, old (864cd1d6f) vs fixed (f35abf912), same test account. Image: x86_64 Android TV API 36, 1,536 MB RAM, effective heap 384 MB. Builds: minified assembleRelease, signed with the debug key.
    • Both builds signed in, loaded Home and played a title, so R8 didn't break the release build.
    • With watch_next_sync_periodic triggered on demand, both builds published the same 4 Watch Next programs (content://android.media.tv/watch_next_program).
    • Requests for that sync, from the server's request log: the old build made one listHomeSections call, 687,215 bytes. The fixed build made one getHomeLayout call, 4,216 bytes, and three getHomeSectionItems calls, 4,377 + 189 + 1,605 bytes. It made no listHomeSections call. The foreground Home screen still uses that endpoint, as before.
    • The OutOfMemoryError was not reproduced: neither build crashed while playing. The emulator's heap is twice the 2018 stick's, and there is no Fire OS image to test on.

Risks

  • Each sync makes 1 + N sequential requests (the layout, then one per matching row) instead of one large one. N is usually 1 or 2.
  • Row reads fetch the row's configured limit (100 by default) and keep 20. On servers that advertise row_item_limit_max, sending the cap with the row read would save more; left as a follow-up to keep this to one concern.
  • On a server without section_item_limit_max, the old sync could publish more than 20 tiles per row; it now publishes at most 20, matching Home.
  • A row removed between the layout and its row read answers 404; the sync returns false, keeps the tiles, and retries on the next run.

Checklist

  • I read and can explain the complete diff.
  • This pull request addresses one concern.
  • The Evidence section shows every change a user can see, or says there is none.

AI Disclosure

  • Harness: Claude Code and Codex, both run inside T3 Code
  • Tool(s): Claude Code; Codex
  • Model(s): claude-opus-5-5 (wrote the change and the review fixes); gpt-6.1-sol (adversarial review); gpt-6-astra (server-contract review); gpt-6.1-terra (full validation run, opened this PR); claude-sonnet-5-5 (researched contribution conventions, drafted text)
  • Involvement: Fully AI-generated; the maintainer of the affected deployment reviewed the investigation and approved submission, but has not verified the diff line by line
  • Adversarial review: gpt-6.1-sol (ultra effort) reviewed the first revision against the silo-server source for row parity, server compatibility, owner and authority fences, error semantics and decoding. It found two regressions: the per-row reads dropped the negotiated 20-item cap, and a filtered-empty Next Up row could block every launcher update. Both are fixed in f35abf9, with tests. It found no authority or compatibility issue. gpt-6-astra separately confirmed that layout, row and list reads resolve the same rows, order, overrides, dismissals and artwork. The final revision was not independently re-reviewed after those fixes.

🤖 Generated with Claude Code

Note

Fix TV Watch Next sync to fetch only Watch Next rows, not all of Home

...

Macroscope summarized c3902a6.

The hourly Watch Next sync downloaded every Home row (over 1 MB with
large rows) to keep two of them, including during playback. It now
reads GET /api/v2/home/layout and then only the continue_watching and
next_up rows.

Closes Silo-Server#624

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@silo-triage silo-triage Bot added the size/M 50–199 added + deleted lines (all files); change volume, not priority. label Nov 1, 2026
@silo-kody

silo-kody Bot commented Nov 1, 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 Nov 1, 2026 •

Copy link
Copy Markdown

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: cb4c5f38-fe8c-4e67-8031-a8325531affd
Commits

Reviewing files that changed from the base of the PR and between f35abf9 and c3902a6.

Files selected for processing: 2
  • androidTvApp/src/androidMain/kotlin/org/siloserver/silo/tv/watchnext/WatchNextHomeSync.kt
  • androidTvApp/src/androidUnitTest/kotlin/org/siloserver/silo/tv/watchnext/WatchNextHomeSyncTest.kt

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

Walkthrough

Android TV Watch Next sync now reads Home layout metadata, then fetches items only for continue_watching and next_up rows. The shared v2 API adds layout model and endpoint support. Tests cover row selection, item limits, read failures, stale profiles, and malformed layouts.

Changes: Watch Next sync

Layer / File(s) Summary
Home layout API
shared/src/commonMain/kotlin/org/siloserver/silo/model/section/SectionModels.kt, shared/src/commonMain/kotlin/org/siloserver/silo/network/apiv2/HomeSectionsV2Api.kt, shared/src/commonMain/kotlin/org/siloserver/silo/network/api/SectionApi.kt, shared/src/commonMain/kotlin/org/siloserver/silo/repository/SectionRepository.kt
Adds HomeLayoutRow and owner-scoped layout reads. The v2 decoder requires a sections array and rejects rows with missing or blank IDs or section types.
Watch Next row reads
androidTvApp/src/androidMain/kotlin/org/siloserver/silo/tv/watchnext/WatchNextHomeSync.kt, androidTvApp/src/androidUnitTest/kotlin/org/siloserver/silo/tv/watchnext/WatchNextHomeSyncTest.kt
The sync fetches items only for continue_watching and next_up rows and processes at most SECTION_ROW_MAX_ITEMS items per row. Layout and row-read failures return false. Tests cover row selection, failures, limits, stale profiles, and malformed layouts.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix · Severity of issue fixed: Medium

Sequence Diagram(s)

sequenceDiagram
  participant WatchNextHomeSync
  participant SectionRepository
  participant HomeV2API
  WatchNextHomeSync->>SectionRepository: Read Home layout
  SectionRepository->>HomeV2API: Request layout
  HomeV2API-->>SectionRepository: Return layout rows
  SectionRepository-->>WatchNextHomeSync: Return layout result
  loop Each continue_watching or next_up row
    WatchNextHomeSync->>SectionRepository: Read row items
    SectionRepository->>HomeV2API: Request section items
    HomeV2API-->>SectionRepository: Return row items
    SectionRepository-->>WatchNextHomeSync: Return row result
  end
Loading

Possibly related PRs

Suggested labels: api-v2, impact: playback, evidence-required

Suggested reviewers: quick104

Merge Risk: Minimal · up to c3902

No actionable merge-blocking risk was identified in the changed Watch Next synchronization flow.

Architecture risk: Low · up to c3902

The change affects 2 systems.

Changed systems: androidTvApp, shared

Architecture concerns
No architecture-level concerns identified.

Review details

Systems and components

  • observed — androidTvApp (service) was modified; 2 changed files map to changed impact.
  • observed — shared (service) was modified; 4 changed files map to changed impact.

Before / after behavior

  • observed — Modified behavior in shared/src/commonMain/kotlin/org/siloserver/silo/model/section/SectionModels.kt: Added HomeLayoutRow with id and sectionType fields to represent a Home layout row without its cards.
  • observed — Modified behavior in shared/src/commonMain/kotlin/org/siloserver/silo/network/api/SectionApi.kt: SectionApi adds getHomeLayout, delegating the owner-scoped request to home.layout.
  • observed — Modified behavior in shared/src/commonMain/kotlin/org/siloserver/silo/network/apiv2/HomeSectionsV2Api.kt: Added the HomeLayoutRow import.
  • observed — Modified behavior in shared/src/commonMain/kotlin/org/siloserver/silo/network/apiv2/HomeSectionsV2Api.kt: Added decodeHomeLayoutV2, which requires a sections array, extracts string id and section_type values from each row, rejects missing or blank identities, and returns HomeLayoutRow entries.
Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documenta… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly and concisely describes the main change: the Android TV Watch Next sync reads only the relevant Home rows instead of all Home rows.
Linked Issues check Passed Issue #624 requires the Android TV Watch Next sync to avoid the full Home read and fetch only continue_watching and next_up. syncWatchNextHome reads getHomeLayout, filters those section types,…
Out of Scope Changes check Passed The changes stay within issue #624. The shared layout model, API and repository methods support the new row-selective read. The Android TV sync and focused tests implement and verify the required beha…
Description check Passed The pull request description directly explains the Android TV Watch Next sync changes, the memory problem, the API approach, validation results, risks, and scope.
Full details: Linked Issues check

Explanation

Issue #624 requires the Android TV Watch Next sync to avoid the full Home read and fetch only continue_watching and next_up. syncWatchNextHome reads getHomeLayout, filters those section types, and reads each selected row with getHomeSectionItems. It caps each row at SECTION_ROW_MAX_ITEMS, accepts empty rows, preserves tiles on failed reads, and rejects a row type change between requests. Focused tests cover these behaviors and the reported validation shows them passing.

Full details: Out of Scope Changes check

Explanation

The changes stay within issue #624. The shared layout model, API and repository methods support the new row-selective read. The Android TV sync and focused tests implement and verify the required behavior. No unrelated product behavior or build changes are identified.

Full details: Docstring Coverage

Explanation

Docstring coverage is 50.00% which is insufficient. 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 6 files.

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

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

@silo-triage silo-triage Bot added bug Something isn't working priority: P2 Limited scope, workaround exists, or polish labels Nov 1, 2026
@coderabbitai coderabbitai Bot added api-v2 API v2 / Huma program (epic silo-server#135) evidence-required Needs before-and-after evidence before the Evidence check passes impact: playback Can't play, stalls, or wrong media labels Nov 1, 2026
@feardubin feardubin changed the title fix(tv): read only Watch Next rows fix(tv): read only the Watch Next rows instead of all of Home Nov 1, 2026

@coderabbitai coderabbitai 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.

Actionable comments posted: 1


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: 06d2f111-cbe9-4112-864d-fe97da8c8219
Commits

Reviewing files that changed from the base of the PR and between 864cd1d and f35abf9.

Files selected for processing: 6
  • androidTvApp/src/androidMain/kotlin/org/siloserver/silo/tv/watchnext/WatchNextHomeSync.kt
  • androidTvApp/src/androidUnitTest/kotlin/org/siloserver/silo/tv/watchnext/WatchNextHomeSyncTest.kt
  • shared/src/commonMain/kotlin/org/siloserver/silo/model/section/SectionModels.kt
  • shared/src/commonMain/kotlin/org/siloserver/silo/network/api/SectionApi.kt
  • shared/src/commonMain/kotlin/org/siloserver/silo/network/apiv2/HomeSectionsV2Api.kt
  • shared/src/commonMain/kotlin/org/siloserver/silo/repository/SectionRepository.kt

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

@Quick104 Quick104 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.

Review of f35abf9. One finding, inline. I'm fixing it in a commit on this branch, so there's no need to change it yourself. The summary comes in a separate comment.

🤖 Claude Code (claude-opus-5-5)

An admin can change a section's type and keep its id. The sync mapped the
row read's cards with the type from the earlier layout read, so a section
changed to another recipe in between was published as Continue Watching or
Next Up. Return false instead, so the launcher keeps its tiles and the
next run reads a fresh layout.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@silo-kody

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

@macroscopeapp

macroscopeapp Bot commented Nov 1, 2026

Copy link
Copy Markdown

WatchNextHomeSync.kt now caps each synced section at 20 programs, whereas the previous sync could publish more on servers without the row limit. This can change which tiles appear in the Android TV launcher’s Watch Next row; the Evidence section has no before-and-after captures of that case. Please add captures of the same launcher row with the same data showing the over-20 result before and after, and identify the device and build or commit. The reported four-program emulator comparison and request-size results do not show this visible difference. The phone, tablet, and folded/open foldable are not reached because this sync runs only in the TV app.

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

Posted via Macroscope — Visible change evidence

@Quick104

Quick104 commented Nov 1, 2026

Copy link
Copy Markdown
Contributor

Maintainer review summary

Reviewed head: c3902a6 (f35abf9 plus one review fix).

Fit: 8/10 · Readiness: 9/10 — conditional (assuming CI is green)

Fit 8. The change fixes a real out-of-memory crash on low-memory TVs at the right boundary. The sync reads the layout and then only the two rows it mirrors, and it adds no setting and no server change. One point is held back for app parity: the tvOS Top Shelf extension does the same full Home read (TopShelfHTTPClient.swift), and no Apple issue or PR tracks it yet. I recommend opening one.

Readiness 9. The server contract matches. getHomeLayout and getHomeSectionItems resolve the same rows as listHomeSections, including the injected Next Up row, and the cross-row dedupe that only the list applies doesn't touch Continue Watching or Next Up. The PR's tests detect the bug: with only WatchNextHomeSync.kt reverted to main, 12 of the 14 sync tests fail because the old sync requests /api/v2/home/sections.

Addressed

  • A section whose type changed between the layout read and its row read could be published as Continue Watching or Next Up. This was fixed in c3902a6 with a test that failed without the fix.
  • CodeRabbit's item_limit suggestion: the author's reply is correct, and CodeRabbit withdrew it.

Left for the maintainers

  • On a restricted profile, the single-row read can choose slightly different Next Up cards from the capped list. The list caps a row before access filtering, and the single-row read caps after it. Tiles stay stable from run to run, so this doesn't block the PR. It's a server selection detail.
  • Follow-ups, none tracked yet: the player's On Deck load in TvPlayerViewModel still reads all of Home when playback starts. Sending item_limit on single-row reads needs row_item_limit_max support.

Validation

  • Validated features: no v1.0 validation task covers the Watch Next sync. The tiles it publishes are unchanged.
  • Not reproduced live. Nothing was run on a Fire TV device, and this review ran unit tests only.
  • User manual: unaffected. No siloserver.org page covers Watch Next.

Evidence: https://evidence.siloserver.org/r/silo-android/pr-775/

🤖 Claude Code (claude-opus-5-5)

@Quick104
Quick104 merged commit 6b61cc5 into Silo-Server:main Nov 1, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api-v2 API v2 / Huma program (epic silo-server#135) bug Something isn't working evidence-required Needs before-and-after evidence before the Evidence check passes impact: playback Can't play, stalls, or wrong media 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] Android TV Watch Next sync reads all of Home every hour, including during playback

2 participants