Repository navigation
fix(tv): read only the Watch Next rows instead of all of Home - #775
Conversation
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 Kody — review completeReview finished. Check the inline comments for findings and verify each suggestion against the code and tests. Reviewing changes in Silo
Review settingsReview OptionsThe following review options are enabled or disabled:
|
|
No actionable comments were generated in the recent review.
|
| 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
Possibly related PRs
- Silo-Server/silo-android#688: Defines the Home-row item cap that this change applies to fetched Watch Next rows.
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,sharedArchitecture 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
HomeLayoutRowwithidandsectionTypefields to represent a Home layout row without its cards. - observed — Modified behavior in shared/src/commonMain/kotlin/org/siloserver/silo/network/api/SectionApi.kt:
SectionApiaddsgetHomeLayout, delegating the owner-scoped request tohome.layout. - observed — Modified behavior in shared/src/commonMain/kotlin/org/siloserver/silo/network/apiv2/HomeSectionsV2Api.kt: Added the
HomeLayoutRowimport. - observed — Modified behavior in shared/src/commonMain/kotlin/org/siloserver/silo/network/apiv2/HomeSectionsV2Api.kt: Added
decodeHomeLayoutV2, which requires asectionsarray, extracts stringidandsection_typevalues from each row, rejects missing or blank identities, and returnsHomeLayoutRowentries.
-
Pre-merge checks: 
4 · 
1
-
Failed checks: 1 warning Passed checks: 4 passed-
Full details: Linked Issues check
-
Explanation
Issue
#624requires the Android TV Watch Next sync to avoid the full Home read and fetch onlycontinue_watchingandnext_up.syncWatchNextHomereadsgetHomeLayout, filters those section types, and reads each selected row withgetHomeSectionItems. It caps each row atSECTION_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
There was a problem hiding this comment.
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
Files selected for processing: 6-
androidTvApp/src/androidMain/kotlin/org/siloserver/silo/tv/watchnext/WatchNextHomeSync.ktandroidTvApp/src/androidUnitTest/kotlin/org/siloserver/silo/tv/watchnext/WatchNextHomeSyncTest.ktshared/src/commonMain/kotlin/org/siloserver/silo/model/section/SectionModels.ktshared/src/commonMain/kotlin/org/siloserver/silo/network/api/SectionApi.ktshared/src/commonMain/kotlin/org/siloserver/silo/network/apiv2/HomeSectionsV2Api.ktshared/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.
-
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 — review completeReview finished. Check the inline comments for findings and verify each suggestion against the code and tests. Reviewing changes in Silo
Review settingsReview OptionsThe following review options are enabled or disabled:
|
|
Automated check: Macroscope check run agent (gpt-6-luna). Evidence was not reviewed for correctness. Posted via Macroscope — Visible change evidence |
Maintainer review summaryReviewed 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 ( Readiness 9. The server contract matches. Addressed
Left for the maintainers
Validation
🤖 Claude Code (claude-opus-5-5) |
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.OutOfMemoryErrorinStringFactory.newStringFromChars. Each time, the server logged a backgroundGET /api/v2/home/sectionsof 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 (
TvPlayerViewModelreads 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'sidandsection_typewithout cards, then reads only thecontinue_watchingandnext_uprows throughGET /api/v2/home/sections/{id}/items. It never callsGET /api/v2/home/sections.HomeSectionsV2Api.layout(),SectionApi.getHomeLayout()andSectionRepository.getHomeLayout()read the layout. They live inshared/with the rest of the section API; only the TV Watch Next sync calls them.SECTION_ROW_MAX_ITEMS(20) cards per row, the same cap a Home row draws.total_countstays above zero, and that must not block the other rows' tiles.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/layouthas existed since the v2 API migration.Validation
./gradlew testDebugUnitTeston f35abf9: passed, 6,657 tests, 0 failures.android-shared,androidAppandandroidTvApp, pluslintVitalReleasefor both apps, on f35abf9: passed.:androidTvApp:assembleDebugand:androidApp:assembleDebugon 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 onlyWatchNextHomeSync.ktis reverted tomain. The two new regression tests (row cap, empty row) fail on this PR's first revision and pass now.main). This change touches no build or workflow files.falsewhen a row read'ssection_typediffers from the layout entry's, because an admin can change a section's type and keep its id. The new testaRowWhoseTypeChangedAfterTheLayoutKeepsEveryTilefailed without the fix and passes with it;WatchNextHomeSyncTestis 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:
WatchNextHomeSyncTeston f35abf9: 14 tests, 0 failures. It fails if the sync requests/api/v2/home/sections. It checks that onlycontinue_watchingandnext_uprows 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.WatchNextHomeSync.kt: 7 of the earlier 9 fail. The two new regression tests (row cap, empty row) fail on this PR's first revision.testDebugUnitTeston f35abf9: 6,657 tests, 0 failures, 0 skipped.body_bytes, HTTP 200):listHomeSectionsmedian 973,940 bytes (p95 1,021,683);getHomeLayoutmedian 56,788;getHomeSectionItemsmedian 28,526 (all row types mixed, so this is indicative, not a paired measurement).864cd1d6f) vs fixed (f35abf912), same test account. Image: x86_64 Android TV API 36, 1,536 MB RAM, effective heap 384 MB. Builds: minifiedassembleRelease, signed with the debug key.watch_next_sync_periodictriggered on demand, both builds published the same 4 Watch Next programs (content://android.media.tv/watch_next_program).listHomeSectionscall, 687,215 bytes. The fixed build made onegetHomeLayoutcall, 4,216 bytes, and threegetHomeSectionItemscalls, 4,377 + 189 + 1,605 bytes. It made nolistHomeSectionscall. The foreground Home screen still uses that endpoint, as before.OutOfMemoryErrorwas 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
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.section_item_limit_max, the old sync could publish more than 20 tiles per row; it now publishes at most 20, matching Home.false, keeps the tiles, and retries on the next run.Checklist
AI Disclosure
🤖 Generated with Claude Code
Note
Fix TV Watch Next sync to fetch only Watch Next rows, not all of Home
...
Macroscope summarized c3902a6.