Skip to content

feat(jellycompat): support DELETE /Videos/ActiveEncodings transcode teardown - #159

Merged
Quick104 merged 2 commits into
Silo-Server:mainfrom
d3v1l1989:feat/jellycompat-active-encodings-teardown
Jun 15, 2026
Merged

Quick104 merged 2 commits into
Silo-Server:mainfrom
d3v1l1989:feat/jellycompat-active-encodings-teardown

Conversation

@d3v1l1989

@d3v1l1989 d3v1l1989 commented Jun 15, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Jellyfin clients (e.g. JellyCon) call DELETE /Videos/ActiveEncodings when playback stops, to tear down the running HLS transcode. The compat layer didn't implement it, so a transcode kept running until the playback-session TTL (default 6 h) expired.

Approach

Implement DELETE /Videos/ActiveEncodings in the session-auth group (Jellyfin marks the endpoint [Authorize]). It resolves the play session by PlaySessionId and tears it down, reusing a shared teardownPlaySession helper extracted from the existing Stopped-report stop path (removing duplicated teardown logic). Every step is idempotent, so an already-gone session is a clean 204.

Ownership is enforced: only the session's own caller (matching CompatToken) may tear it down; an unknown or not-owned PlaySessionId is a uniform 204 no-op — no cross-session teardown and no ownership oracle — mirroring the ownership check the Stopped report already uses. DeviceId is intentionally ignored: Silo's store is keyed by PlaySessionId, clients always send it, and Jellyfin's own teardown matches by playSessionId when it is non-empty.

Testing

New tests: happy path stops the upstream session and deletes the store entry (204); missing PlaySessionId → 204 no-op; unknown session → 204; lowercase playSessionId key resolves; a foreign-token request does not tear down the session (ownership guard); and the real DeviceId=...&PlaySessionId=... client shape. Green in a libvips container; the ownership guard was mutation-verified (the foreign-session test fails when the check is removed).

Notes / scope

This adds a new compat endpoint. If it falls under the v1 capability scope gate (docs/architecture/v1-scope.md), I'm happy to file a capability proposal first — flagging for triage. DeviceId is accepted but ignored by design (the store has no device index).


AI-use disclosure: implemented and tested with AI assistance (Claude Code), including an adversarial review that caught and fixed a cross-session IDOR (a missing ownership check) before submission. Diff and tests were human-reviewed and run in a libvips Docker container.

Summary by CodeRabbit

Release Notes

  • New Features

    • Added a DELETE /Videos/ActiveEncodings endpoint to stop active encoding sessions with session ownership validation.
  • Improvements

    • Consolidated session teardown logic to ensure consistent behavior across playback stop operations and the new delete endpoint.
  • Tests

    • Extended test coverage for the new endpoint, validating session ownership, idempotent behavior, and proper session cleanup.

@coderabbitai

coderabbitai Bot commented Jun 15, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Caution

Review failed

Pull request was closed or merged during review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 6726fd90-14c8-43a2-8cca-87fbafebe99c

📥 Commits

Reviewing files that changed from the base of the PR and between 2849443 and c08b51b.

📒 Files selected for processing (4)
  • internal/jellycompat/audio_selection_test.go
  • internal/jellycompat/router.go
  • internal/jellycompat/streams.go
  • internal/jellycompat/streams_test.go

📝 Walkthrough

Walkthrough

Adds a DELETE /Videos/ActiveEncodings Jellyfin-compat endpoint handled by HandleDeleteActiveEncodings. The handler extracts PlaySessionId, applies ownership and pre-start guards, and calls a new shared teardownPlaySession helper. The same helper replaces the inline teardown previously in handlePlaybackReport for STOP reports. The route is registered in NewRouter, and a full test suite covers all guard branches.

Changes

DELETE /Videos/ActiveEncodings endpoint

Layer / File(s) Summary
Handler, teardown helper, and route registration
internal/jellycompat/streams.go, internal/jellycompat/router.go
HandleDeleteActiveEncodings extracts PlaySessionId, enforces token ownership and pre-start guards, and returns 204 for all no-op paths. teardownPlaySession encapsulates close-transcode + stop-upstream + delete-store steps, shared by the new handler and the existing STOP-report path in handlePlaybackReport. Route DELETE /Videos/ActiveEncodings is registered in NewRouter.
Test helpers and test cases
internal/jellycompat/audio_selection_test.go, internal/jellycompat/streams_test.go
testCompatSessionManager gains a stopCalls field and a recording StopSession method. withCompatSession and newActiveEncodingsHandler helpers are added. Seven TestHandleDeleteActiveEncodings_* cases cover: successful teardown, missing/unknown PlaySessionId no-ops, case-insensitive parameter lookup, ownership enforcement, DeviceId ignorance, and pre-start window protection.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main feature added: implementing the DELETE /Videos/ActiveEncodings endpoint for transcode teardown in the Jellyfin compatibility layer.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ 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 and usage tips.

@Quick104

