Skip to content

fix(player): refresh direct-play credentials without reloading the player - #759

Merged
Quick104 merged 2 commits into
mainfrom
fix/direct-play-credentials
Oct 13, 2026
Merged

Quick104 merged 2 commits into
mainfrom
fix/direct-play-credentials

Conversation

@Quick104

@Quick104 Quick104 commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Related issue: N/A (split from #611)
Validation tasks: none

Direct play reloads the player every time the access token rotates. Server HLS with video gets a per-request credential resolver, so it picks up the new token on its next request. Direct play opens with static headers. After the next successful progress report, the app sees that the Authorization header changed and reloads the whole player at the current position. Viewers see a stall and a rebuffer at each rotation.

Approach

This PR passes the same resolver to direct play when the media has video (original_http and server_remux_progressive), so the engine can ask for current headers on each range request. Server HLS with video behaves as before. Audio-only media, whether server HLS or progressive, still gets no resolver. It keeps its opening headers and the existing reload-after-rotation and 401-reload paths, as #346 intended. A new AetherAuthenticationRecoveryPolicy.resolvesRequestCredentials(delivery:hasVideo:) holds this rule. AetherLoadSpec and PlayerViewModel both call it, so the load options and the resolver they build stay in agreement.

Do not merge this alone. At main's AetherEngine pin (87f85740), the engine ignores httpRequestAuthorization for direct media. Once a direct-play spec carries a resolver, the app skips its reload-after-rotation and 401-reload paths, because both require httpRequestAuthorization == nil. Merged on its own, this change would leave direct play using expired headers with no recovery.

Dependencies

Validation

  • AetherPlaybackBoundaryTests on an iOS 27 simulator (scheme Silo, -only-testing:SiloTests/AetherPlaybackBoundaryTests): 63 tests, 0 failures.
  • AetherPlaybackBoundaryTests on a tvOS 27 simulator (scheme SiloTV, -only-testing:SiloTVTests/AetherPlaybackBoundaryTests): 64 tests, 0 failures.
  • xcodebuild build -scheme SiloMac -destination platform=macOS CODE_SIGNING_ALLOWED=NO: build succeeded.
  • New tests: testMediaWithVideoResolvesCredentialsButAudioOnlyKeepsReloadPath checks the rule for all four deliveries, with and without video. testDirectPlayWithVideoResolvesCredentialsPerRequest builds a direct-play AetherLoadSpec from the v2 fixture and checks that the resolver is attached when the media has video and left off when it is audio-only. On main the direct-play spec with video gets no resolver, so the second test fails there.
  • Sandbox run (2-minute access tokens, iPhone 17 Pro simulator on iOS 27.0, direct play of a 1080p H.264 MKV), same steps for both builds:
    • PR base b6412ed: the token refresh reloaded the plan at the same moment; the picture jumped back 2.4 s and froze for 2.6 s, and the engine downloaded the file again.
    • This branch at b8b6f6c: no reload and no freeze at the refresh. The engine had already cached the whole file, so it sent nothing with the expired token.
  • AetherPlaybackBoundaryTests at b8b6f6c on an iOS 27.0 simulator: 63 tests, 0 failures.
  • Not verified: the credential refresh itself on direct play. At main's engine pin the direct-play reader keeps its opening headers, so a range request after the token expires (a file larger than the engine's cache, or a slower link) would get a 401, and this branch no longer reloads to recover. That needs AetherEngine#12 and the pin bump.

Risks

  • Merging before the engine pin bump breaks direct-play recovery after token rotation, as described above.
  • Audio-only server HLS and audio-only progressive media are deliberately unchanged and still reload after rotation.

Evidence

Evidence: https://evidence.siloserver.org/r/silo-apple/pr-759/

During direct play, an access-token refresh no longer reloads the player. On the PR base, the refresh reloads the plan: the picture jumps back 2.4 s and freezes for 2.6 s. On this branch, playback continues through the refresh. The page has before and after recordings from the same simulator, title and start point, with app and server log excerpts.

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 (in T3 Code), with Claude Code subagents
  • Tool(s): Claude Code
  • Model(s): claude-opus-5-5
  • Involvement: Fully AI-generated, not yet human verified
  • Adversarial review: gpt-6.1-sol (Codex harness in T3 Code) reviewed c92734f and found no issues. A Claude Code /silo review (claude-opus-5-5) ran the sandbox captures and added the b8b6f6c cleanup.

🤖 Generated with Claude Code

Note

Fix direct-play credential refresh to cover all video Protocol V3 delivery modes

Adds AetherAuthenticationRecoveryPolicy.resolvesRequestCredentials in AetherLoadSpec.swift as a shared predicate. It returns true for media with video in any of the four Protocol V3 delivery modes (original HTTP, progressive remux, remux HLS, transcode HLS).

  • Replaces the narrower server-HLS-only and remux-HLS/transcode-HLS conditions in the AetherLoadSpec initializer and the Protocol V3 request-authorization builder in PlayerViewModel.swift with this shared policy.
  • Audio-only media keeps its existing opening-header authentication path and gets no request-authorization provider.
  • Adds boundary tests covering all four delivery modes for both media kinds.
  • Behavioral Change: authenticated video original-HTTP and progressive-remux playback now resolves credentials per request, so expired credentials refresh without a player reload; audio-only behavior is unchanged.

