Skip to content

fix(jellycompat): keep Jellyfin play sessions for 24 hours by default - #2922

Merged
Quick104 merged 2 commits into
mainfrom
fix/issue-2899-jellycompat-play-session-ttl
Oct 22, 2026
Merged

Quick104 merged 2 commits into
mainfrom
fix/issue-2899-jellycompat-play-session-ttl

Conversation

@Quick104

@Quick104 Quick104 commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Closes #2899
Related issue: N/A
Validation tasks: none

Jellyfin apps lose their stream six hours after they start playing. After that, every request that carries only PlaySessionId returns 401: HLS playlists, segments, and font attachments. A movie paused overnight or a long play can't continue. This change makes those play sessions last 24 hours by default, as the compat router intends, and keeps any value an administrator chose.

The router gives compat play sessions the 24-hour stream-token lifetime (playback.MaxTokenTTL), but jellyfin_compat.playback_session_ttl replaces it whenever it is set. Every database is seeded with 6h, and the config, database loader, and admin defaults all said 6h, so 6 hours is what runs. The lifetime counts from PlaybackInfo and activity doesn't extend it.

Approach

  • The setting's defaults move to 24h in the config, the database loader, and the admin defaults.
  • A Goose migration changes a stored 6h to 24h. A stored 6h can't be told apart from an administrator who typed 6h, so both move. Any other value stays, and a database without the row uses the new code default. The 001_schema.sql seed is unchanged because merged migrations are immutable; fresh installs reach 24h through the new migration.
  • NewDurableCompatPlaybackStore takes the lifetime its in-memory store resolves, instead of its own 6-hour fallback.
  • The admin field said "Forget idle playback after", which reads as an idle timeout. It is now "End playback sessions after", with a hint saying the time counts from when playback starts, paused or not.

The expiry stays absolute. A sliding expiry would need a Postgres write on segment requests, which the durable store keeps off that path, and this bug doesn't need it.

Device profiles use the same setting (NewDeviceProfileStore), so a client's registered capabilities are also kept for 24 hours instead of 6. Clients re-register them on every capabilities post and PlaybackInfo, so the stored profile is the device's latest.

Validation

  • Live on a dev sandbox, one database before and after:
    • On main, a Jellyfin PlaybackInfo session was stored with a 6-hour lifetime. After its timestamps were moved 6 h 1 m back and the server restarted, its HLS master playlist returned 401 to a request carrying only PlaySessionId.
    • On this branch, the same database migrated from 6h to 24h on startup. A new session was stored with a 24-hour lifetime, and after the same shift and restart its master playlist and first segment returned 200.
    • A copy of the database where an admin had set 12h through the admin API kept 12h after the migration. An empty database migrated from scratch ends at 24h.
  • The new jellycompat test runs default settings through the real auth middleware. With fails-on-base, it fails on main (401 at 23 h 59 m) and passes here. The migration test (old seed, admin value, missing row) runs against Postgres and is listed in db-contracts.txt. Removing the migration's value = '6h' guard makes it fail.
  • Go gate: build, gofmt, vet, make lint-changed (0 issues), make lint-router-recovery, the contract and fixture checks, and make verify-migrations all pass. In make test-go, internal/mediasample fails the same way on main (host ffmpeg), and one internal/subtitles/ai panic did not repeat in 5 reruns; neither package depends on this change. The jellycompat and migrations packages pass against Postgres.
  • Web gate: lint, format, build, and budget pass. Two make test-web failures (shuffle chrome and the PGS parser, both timing-sensitive) pass when rerun.

Evidence

The Compatibility settings field before (Forget idle playback after, 6h) and after (End playback sessions after, 24h), on desktop and at phone width, plus the before and after server transcripts and the tests' failing runs on main.

Evidence: https://evidence.siloserver.org/r/silo-server/issue-2899/