Copy link
Copy Markdown
Contributor

Code review

I validated the PR's claims and they largely hold: ownership enforcement, DeviceId handling, case-insensitive query parsing, and the shared teardownPlaySession extraction all check out, and the tests exercise them well. One issue worth addressing:

Found 1 issue:

  1. HandleDeleteActiveEncodings drops the UpstreamSessionID == "" guard that the sibling Stopped-report path keeps, so the teardown is not actually "no-op-safe for an already-gone session" as teardownPlaySession's doc comment claims.

HandlePlaybackInfo creates a PlaybackSession with an empty UpstreamSessionID; that field is only populated later by ensureUpstreamPlayback on the first manifest/stream request. If a client sends DELETE /Videos/ActiveEncodings with a matching token in that early window, the ownership guard passes and teardownPlaySession runs h.playbackStore.Delete(playSession.ID) — deleting a live session that was never torn down. A subsequent HandleMasterManifest then returns 404 ("Playback session not found"). handlePlaybackReport avoids exactly this by including || playSession.UpstreamSessionID == "" in its guard.

playSession, ok := h.playbackStore.Get(playSessionID)
if !ok || playSession.CompatToken != session.Token {
w.WriteHeader(http.StatusNoContent)
return
}
h.teardownPlaySession(playSession)

The sibling guard it diverges from:

playSession, ok := h.playbackStore.Get(req.PlaySessionID)
if !ok || playSession.CompatToken != session.Token || playSession.UpstreamSessionID == "" {
w.WriteHeader(http.StatusNoContent)

Adding || playSession.UpstreamSessionID == "" to the guard (or short-circuiting inside teardownPlaySession) restores parity. Real-world frequency is low — clients normally call this only after a transcode is running — but it's a genuine divergence from the stated idempotency/no-op contract.

Note (process): per the root CLAUDE.md "Silo v1 Process," a new user-facing capability needs a filed/triaged v1 capability proposal and a Part of #NNN link before a feature PR. The PR body already self-flags this for triage.

🤖 Generated with Claude Code

- If this code review was useful, please react with 👍. Otherwise, react with 👎.

…ted sessions

HandleDeleteActiveEncodings omitted the UpstreamSessionID == "" guard that
the sibling Stopped-report path uses. A PlaybackSession is created by
PlaybackInfo with an empty UpstreamSessionID; it is only populated once the
first manifest request reaches ensureUpstreamPlayback. A DELETE
/Videos/ActiveEncodings arriving in that window (with a matching token) passed
the ownership guard and ran teardownPlaySession, which deletes the compat play
session from the store. A subsequent HandleMasterManifest then 404s, and the
teardown was not the "no-op-safe" operation its doc comment claims.

Mirror the Stopped report path by treating an unknown, not-owned, OR
not-yet-started PlaySessionId as a uniform idempotent 204 no-op. Add a
regression test that fails if the guard is removed.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@Quick104

Copy link
Copy Markdown
Contributor

Pushed c08b51b3c0eb66c99b2211a85571830beb856c71 to address the review finding.

HandleDeleteActiveEncodings now mirrors the Stopped report path's guard — an unknown, not-owned, or not-yet-started (UpstreamSessionID == "") PlaySessionId is a uniform idempotent 204 no-op. This stops a DELETE /Videos/ActiveEncodings that lands in the window between PlaybackInfo and the first manifest request from deleting a live session and 404-ing the pending manifest. Added TestHandleDeleteActiveEncodings_NotYetStartedNotTornDown, which fails if the guard is removed.

The scope-gate process note (v1 capability proposal + Part of #NNN) is unchanged and left for triage as you flagged in the PR description.

🤖 Generated with Claude Code

@Quick104
Quick104 merged commit cd6277e into Silo-Server:main Jun 15, 2026
1 check was pending
@d3v1l1989
d3v1l1989 deleted the feat/jellycompat-active-encodings-teardown branch June 15, 2026 22:19
Quick104 added a commit that referenced this pull request Jun 17, 2026
…eardown (#159)

* feat(jellycompat): support DELETE /Videos/ActiveEncodings transcode teardown

* fix(jellycompat): guard ActiveEncodings teardown against not-yet-started sessions

HandleDeleteActiveEncodings omitted the UpstreamSessionID == "" guard that
the sibling Stopped-report path uses. A PlaybackSession is created by
PlaybackInfo with an empty UpstreamSessionID; it is only populated once the
first manifest request reaches ensureUpstreamPlayback. A DELETE
/Videos/ActiveEncodings arriving in that window (with a matching token) passed
the ownership guard and ran teardownPlaySession, which deletes the compat play
session from the store. A subsequent HandleMasterManifest then 404s, and the
teardown was not the "no-op-safe" operation its doc comment claims.

Mirror the Stopped report path by treating an unknown, not-owned, OR
not-yet-started PlaySessionId as a uniform idempotent 204 no-op. Add a
regression test that fails if the guard is removed.

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

---------

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants