Skip to content

fix(jellycompat): tolerate item-id mediaSourceId on direct-play streams - #313

Merged
Quick104 merged 1 commit into
Silo-Server:mainfrom
yammes08:fix/jellycompat-directplay-mediasource-fallback
Jul 7, 2026
Merged

Quick104 merged 1 commit into
Silo-Server:mainfrom
yammes08:fix/jellycompat-directplay-mediasource-fallback

Conversation

@yammes08

@yammes08 yammes08 commented Jul 6, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Native clients that direct-play via /Videos/{id}/stream?static=true fail with 400 "Media source is required" and can't play back at all (even content the device supports natively) when they:

  1. call PlaybackInfo and reuse the server-returned PlaySessionId on the stream request, and
  2. send the item id as mediaSourceId (per the Jellyfin MediaSource.Id == Item.Id convention) rather than Silo's fileID-based media-source id.

Negotiation succeeds (PlaybackInfo returns 200, direct play), but the follow-up stream request 400s, so playback never starts.

Root cause

resolvePlaybackRoute has three resolution paths. FindByRoute and createStaticPlaySession both fall back to firstMediaSource when a named mediaSourceId matches no stored source. The PlaySessionId-hit path does not; it returns findMediaSource's nil result directly:

if mediaSourceID != "" {
    source := findMediaSource(playSession, mediaSourceID)
    return playSession, source, nil   // nil when the id doesn't match
}

Silo assigns each media source a fileID-based id (EncodeIntID(EncodedIDMediaSource, fileID)), intentionally distinct from the item id so /Items/{id}/Download and detail/image routes can decode the file statelessly and multi-version files stay distinguishable. So a client sending the item id as mediaSourceId never matches, findMediaSource returns nil, and because resolution returns a nil error, HandleVideoStream's Static fallback (createStaticPlaySession) never fires either. The result is a hard 400 on every direct-play request.

This slips past the #165 safety net, which only covers clients whose PlaySessionId is server-unknown (client-generated, so it falls through to FindByRoute). A client that calls PlaybackInfo and reuses the server's PlaySessionId lands in the strict branch instead.

Fix

Give the PlaySessionId-hit branch a primary-source fallback scoped to the convention it needs to satisfy: fall back to the session's primary source only when mediaSourceId is empty or equals the route item id. This mirrors upstream Jellyfin's StreamingHelpers, which defaults to mediaSources[0] only for an empty or item-id mediaSourceId and leaves any other unmatched id unresolved.

The behavior delta is exactly one case: a known PlaySessionId plus an item-id mediaSourceId now serves the primary source instead of 400ing. Exact source-id matches and the empty-mediaSourceId case are unchanged. Any other unmatched id (a stale/foreign id, or a wrong version on a multi-version item) still returns 400, so it can't silently stream the wrong file. The media-source id scheme is left as-is.

Test

Adds two tests:

  • TestHandleVideoStream_KnownPlaySessionItemIDMediaSourceServesFile — known PlaySessionId + item-id mediaSourceId: 400 before, serves the file (200) after.
  • TestHandleVideoStream_KnownPlaySessionUnknownMediaSourceRejected — known PlaySessionId + a non-item, non-matching id: still 400 (guards the fallback scope).

The full internal/jellycompat suite passes.

@coderabbitai

coderabbitai Bot commented Jul 6, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@yammes08, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 47 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: c0c02d3d-c9de-4627-bbed-3d1d843fdc51

📥 Commits

Reviewing files that changed from the base of the PR and between 080a55c and e9904cf.

📒 Files selected for processing (2)
  • internal/jellycompat/playback_static_directplay_test.go
  • internal/jellycompat/streams.go
📝 Walkthrough

Walkthrough

Modified resolvePlaybackRoute in internal/jellycompat/streams.go so that when a cached play session's mediaSourceId doesn't match a stored source, it falls back to the session's primary source instead of returning nil. Added a regression test covering this scenario.

Changes

Playback route media source fallback

Layer / File(s) Summary
Fix source resolution fallback and add regression test
internal/jellycompat/streams.go, internal/jellycompat/playback_static_directplay_test.go
resolvePlaybackRoute now falls back to the play session's primary source when mediaSourceId doesn't resolve to a stored source, avoiding a nil source; a new test confirms static stream playback succeeds when the client sends the route item id as mediaSourceId.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

  • Silo-Server/silo-server#262: Both PRs modify resolvePlaybackRoute's Static/direct-play session routing logic in internal/jellycompat/streams.go.

Suggested labels: v1

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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 Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main fix: accepting item-id mediaSourceId values for direct-play streams in jellycompat.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@coderabbitai coderabbitai Bot added the v1.0 Silo v1 scope - auto-adds to the Silo v1 project label Jul 6, 2026

@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: 080a55cb97

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread internal/jellycompat/streams.go Resolved
Native clients that call PlaybackInfo, reuse the returned PlaySessionId on the
/Videos/{id}/stream?static=true request, but send the *item* id as mediaSourceId
(per the Jellyfin MediaSource.Id == Item.Id convention) rather than Silo's
fileID-based source id got a 400 "Media source is required" and could not
direct-play at all.

The PlaySessionId branch of resolvePlaybackRoute returned findMediaSource's nil
result directly, with no fallback -- unlike the FindByRoute and
createStaticPlaySession paths. Because resolution returned a nil error,
HandleVideoStream's Static fallback never fired either, so every direct-play
request 400'd.

Fall back to the session's primary source only when mediaSourceId is empty or
equals the route item id (the MediaSource.Id == Item.Id convention), matching
Jellyfin's StreamingHelpers. Any other unmatched id -- a stale/foreign id, or a
wrong version on a multi-version item -- stays rejected so it can't silently
stream the wrong file. Exact source-id matches are unchanged.
@Quick104
Quick104 merged commit 2f95f6b into Silo-Server:main Jul 7, 2026
1 check passed
Quick104 pushed a commit that referenced this pull request Jul 10, 2026
…ms (#313)

Native clients that call PlaybackInfo, reuse the returned PlaySessionId on the
/Videos/{id}/stream?static=true request, but send the *item* id as mediaSourceId
(per the Jellyfin MediaSource.Id == Item.Id convention) rather than Silo's
fileID-based source id got a 400 "Media source is required" and could not
direct-play at all.

The PlaySessionId branch of resolvePlaybackRoute returned findMediaSource's nil
result directly, with no fallback -- unlike the FindByRoute and
createStaticPlaySession paths. Because resolution returned a nil error,
HandleVideoStream's Static fallback never fired either, so every direct-play
request 400'd.

Fall back to the session's primary source only when mediaSourceId is empty or
equals the route item id (the MediaSource.Id == Item.Id convention), matching
Jellyfin's StreamingHelpers. Any other unmatched id -- a stale/foreign id, or a
wrong version on a multi-version item -- stays rejected so it can't silently
stream the wrong file. Exact source-id matches are unchanged.
@zZebrahz zZebrahz mentioned this pull request Sep 26, 2026
12 tasks done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

v1.0 Silo v1 scope - auto-adds to the Silo v1 project

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants