Skip to content

perf(player): cache profile preferences and defer startup preview and next-episode reads - #129

Merged
Quick104 merged 7 commits into
mainfrom
perf/stream-start-speedup
Dec 6, 2026
Merged

Quick104 merged 7 commits into
mainfrom
perf/stream-start-speedup

Conversation

@Quick104

@Quick104 Quick104 commented Dec 4, 2026 •

Copy link
Copy Markdown
Contributor

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/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.

Evidence: https://evidence.siloserver.org/r/silo-roku/pr-129/

AI Disclosure

  • Harness: Antigravity (T3 Code)
  • Tool(s): T3 Code, Antigravity agent
  • Model(s): gemini-4-neon
  • Involvement: AI-assisted
  • 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.

Macroscope summarized c907d76.

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

coderabbitai Bot commented Dec 4, 2026 •

Copy link
Copy Markdown

Explain Change →

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.
Verify playback preference caching
tests/components/PlayerProbe.bs, tests/components/PlayerProbe.xml, tests/player/preferencesCache.spec.bs, scripts/test-headless.py
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.

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

Change: Refactor

Sequence Diagram(s)

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

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: Passed 4

Check name Status Explanation
Title check Passed 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 Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Description check Passed 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.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Dec 4, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-12-06T03:54:07.223323Z c907d76 New commits
🔒 Security Review ✅ Completed 2026-12-06T03:55:17.319043Z c907d76 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 215a03b4fa

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread components/player/Player.bs Outdated
cacheKey = preferencesCacheKey()
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)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge 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.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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.

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

Comment thread components/player/Player.bs Outdated
Comment on lines +661 to +664
m.preferences = entry.preferences
m.preferencesRead = true
if not m.autoplayChosen then setAutoplay(m.preferences.autoPlayNext)
if util.isString(entry.bufferingMode) and entry.bufferingMode <> "" and not inParty() then m.bufferingMode = entry.bufferingMode

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge 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.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in cbd72f5: a cache hit calls applySkipSeconds(), the same path onPreferences uses, so the overlay and controls get the cached intervals.

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

@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

Minor 2
  1. Use one clock basis for cache timestamps across Player instances.
  2. Cache the buffering mode only from its own response.
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: 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.

Comment thread components/player/Player.bs Resolved
Comment thread components/player/Player.bs Resolved

@Quick104 Quick104 left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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.

Quick104 and others added 4 commits December 6, 2026 00:28
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>

@Quick104 Quick104 left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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.

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

Comment thread components/player/Player.bs Resolved
@silo-triage silo-triage Bot added size/L 200–499 added + deleted lines (all files); change volume, not priority. and removed size/M 50–199 added + deleted lines (all files); change volume, not priority. labels Dec 6, 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

Minor 2
  1. Reject cache writes from reads started before invalidation.
  2. A late preference response can be cached under the next profile's key.
Trivial 1
  1. 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.

' Keeps part, the preferences or the buffering mode as its own answer gave
' it, in this profile's entry beside the other part.
sub savePreferencesCache(part as Object)
cacheKey = preferencesCacheKey()

Copy link
Copy Markdown

Choose a reason for hiding this comment

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.

Comment thread components/player/Player.bs Resolved
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>
@Quick104

Quick104 commented Dec 6, 2026

Copy link
Copy Markdown
Contributor Author

Review summary

Reviewed head: bf9ff3fc.

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

What changed in review

  • Expiry: the cache expires by the wall clock, which every player shares.
  • Buffering mode: cached from its own answer.
  • Failed refresh: keeps preferences already applied.
  • Invalidation: the cache is cleared on local settings writes, the autoplay toggle, and sign-out, and its key includes the account.
  • Skip intervals: cached ones are applied on a hit.
  • Autoplay: a toggle made before the background read returns is kept, and that read doesn't refill the cache.
  • Checks: lint, format, and the headless tests pass. The new cache tests fail with each fix reverted.

Evidence: https://evidence.siloserver.org/r/silo-roku/pr-129/

Left for the maintainers

  • 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.

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

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

Quick104 commented Dec 6, 2026

Copy link
Copy Markdown
Contributor Author

Review update

Reviewed head: c907d762.

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.

Evidence: https://evidence.siloserver.org/r/silo-roku/pr-129/

Council

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

Readiness stays 8 until a Roku device pass on this head.

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

@Quick104
Quick104 merged commit be84365 into main Dec 6, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/L 200–499 added + deleted lines (all files); change volume, not priority.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant