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
perf(player): cache profile preferences and defer startup preview and next-episode reads - #129
Each time the Roku player opened a title, it waited on /settings/effective before starting playback and immediately issued trickplay preview and next-episode requests alongside the first media segments.
Approach
Cache parsed playback preferences and buffering mode on m.global.playbackPreferencesCache, keyed by server origin and profile ID with a 5-minute TTL (PREFERENCES_CACHE_TTL_MS = 300000). A fresh cache entry satisfies start immediately while the background refresh still runs to pick up changes; temporary/external playback identities skip the cache.
Defer followPreviews and resolveNext during initial planLoaded until onVideoState reports the first frame (m.titlePlayed), keeping startup network bandwidth and SceneGraph task slots free for initial stream segments.
Validation
BrightScript lint and transpile (npm run lint, covering bsconfig.json and bsconfig.dev.json with warnings-as-errors): passed.
Sideloaded onto a physical Roku TV and verified playback startup against a live server.
Evidence
No visual UI changes; verified via lint/transpile and device sideload on commit 215a03b4:
npm run lint: 0 errors, 0 warnings across both bsconfig.json and bsconfig.dev.json.
Sideloaded and tested playback startup on a physical Roku TV; playback starts immediately with cached preferences and loads seek previews and next-episode metadata once playback begins.
Risks
If a viewer edits playback preferences on another client and starts a new title on Roku within the 5-minute cache window, the cached preference applies for the initial start while the background refresh updates m.preferences and cache on response.
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 how I checked a change nobody sees.
Council review
Rounds: 3, last reviewed at the round-2 fix head; round-3 fixes end at c907d762.
Member
Round 1
Round 2
Round 3
Sol (gpt-6.2-sol, medium)
7/10
8/10
9/10
Opus (claude-opus-5-5, medium)
7/10
8.5/10
9/10
Gemini (gemini-4-neon, medium)
4/10
9.5/10
9/10
Visual review: not run; nothing changes on screen. Fixed in review: wall-clock expiry, buffering mode cached from its own answer, failed refresh keeps preferences, cache cleared on local writes and sign-out with the account in its key, skip intervals applied on a hit, autoplay toggle kept over a late answer. Round 3: one helper clears the preferences cache.
Adversarial review: see Council review above; review fixes by Claude Code (claude-opus-5-5) in T3 Code
Note
Clear playback preferences cache in AppScene.forgetSidecars on sign-out
Adds the global playback-preferences cache to the cleanup in AppScene.bs. When the session is not signed in, AppScene.forgetSidecars now resets this cache alongside the existing sidecar and refused-subtitle cache resets.
No actionable comments were generated in the recent review.
Walkthrough
The player caches playback preferences for eligible profiles and applies fresh cached settings while refresh requests proceed. It also defers preview-file handling and next-item resolution until the first frame.
Changes: Playback preferences and startup
Layer / File(s)
Summary
Cache and apply playback preferences components/player/Player.bs, source/playback/preferencesCache.bs, components/AppScene.bs, components/screens/settings/SettingsScreen.bs
The player caches preferences and buffering mode by server, account, and profile. It applies fresh matching entries, retains cached preferences after failed refreshes, and clears the cache in sign-out, settings-save, and autoplay-write paths.
Defer plan operations components/player/Player.bs
Before the first frame, the player records preview-file handling and next-item resolution as pending. It processes those operations on the first frame.
The probe adds preference-read, response, and inspection hooks. Tests cover cache reuse, failed refreshes, and stale or future timestamps. The headless test shard includes the new spec.
sequenceDiagram
participant Player
participant PreferenceCache
participant PreferencesAPI
Player->>PreferenceCache: Check matching fresh preference values
Player->>PreferencesAPI: Request uncached preference values
PreferencesAPI->>Player: Return preference or buffering-mode response
Player->>PreferenceCache: Save successful response values
Loading
Possibly related PRs
Silo-Server/silo-roku#24: Both changes address how preference responses are applied during a Watch Party.
Merge Risk: Minimal · up to c907d
This change speeds up Roku playback startup by caching profile preferences for five minutes and deferring preview and next-episode loading until the first frame. No new blocking risk was found. Changes made on another device may take up to five minutes to appear.
Security architecture risk: Minimal · up to c907d
A delayed preference response can no longer put the old Auto-play next value back into the shared cache after that Player changes it. Roku can still start with recently cached preferences after a change on another client; that is the stated startup tradeoff.
Security review details
Security Blast Radius
inferred — The earlier race affected later playback on the same Roku app for the matching server, account, and profile. Its consequence was an incorrect autoplay preference, not a change to server permissions.
Trust Boundaries and Controls
observed — Player only reuses an entry whose key matches the active server origin, account, and profile. It bypasses the cache for borrowed playback identities or when any key component is missing.
Dependencies
observed — Player reads effective values with profile authentication. Its Auto-play next write uses the profile-device settings scope.
Data and control flow
observed — A local Auto-play next toggle updates Up Next immediately, then invalidates the shared preference cache before sending the settings write.
Resilience and Maintainability Implications
observed — A failed refresh leaves preferences already loaded from a fresh cache in effect for that Player; without such an entry, the failed read uses defaults. A failed Auto-play next write is logged and does not roll back the current Player's choice. The cache invalidation prevents the earlier stale-response race but does not guarantee that the server saved the choice.
Pre-merge checks: 4
Check name
Status
Explanation
Title check
The title describes the main change: caching profile playback preferences and deferring startup preview and next-episode reads in the Roku player. The changeset implements both parts (Player.bs cache …
Linked Issues check
Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check
Check skipped because no linked issues were found for this pull request.
Description check
The description is related to the changeset. It explains the problem (Roku playback startup waited on /settings/effective and issued preview and next-episode requests early), the caching approach with…
Full details: Title check
Explanation
The title describes the main change: caching profile playback preferences and deferring startup preview and next-episode reads in the Roku player. The changeset implements both parts (Player.bs cache and deferred followPreviews/resolveNext, plus supporting cache invalidation in AppScene and SettingsScreen and new tests).
Full details: Description check
Explanation
The description is related to the changeset. It explains the problem (Roku playback startup waited on /settings/effective and issued preview and next-episode requests early), the caching approach with a 5-minute TTL on m.global.playbackPreferencesCache, the deferral of followPreviews and resolveNext until the first frame, validation steps, and the risk of cross-device preference changes within the cache window. It is specific and matches the summarized file changes, so it is not off-topic or vague.
Finishing Touches
Generate unit tests (beta)
Commit to this branch
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
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: 22922f5a-fd80-474d-8a5b-a135ef6f0523
Commits
Reviewing files that changed from the base of the PR and between 9d6e509 and c907d76.
Files selected for processing: 4
components/AppScene.bs
components/player/Player.bs
components/screens/settings/SettingsScreen.bs
source/playback/preferencesCache.bs
Included review availability: This review used your included allowance. 0 included reviews remain after this review. Your included PR review attempts over the past 7 days set your current allowance at 1 review per hour.
if cacheKey <> "" and m.global <> invalid and m.global.hasField("playbackPreferencesCache")
entry = m.global.playbackPreferencesCache
if util.isObject(entry) and entry.key = cacheKey and util.isNumber(entry.cachedAt) and m.env.now() - entry.cachedAt < PREFERENCES_CACHE_TTL_MS and util.isObject(entry.preferences)
The reason will be displayed to describe this comment to others. Learn more.
Use a shared clock for cross-player cache expiration
After leaving playback and opening another title, this comparison uses timestamps from different clocks: each Player.init() creates a new roTimespan, while cachedAt survives on m.global. The new player's elapsed time starts near zero, so subtracting the previous player's timestamp normally produces a negative age, even if the viewer spent hours browsing between titles. Consequently, expired preferences still bypass the startup wait, and settings such as audio language and bitrate cap can start playback with arbitrarily stale values. Store and compare timestamps using an application-wide clock or wall-clock time instead.
The reason will be displayed to describe this comment to others. Learn more.
Confirmed and fixed in a8fb9d9: each part of the entry is stamped with m.env.epoch() (wall-clock seconds), and an entry is fresh only while 0 <= age < 300. tests/player/preferencesCache.spec.bs covers it and fails with the fix reverted.
The reason will be displayed to describe this comment to others. Learn more.
Apply cached skip intervals to the controls before starting
When a cache hit allows playback to start before the background preferences request finishes, only m.preferences and autoplay are restored here. The controls reducer and overlay retain their default 10-second back/30-second forward intervals; their only preference updates occur in onPreferences(). A viewer with cached custom intervals therefore gets incorrect seek distances until that request completes, despite the preferences already being available locally. Apply the cached skip intervals to both the overlay and controls reducer when accepting the cache entry.
File: No configuration file from this repository applied
Commit: Unavailable
Layers: Organization UI
Review profile: CHILL
Plan: Advanced
Run ID: 5c9135c0-0cdc-4319-b33b-5f14ba85d3c8
Commits
Reviewing files that changed from the base of the PR and between 8e8628e and 215a03b.
Files selected for processing: 1
components/player/Player.bs
Included review availability: This review used your included allowance. 0 included reviews remain after this review. Your included PR review attempts over the past 7 days set your current allowance at 1 review per hour.
The reason will be displayed to describe this comment to others. Learn more.
Independently tested 215a03b4 against 8e8628ed9c on a Roku Ultra. Median title request to first frame was 1,653 → 1,244 ms cold and 1,217 → 916 ms warm (4 trials per revision and phase).
A failed background refresh discards preferences that were already applied. In a focused player test, I applied autoSkipRecap=true and returned HTTP 503 from the background read. The player parsed defaults and turned off recap skipping mid session. On a refresh failure, retain the last applied preferences. Use defaults when no preferences have been loaded. Refresh handler
The same harness reproduced the clock problem in the existing expiration thread. It also verified that a different profile and a borrowed identity bypass the cache, and that trickplay and Next Up requests start after the first frame and accept their fixture responses.
AI-assisted validation · Codex (gpt-6.2-sol, xhigh) in T3 Code.
The cache entry was stamped with the player's own roTimespan, which
restarts at zero in every player, so the next player saw a negative age
and took preferences of any age. Each part now carries the wall-clock
second its own answer came, and an entry from the future (a clock that
went back) is stale too.
The buffering mode was cached only when the preferences answered, so it
held the default (or an older cached mode) whenever the preferences won
the race, with a fresh stamp each time. It is now cached from its own
answer, under its own stamp.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A player that started from cached preferences still refreshes them, and
a failed refresh (a 503 or a timeout) replaced them with the defaults
mid-session: autoplay, the skip modes, and the skip intervals went back
to the manifest's. The session now keeps what it already read and uses
the defaults only when nothing was read.
A cache hit also left the overlay and the controls reducer on the
default 10 s and 30 s skip intervals until the refresh answered; it now
applies the cached intervals the way an answer does.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A player opened within five minutes of a change in Settings, or of the
player's own Auto-play next toggle, started with the preferences cached
before it: the old quality, bitrate cap, languages, and buffering mode
for the whole first title. Those writes now clear the cache, and so
does a session that is no longer signed in, as the sidecar caches are
cleared. The key also names the account.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Two players sharing m.global: the second starts from the first's
preferences and buffering mode with its skip intervals applied, keeps
them over a failed refresh, and reads again over an entry past the time
limit or stamped ahead of the clock. The spec runs in the small
player-credits shard; the player shard sits at its heap limit.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 215a03b4. The inline finding is new; the clock, buffering-mode, and skip-interval threads are answered in place. The earlier validation review's point about a failed background refresh (HTTP 503) replacing applied preferences with defaults also holds: playback.preferences.parse(invalid) applies defaults mid-session. I'm fixing it so a failed refresh keeps preferences already read.
For the maintainers: preferences changed on another device still aren't seen by a player opened within the 5-minute window. That is how the cache in this PR works, and these fixes don't change it.
A local Auto-play next write can leave the cache holding the old value even after the server accepts the write. Player clears the cache before sending the write, but a refresh already in flight can publish a pre-write value with a fresh timestamp, and the write acknowledgment does not invalidate it. The current player's explicit choice is protected by m.autoplayChosen; a newly opened player does not inherit that guard. It can start with the old value and keep it for that playback if its refresh fails. This is distinct from the accepted delay for edits made on another client.
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: a8ff7b6c-4a5c-4a8f-83c2-11ee646fb42d
Commits
Reviewing files that changed from the base of the PR and between 215a03b and 9d6e509.
Files selected for processing: 7
components/AppScene.bs
components/player/Player.bs
components/screens/settings/SettingsScreen.bs
scripts/test-headless.py
tests/components/PlayerProbe.bs
tests/components/PlayerProbe.xml
tests/player/preferencesCache.spec.bs
Included review availability: This review used your included allowance. 0 included reviews remain after this review. Your included PR review attempts over the past 7 days set your current allowance at 1 review per hour.
The reason will be displayed to describe this comment to others. Learn more.
Minor · Data Integrity & Integration · Quick win
A late preference response can be cached under the next profile's key.
The cache key is computed when the response is saved, not when the request starts. If the response callback runs after the active profile changes to profile B, savePreferencesCache stores profile A's preferences under profile B's key. The next Player for profile B then accepts them for up to five minutes.
Bind each cache write to the identity that issued its request. Capture the key when the request starts, and do not write a response under a different key when the callback runs.
Where the key is computed
components/player/Player.bs:707 computes the key inside savePreferencesCache.
components/player/Player.bs:764 saves the response from onPreferences.
Toggling autoplay cleared the cache, but a background preferences read already in flight then saved the server's pre-toggle value back into it, so the next player started with the old setting. That answer now keeps the toggle and leaves the cache empty.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Preferences changed on another device aren't seen by a player opened within the 5-minute window. That's how this cache works.
Settings clears the cache on every setting write, not only playback ones.
Council
Member
Round 1
Round 2
Sol (gpt-6.2-sol, medium)
7/10
8/10
Opus (claude-opus-5-5, medium)
7/10
8.5/10
Gemini (gemini-4-neon, medium)
4/10
9.5/10
Fit is 8: it matches the other apps' start-without-waiting behavior. Readiness is 8: the fixes are covered by tests and the earlier device run measured the gain. A device pass on the fixed head hasn't been done.
Settings, the player's autoplay write, and sign-out each emptied
m.global.playbackPreferencesCache with their own copy of the same line.
They now call playback.preferencesCache.forget, so a change to the
cache's field or shape is made once.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Fit: 8/10 · Readiness: 8/10 — conditional (assuming CI is green)
What changed since the last summary
One clear for the preferences cache. Settings writes, the player's autoplay toggle, and sign-out all clear it through playback.preferencesCache.forget.
Checks. Lint, format, and 3,885 headless tests pass.
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
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
Related issue: N/A
Other clients: Apple Silo-Server/silo-apple#1360; Android Silo-Server/silo-android#1135; Roku (this PR); Web Silo-Server/silo-server#5849
Each time the Roku player opened a title, it waited on
/settings/effectivebefore starting playback and immediately issued trickplay preview and next-episode requests alongside the first media segments.Approach
m.global.playbackPreferencesCache, keyed by server origin and profile ID with a 5-minute TTL (PREFERENCES_CACHE_TTL_MS = 300000). A fresh cache entry satisfies start immediately while the background refresh still runs to pick up changes; temporary/external playback identities skip the cache.followPreviewsandresolveNextduring initialplanLoadeduntilonVideoStatereports the first frame (m.titlePlayed), keeping startup network bandwidth and SceneGraph task slots free for initial stream segments.Validation
npm run lint, coveringbsconfig.jsonandbsconfig.dev.jsonwith warnings-as-errors): passed.Evidence
No visual UI changes; verified via lint/transpile and device sideload on commit
215a03b4:npm run lint: 0 errors, 0 warnings across bothbsconfig.jsonandbsconfig.dev.json.Risks
If a viewer edits playback preferences on another client and starts a new title on Roku within the 5-minute cache window, the cached preference applies for the initial start while the background refresh updates
m.preferencesand cache on response.Checklist
Council review
Rounds: 3, last reviewed at the round-2 fix head; round-3 fixes end at
c907d762.Visual review: not run; nothing changes on screen. Fixed in review: wall-clock expiry, buffering mode cached from its own answer, failed refresh keeps preferences, cache cleared on local writes and sign-out with the account in its key, skip intervals applied on a hit, autoplay toggle kept over a late answer. Round 3: one helper clears the preferences cache.
Evidence: https://evidence.siloserver.org/r/silo-roku/pr-129/
AI Disclosure
Note
Clear playback preferences cache in
AppScene.forgetSidecarson sign-outAdds the global playback-preferences cache to the cleanup in AppScene.bs. When the session is not signed in,
AppScene.forgetSidecarsnow resets this cache alongside the existing sidecar and refused-subtitle cache resets.Macroscope summarized c907d76.