Macroscope summarized c92734f.

…ayer

Direct play opens with static headers, so every access-token rotation
forces a full player reload at the current position after the next
successful progress report. Server HLS with video already resolves the
current credential for each request.

Pass the request-authorization resolver to direct play with video
(original_http and server_remux_progressive) as well as to server HLS
with video. Audio-only media, HLS or progressive, still gets no
resolver and keeps its existing reload-after-rotation and 401-reload
recovery. AetherAuthenticationRecoveryPolicy.resolvesRequestCredentials
holds the rule for both the load spec and the player view model.

Not safe to merge on its own: the AetherEngine pin on main ignores the
resolver for direct media, while a spec that carries one skips the
app's reload recovery. This needs an engine pin that includes
Silo-Server/AetherEngine#12 first.

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

silo-kody Bot commented Oct 13, 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 Oct 13, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 14 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: b988fbb2-a68b-43c9-a824-aea9a08d2bb3
📥 Commits

Reviewing files that changed from the base of the PR and between b02d55a and b8b6f6c.

📒 Files selected for processing (3)
  • iosApp/Tests/AetherPlaybackBoundaryTests.swift
  • iosApp/iosApp/Screens/Player/AetherLoadSpec.swift
  • iosApp/iosApp/Screens/Player/PlayerViewModel.swift
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@silo-triage silo-triage Bot added 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 needs-review Needs maintainer review to resolve uncertain classification, scope, or changed evidence. priority: P1 Core-path bug; painful workaround — next after P0 labels Oct 13, 2026
@silo-triage

silo-triage Bot commented Oct 13, 2026

Copy link
Copy Markdown

Evidence is currently descriptive only. Because this changes user-visible direct-play behavior, add before/after evidence for the same playback flow and data, naming the platform and build; include a short recording covering token rotation and the resulting playback behavior. A published Evidence link is acceptable. Do not merge this PR until AetherEngine#12 is merged and the Apple dependency pin is updated.

…tials

resolvesRequestCredentials listed the same four deliveries that
PlaybackProtocolV3.PlanDelivery.supported already holds. Use the set so
the rule follows the canonical list. No behavior change: both callers
only see plans that already passed the supported-delivery check.

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

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

Review of c92734f. Two findings are on the diff below. The first is the merge gate the description already names, with what a sandbox run showed.

Low, rare path, needs your call: scrub previews keep the opening headers. AetherScrubPreviewProvider.activate and begin build the FrameExtractor from spec.options.httpHeaders. Before this PR, the rotation reload re-ran activate(spec) with fresh headers. With that reload gone for direct play with video, nothing refreshes them, and AetherEngine#12 also leaves scrub thumbnails on static headers. The extractor only runs when engine.supportsCacheBackedStills is false, which for a remote software session means the engine's packet cache is unavailable (for example, the device is low on disk). The effect: scrub previews stop appearing once the opening token expires. Playback is not affected, and server HLS with video already has the same exposure. Options: resolve current headers when begin builds the extractor, or accept the gap and note it. I'm not changing this.

Checked and fine:

  • Subtitle sidecars and fonts on direct play now use the strict subtitle resolver. Every sidecar and font URL the server mints passes SubtitleScope, the same as server HLS today.
  • The resolver scope admits the direct-play URL the server mints (/api/v2/stream/<session>); the sandbox runs played original_http with it attached.
  • Android already refreshes credentials on every direct-play request (RefreshingHttpDataSource), so this change brings Apple closer to Android. No Android change is needed.

AI disclosure: written by Claude Code (claude-opus-5-5) running /silo review; the sandbox and simulator results above come from that run.