Risks

  • An administrator who deliberately set 6h gets 24h after the upgrade and has to set it again.
  • A leaked PlaySessionId can stream its one item for up to 24 hours instead of 6, while the session is never stopped and its owner stays signed in. Request logs already record the ID.
  • Unstopped and in-progress rows live up to 24 hours, so the compat session table and each node's in-memory map hold about 3.6 times as many entries. The scans over them are already linear. That's negligible for a household. On a large cluster it adds work to credential-less static-stream grants and terminal recovery.
  • During a rolling upgrade, a replica that has not restarted keeps issuing 6-hour sessions. The setting requires a restart, and each session keeps the expiry it was created with.

Checklist

  • I read and can explain the complete diff.
  • This pull request addresses one concern.
  • Each test this pull request adds meets "Decide what to test" in CONTRIBUTING.md.
  • The Evidence section shows every change a user can see, or says there is none.

AI Disclosure

  • Harness: Claude Code (in T3 Code)
  • Tool(s): Claude Code /silo skill and review subagents; T3 Code delegate_task for the cross-provider reviews; GitHub CLI
  • Model(s): claude-opus-5-5 (implementation and review); claude-sonnet-5-5 (one review pass); gpt-6.1-sol (plan review and background review)
  • Involvement: AI-assisted
  • Adversarial review: before implementation, gpt-6.1-sol (xhigh) reviewed the plan and found it held. It corrected the reason for keeping the expiry absolute (PlaybackInfo doesn't mint the stream token), noted that idle native sessions can still retire a compat session earlier, and narrowed what the new test claims to cover. A multi-pass code review led to the relabeled admin field; its other findings are the risks listed above. A background review with gpt-6.1-sol (xhigh) of d6e43a3 found nothing to change.

🤖 Generated with Claude Code

Note

Raise Jellyfin compatibility play session TTL default to 24 hours

  • Changes the default playback-session lifetime for Jellyfin compatibility from 6 hours to 24 hours, aligning it with the stream-token lifetime. Adds a shared defaultJellyfinCompatPlaybackSessionTTL constant used by setDefaults, LoadFromDB, and the admin-settings defaults.
  • Adds a Goose migration that rewrites only rows still holding the old 6-hour seed value to 24 hours; admin-selected values and missing rows stay unchanged. The down migration is a no-op.
  • Removes the constructor-local 6-hour fallback in NewDurableCompatPlaybackStore; the durable store now copies the TTL resolved by the in-memory playback store.
  • Rewords the admin UI setting: the duration is measured from playback start regardless of pause state, with 24 hours as the example.
  • Behavioral Change: existing installs with the seeded 6-hour value move to 24 hours after migration; the TTL counts from playback start, not idle time. See migrations/sql/20261022130254_jellyfin_compat_play_session_ttl_24h.sql.

Macroscope summarized d6e43a3.

Quick104 and others added 2 commits October 22, 2026 09:12
The router gives compat play sessions the 24h stream-token lifetime, but
jellyfin_compat.playback_session_ttl overrides it whenever it is set, and
every database was seeded with 6h. PlaySessionId-only HLS and attachment
requests started failing six hours after PlaybackInfo.

Default the setting to 24h in the config, the database loader and the admin
defaults, and migrate a stored 6h (the old seed) to 24h while leaving any
other value an administrator chose. The durable store now takes the lifetime
its in-memory cache resolves instead of its own 6h fallback.

Closes #2899

Co-Authored-By: Claude Opus 5.5 <[email protected]>
"Forget idle playback after" suggested an idle timeout, but a Jellyfin play
session ends a fixed time after playback starts, paused or not. Rename the
field and say so in its hint. Drop test rows the boundary cases already cover.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@silo-triage silo-triage Bot added the size/M 50–199 added + deleted lines (all files); change volume, not priority. label Oct 22, 2026
@coderabbitai

coderabbitai Bot commented Oct 22, 2026

Copy link
Copy Markdown
Contributor

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 26 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 4 included reviews currently available.

Learn how review limits work.

Review configuration:

⚙️ 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: 7d4abfad-e6c6-427e-83fd-3ac861fb67ad
📥 Commits

Reviewing files that changed from the base of the PR and between d004620 and d6e43a3.

📒 Files selected for processing: 11
  • internal/config/admin_settings.go
  • internal/config/config.go
  • internal/config/db_loader.go
  • internal/jellycompat/auth_test.go
  • internal/jellycompat/playback_sessions_postgres.go
  • internal/jellycompat/router.go
  • migrations/jellyfin_compat_play_session_ttl_test.go
  • migrations/sql/20261022130254_jellyfin_compat_play_session_ttl_24h.sql
  • scripts/ci/db-contracts.txt
  • web/src/lib/adminSettingsSearch.ts
  • web/src/pages/admin-settings/CompatibilityProxiesSettings.tsx
  • 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-kody

silo-kody Bot commented Oct 22, 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 ❌

@silo-triage silo-triage Bot added bug Something isn't working impact: playback Can't play, stalls, or wrong media priority: P2 Limited scope, workaround exists, or polish labels Oct 22, 2026
Comment on lines +6 to +9
UPDATE server_settings
SET value = '24h'
WHERE key = 'jellyfin_compat.playback_session_ttl'
AND value = '6h';

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

kody code-review Bug medium

Configuration overwrite in migrations/sql/20261022130254_jellyfin_compat_play_session_ttl_24h.sql changes administrator-selected 6h values for server_settings key jellyfin_compat.playback_session_ttl to 24h, violating the requirement to preserve administrator choices. The key/value settings schema provides no provenance to distinguish explicitly selected six-hour lifetimes from seeded defaults, so value matching alone cannot safely identify settings to migrate.

Prompt for LLM

File migrations/sql/20261022130254_jellyfin_compat_play_session_ttl_24h.sql:

Line 6 to 9:

Configuration overwrite in `migrations/sql/20261022130254_jellyfin_compat_play_session_ttl_24h.sql` changes administrator-selected `6h` values for `server_settings` key `jellyfin_compat.playback_session_ttl` to `24h`, violating the requirement to preserve administrator choices. The key/value settings schema provides no provenance to distinguish explicitly selected six-hour lifetimes from seeded defaults, so value matching alone cannot safely identify settings to migrate.

Talk to Kody by mentioning @kody

Was this suggestion helpful? React with 👍 or 👎 to help Kody learn from this interaction.

​

​

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.

This is deliberate, and the PR's Risks section discloses it. As you say, server_settings stores only key and value, so a 6h an administrator typed can't be told apart from the 6h that 001_schema.sql seeded on every install. That leaves two options:

  • Move every stored 6h, which is this PR. A deliberate 6h becomes 24h, and the administrator can set it back on the Compatibility page.
  • Move only databases no administrator has touched, gated on no users or no setup.completed like 20260923181531. Every existing deployment would keep the 6-hour lifetime this PR fixes, so only fresh installs would benefit.

The issue asks for the first, the way 20260806224241 and 20260809133921 moved their old seeds. Any other value an administrator chose, such as 12h, is kept. The migration test covers that, and so does an upgraded database in the PR's evidence. I'm leaving this open for the maintainer to decide.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Agreed. My suggestion treated preserving an explicitly selected 6h as an unconditional requirement, but this PR deliberately accepts that indistinguishable case to fix existing installations.

The migration’s guard preserves values other than 6h; it cannot preserve deliberate 6h choices without also retaining the seeded default. Given the documented trade-off, this is an intentional behavior change for maintainer approval, not an overlooked migration bug.

I would not block this PR on the original suggestion. Leaving the decision with the maintainer makes sense.

@Quick104
Quick104 merged commit 4042544 into main Oct 22, 2026
39 of 41 checks passed
@Quick104
Quick104 deleted the fix/issue-2899-jellycompat-play-session-ttl branch October 22, 2026 14:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working impact: playback Can't play, stalls, or wrong media priority: P2 Limited scope, workaround exists, or polish size/M 50–199 added + deleted lines (all files); change volume, not priority.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug] Jellyfin play sessions expire after 6 hours although the router intends 24

1 participant