httpHeaders: effectiveHeaders,
httpRequestAuthorization: isServerHLS && plan.effectiveRecipe.videoCodec != nil
? requestAuthorization : nil,
httpRequestAuthorization: AetherAuthenticationRecoveryPolicy.resolvesRequestCredentials(

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.

High, disclosed: merging before the engine pin bump breaks token recovery for direct play.

At the pinned engine (87f85740), only the native remote-HLS stand-in reads httpRequestAuthorization. The direct-play AVIOReader keeps the headers it opened with. Attaching a resolver here turns off both app recovery paths for original_http and server_remux_progressive with video, because PlayerViewModel gates them on httpRequestAuthorization == nil (lines 1862 and 1912). A range request sent after the opening token expires gets a 401, attemptProtocolV3AuthenticationReload returns false, and the failure goes to the failure_recovery replan, which excludes the direct-play route.

On a sandbox with 2-minute access tokens (iPhone simulator, same title and start point for both builds):

  • PR base: the token refreshed at 17:26:39Z and the app reloaded the plan at that moment. The picture jumped back 2.4 s, froze for 2.6 s, and the engine downloaded the file again (67 range requests).
  • This branch: the token refreshed at 17:39:33Z with no reload and no freeze. The engine had already cached the whole 1.5 GB file, so it sent nothing with the expired token. A file larger than the engine's packet cache, or a slower link, would reach the 401 path above.

Repair: keep this unmerged until AetherEngine#12 is rebased and merged, and put the pin bump in this PR rather than a separate one. #12 is 472 commits behind the current pin and conflicts with engine main, so the rebase should cover readers added since its base. I'm not changing this here; it waits on the engine.

The new comments at lines 74-77 and in PlayerViewModel (1849-1850) describe the behavior after #12. Once the pin moves they hold, except for scrub thumbnails, which #12 leaves on static headers (see the review body).

@silo-kody

silo-kody Bot commented Oct 13, 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 ❌
⚠️ 3 Kody Rule(s) were not evaluated

These rules declare that they need repository context beyond this diff, and the review could not retrieve it, so they were not judged on this pull request:

  • Centralize server-relative authentication path validation
  • Enforce latest-link-wins centrally across deferred deep links
  • Rank subtitles using container capabilities and one stable cross-client policy

@Quick104

Copy link
Copy Markdown
Contributor Author

/silo review summary

Reviewed head: b8b6f6c (c92734f plus one cleanup commit from this review).

Fit: 9/10 · Readiness: 4/10 — not ready

Not ready because merging before AetherEngine#12 and an engine pin bump would leave direct play with video without working credential recovery. That is the dependency the description already names. The rest of the change is sound.

Findings

  • Merge gate (high, disclosed, open): thread on AetherLoadSpec.swift:510. Waits on AetherEngine#12, which needs a rebase (472 commits behind the current pin, conflicts with engine main), and on the pin bump, which should land in this PR.
  • Duplicated delivery list (low): fixed in b8b6f6c; thread resolved.
  • Scrub previews keep the opening headers (low, rare path, needs your call): in the review body. Not changed.

Verification

  • Sandbox run with 2-minute access tokens on an iPhone simulator, same title and start point for both builds. On the PR base, the token refresh reloads the player: the picture jumps back 2.4 s and freezes for 2.6 s. On this branch, playback continues with no reload. The Evidence link in the PR body has the recordings and log excerpts.
  • Not verified: the credential refresh itself on direct play. It can't run until the engine change lands. In the run on this branch, the engine had cached the whole file before the token expired, so it never sent the expired token.
  • AetherPlaybackBoundaryTests at b8b6f6c on an iOS 27.0 simulator: 63 tests, 0 failures.
  • CI: Evidence and test pass; the regression jobs are still running. Regression (SiloTV) is expected to fail until fix(tvos): build again after the On Deck focus change #773 merges (fix(tvos): main fails to build after On Deck focus change #753).
  • Cross-provider review: gpt-6.1-sol reviewed c92734f and found nothing. b8b6f6c doesn't change behavior, so there was no second round.

Validated features

No passed case on the 1.0 validation board reaches this code; the passed cases cover Calendar, person pages and server branding. Validation tasks: none stands. I couldn't check the board's task links for this PR automatically. The not-run Apple cases that test token refresh during direct play (silo-apple#22, #23, #337, #338) should run on a build that includes the engine change, not on this branch alone.

User manual

Unaffected. No setting, screen or default changes, and the docs don't describe player reloads on token refresh.

Apple and Android

Android already sends fresh credentials on every direct-play request, so it needs no matching change. This PR brings Apple closer to Android.

Fit

The change removes a stall from the core playback path at every token refresh. It reuses the per-request credential resolver server HLS already uses, adds no setting or API surface, and puts the fix in the engine's reader instead of reloading the player. Once #12 lands and the pin moves in this PR, re-check on a simulator or device with a file larger than the engine's cache, so a range request actually goes out after the old token expires.

AI disclosure: written by Claude Code (claude-opus-5-5) running /silo review.

@Quick104
Quick104 merged commit 5efe45f into main Oct 13, 2026
8 checks passed
@Quick104
Quick104 deleted the fix/direct-play-credentials branch October 13, 2026 18:30
Quick104 added a commit that referenced this pull request Oct 19, 2026
Direct play stalled about an hour into a session: the engine kept
sending the access token it opened with after the app refreshed it, so
every range request got a 401 until the engine gave up and the player
replanned. #759 gave direct play a per-request credential resolver and
skipped the app's reload-after-rotation path, but AetherEngine asks that
resolver only for HLS (the direct-play side, AetherEngine#12, never
merged).

AetherEngine 7.37.0 (upstream #792) lets a host replace a running
session's request headers (updateRequestHeaders) and publishes the first
refusal of a header set (sourceAuthorizationRefused). The controller now
uses both for direct play with video:

- after each successful progress report it asks the resolver for the
  current headers and pushes them when the token has rotated, ahead of
  the old token's expiry;
- on a refusal it hands the refused set back to the resolver, which
  refreshes the token first, and pushes the answer while the engine's
  reader still retries;
- answers apply in the order asked, so a slow earlier answer never
  replaces a later one.

Server HLS keeps resolving per request and audio-only media keeps the
reload-after-rotation path.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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 needs-review Needs maintainer review to resolve uncertain classification, scope, or changed evidence. priority: P1 Core-path bug; painful workaround — next after P0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant