Skip to content

fix(playback): play Jellyfin streams and rebuilt transcodes when the GPU can't decode the source - #4097

Merged
Quick104 merged 1 commit into
mainfrom
fix/issue-4030-explicit-decode-retry
Nov 13, 2026
Merged

Quick104 merged 1 commit into
mainfrom
fix/issue-4030-explicit-decode-retry

Conversation

@Quick104

@Quick104 Quick104 commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Closes #4030
Related issue: N/A
Validation tasks: unblocks #1172 C2

Other clients: N/A (no client-visible change)

With Hardware acceleration set to an explicit backend such as NVENC, a GPU whose decoder can't take the source (HEVC on a GTX 970) makes FFmpeg exit at startup with Hardware is lacking required capabilities. #4057 made the starts that wait for a first manifest retry with CPU decoding. Four paths start FFmpeg without waiting, so they never saw the rejection and handed back a process that had already exited:

  • a Jellyfin-compatible start on the API server;
  • a Jellyfin-compatible start on a transcode node;
  • a rebuild of a lost transcode on the API server;
  • a rebuild of a lost transcode on a transcode node.

On such a server, Jellyfin clients could not start an HEVC transcode at all. A rebuild fails the same way when its recipe was written where the GPU does decode the source: after the operator switches Hardware acceleration from Auto or None to NVENC, or when a Jellyfin transcode moves off a dead node, which rebuilds on the new executor instead of starting fresh.

This change makes all four paths decode on the CPU when the decoder rejects the source, using the retry #4057 added.

Approach

A start under an explicit hardware backend that decodes on the GPU, without tone mapping, is now waited on until its first manifest or its exit. If FFmpeg exits with the decoder rejection, the path walks the same order as #4057: CPU decode with the hardware encoder, then software. One exported predicate, playback.HardwareDecodeRetryEligible, decides which starts are waited on, and NewSoftwareDecodeRetryPipeline now uses it for its own gate.

Only a decoder rejection changes what three of the paths do. A ready process, a slow one, and one that exits for any other reason are returned as they were, so the existing exit monitor and segment recovery still handle them.

The Jellyfin node start is the exception. The API server now sends RequireReady for an eligible start, which reuses the node behavior #4057 shipped and needs no node change. RequireReady also closes a process that has no manifest after 30 seconds. hw_accel=auto on this path and every native start already work that way.

On a transcode node, a rebuild whose backend already has its own software retry (VideoToolbox, or QSV/VAAPI without a render device) keeps that path unchanged, so no start is waited on twice. A rebuild's retry is launched on a context detached from the request that triggered it, because other requests wait on the same rebuild.

worker-http-protocol.md and restart-resilient-playback.md describe the new start and rebuild rules.

Validation

  • Focused tests, one per path, through entry points that exist before and after the change. Each fails on main for the reported reason (one GPU-decode attempt, then a dead or unwaited start) and passes here. The Jellyfin and node tests run a fake FFmpeg that prints the NVDEC line for any -hwaccel cuda command.
  • go build ./..., gofmt -l, go mod tidy -diff, go vet, make lint-changed, make lint-router-recovery, make verify-local-paths: clean.
  • make test-go: no test fails here that passes on main. On the machine I ran it on, main itself fails TestCopyRemuxSubtitleRenditionRealFFmpeg (stock FFmpeg 6.1.1) and tests in internal/ebookconvert, internal/mediasample, internal/uploads, internal/backup and internal/api/handlers; the same tests fail with this change. CI is the check for those.
  • Web gate and generated-contract checks: not run. The change touches no web code, API contract, or setting.
  • Not reproduced on real hardware. I had no NVIDIA card whose decoder rejects a source, so none of the four paths was run against one. The reporter confirmed fix(playback): decode on the CPU when the GPU decoder rejects the source #4057's retry on a GTX 970 for native playback and downloads; this change routes four more paths into that retry.
  • Passed validation cases: none changes under hw_accel=auto. Under an explicit backend, the worker-loss cases Distributed transcode nodes — Server #1177 C3 and Distributed transcode nodes — Web admin #1178 C2 wait a few seconds longer on a rebuild; the build they passed on does not record its Hardware acceleration setting.

Evidence

No capture: nothing visible changes, and no hardware here reproduces the rejection. The page holds the failing run on main and the passing run on this branch for the four tests.

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

Risks

  • A Jellyfin-compatible start on the API server under an explicit backend now answers the manifest request after FFmpeg's first manifest, at most 30 seconds later. Before, a bounded-length encode answered at once and the first segment request did the waiting. Time to first frame moves later by about the encode time of one or two segments.
  • A Jellyfin-compatible node start under an explicit backend that has no manifest after 30 seconds is now closed. The API server then tries another node or local execution, and answers 502 only when none is left. Such a start used to keep running.
  • A transcode node older than fix(playback): decode on the CPU when the GPU decoder rejects the source #4057 gets RequireReady without the retry. It now fails the start as soon as FFmpeg exits, and the API server tries elsewhere, where before it reported the dead process as started.
  • A rebuild under an explicit backend now holds the session's lifecycle lock and a rebuild pacing slot until its first manifest (three segments), at most 30 seconds, and up to about 90 seconds when the decoder rejects the source. On a node it also holds the config reload read lock, so a reload, a stop, or a new start for that session waits behind it. hw_accel=auto already holds the same locks for the same wait.
  • Every start and rebuild on an affected card still makes one failed GPU-decode attempt first. A rebuild can't record the result: a native recipe travels in the client's stream token.
  • The wait also applies to a few starts that end up encoding in software after a probe, such as an unconstrained VideoToolbox request. They gain nothing from it.
  • A request whose Hardware acceleration value is empty skips the Jellyfin node change, and the node applies its own setting. The config default, the YAML import, and the admin setting never leave the value empty.

Follow-ups: the review turned up two defects that already exist on main, filed separately. #4098: a rebuild under hw_accel=auto launches its fallback attempts on the triggering request's context. #4099: a node rebuild with a software retry can accept a manifest left by an earlier process. The user manual needs no change; its playback and node pages don't describe how an explicit backend falls back.

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 how I checked a change nobody sees.

AI Disclosure

  • Harness: Claude Code (T3 Code)
  • Tool(s): Claude Code; OpenAI Codex (plan review)
  • Model(s): claude-fable-5-2 (implementation and review); gpt-6.1-sol and claude-opus-5-5 (plan review); claude-sonnet-5-5 (cleanup and validation checks)
  • Involvement: Fully AI-generated. The maintainer directed the work and reviews it on this pull request.
  • Adversarial review: Before any code, gpt-6.1-sol attacked the plan and claude-opus-5-5 cut it down. Sol found that a slow VideoToolbox rebuild on a node would be waited on twice, and that the rebuild's retry would launch on a request context that may have ended; both are fixed here. Opus kept all four paths and trimmed the tests and docs. A simplify pass and a multi-agent code review at high (three finders, a validation check, four verifiers) followed. The review found no correctness defect in the change. It led to one fix (MPEG-4 Part 2 sources are no longer waited on) and to the Risks above. A background adversarial review by gpt-6.1-sol of 1f2f62e, run after this pull request opened, found nothing and posted no review.

…GPU can't decode the source

With Hardware acceleration set to an explicit backend, a GPU whose decoder
rejects the source (HEVC on a GTX 970) made FFmpeg exit at startup. #4057
retried on the CPU for starts that wait for a first manifest. Four paths
started FFmpeg without waiting and handed back the exited process:
Jellyfin-compatible local and node starts, and local and node reconstructs.

These paths now wait for the first manifest when the start decodes on the GPU,
and walk the same CPU-decode retry on a decoder rejection. Any other outcome is
returned as before, except that a Jellyfin node start is now sent with
RequireReady.

Related issue: #4030

Co-Authored-By: Claude Fable 5.2 <[email protected]>
@silo-triage silo-triage Bot added the size/L 200–499 added + deleted lines (all files); change volume, not priority. label Nov 13, 2026
@silo-kody

silo-kody Bot commented Nov 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 ❌

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 13, 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-11-13T19:48:32.518157Z 1f2f62e PR opened
🔒 Security Review ✅ Completed 2026-11-13T19:52:58.006590Z 1f2f62e PR opened
ℹ️ 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.

@coderabbitai

coderabbitai Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

Walkthrough

Eligible reconstruction starts now retry GPU decoder capability rejections with CPU video decoding while retaining hardware encoding. Compatible transcode requests wait for readiness when that retry applies. Tests and architecture documentation describe the retry behavior.

Changes: GPU Decoder Rejection Retry

Layer / File(s) Summary
Reconstruction retry behavior
internal/playback/transcode_startup.go, internal/playback/transcode_startup_test.go, internal/playback/transcode_manager.go, internal/playback/transcode_manager_test.go, docs/architecture/restart-resilient-playback.md
Reconstruction retries eligible GPU decoder rejections with CPU video decoding. The retry preserves the output directory and uses a non-canceled context. The retry eligibility predicate excludes MPEG-4 Part 2, tone-map recipes, video-copy targets, software decoding, and non-hardware backends.
Transcode-node reconstruction wiring
internal/transcodenode/server.go, internal/transcodenode/auto_transcode_fallback_test.go
Applicable reconstruction starts use the retry-aware startup path unless a separate software-encode retry applies. Tests verify explicit NVENC reconstruction retries without CUDA decoding.
Compatible transcode readiness and retry
internal/jellycompat/handlers_playback.go, internal/jellycompat/streams.go, internal/jellycompat/auto_transcode_fallback_test.go, docs/architecture/worker-http-protocol.md
Eligible explicit-hardware requests require readiness. Compatible startup retries eligible decoder rejections while preserving the existing automatic-pipeline fallback behavior. Tests cover readiness and retry behavior.

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

Change: Bug fix · Severity of issue fixed: Medium

Sequence Diagram(s)

sequenceDiagram
  participant Node as Transcode node
  participant Startup as Reconstruction startup
  participant FFmpeg as FFmpeg process
  Node->>Startup: Start eligible hardware reconstruction
  Startup->>FFmpeg: Decode on GPU and encode on GPU
  FFmpeg-->>Startup: Hardware decoder capability rejection
  Startup->>FFmpeg: Retry with CPU decode and GPU encode
  FFmpeg-->>Startup: Produce first manifest
  Startup-->>Node: Return ready reconstruction session
Loading

Suggested reviewers: blurbery, rhainland, rangodj

Merge Risk: Moderate · up to 1f2f6

After a restart or lost-transcode rebuild, a stream that needed the GPU-decoder CPU-decode retry under explicit NVENC can be rebuilt with CPU encoding instead of NVENC. Playback still works but uses much more CPU and may stutter on weaker hosts. Preserve the NVENC permission across reconstruction before relying on this path.

Security architecture risk: Minimal · up to 1f2f6

The change adds bounded decoder fallback to existing playback flows. The inspected authorization, process-cleanup, and session-ownership controls remain in place, with no material security or failure-containment regression established.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The added work consumes CPU and potentially GPU capacity on the selected API server or worker. The retry retains the admitted session’s media input and output directory rather than granting access to another session or introducing a new executor authority.

Trust Boundaries and Controls

  • observed — The worker start and media routes remain behind node-signature verification. Fresh starts require approved input paths; reconstruction verifies a presented token and transport binding or obtains a complete transport-bound recipe from the control-plane store, then rechecks input authority and stop fences before spawning.

Resilience and Maintainability Implications

  • observed — Reconstruction deliberately detaches readiness waiting from the triggering request, extending lock and pacing-slot occupancy. Countervailing controls include 30-second per-attempt manifest waits, finite retry stages, reconstruction pacing, shutdown-aware manager publication, and worker stop serialization against in-flight reconstruction.
Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: Jellyfin-compatible streams and rebuilt transcodes now play when the GPU cannot decode the source. The raw summary and objectives confirm the four affected paths (Jell…
Linked Issues check Passed [#4030] The requirement is a CPU-decode retry for explicit hardware backends (for example NVENC) when FFmpeg reports "Hardware is lacking required capabilities". The diff implements this for the four …
Out of Scope Changes check Passed The changed hunks in internal/playback/transcode_startup.go, internal/jellycompat/streams.go, handlers_playback.go, and transcodenode/server.go connect to the four paths named in #4030 and the PR obje…
Description check Passed The description is specific and on-topic. It names the problem (an explicit NVENC backend whose GPU decoder rejects HEVC input, causing FFmpeg to exit with 'Hardware is lacking required capabilities')…
Full details: Title check

Explanation

The title names the main change: Jellyfin-compatible streams and rebuilt transcodes now play when the GPU cannot decode the source. The raw summary and objectives confirm the four affected paths (Jellyfin-compatible starts and lost-transcode rebuilds on the API server and transcode nodes) and the CPU-decode retry for explicit hardware backends. The title is specific and matches the changeset.

Full details: Linked Issues check

Explanation

[#4030] The requirement is a CPU-decode retry for explicit hardware backends (for example NVENC) when FFmpeg reports "Hardware is lacking required capabilities". The diff implements this for the four named paths. In internal/playback/transcode_startup.go, startReconstructOnce waits on eligible reconstructs and, on a decoder rejection, runs NewSoftwareDecodeRetryPipeline in the same output directory. HardwareDecodeRetryEligible gates eligibility. In internal/jellycompat/streams.go, awaitCompatAutoTranscode now runs the same retry for a disabled explicit-backend pipeline, and ensureTranscodeSessionWithToneMapMode waits on eligible explicit starts. The node-side spawnReconstruct in internal/transcodenode/server.go routes explicit backends through StartReconstructTranscode. The issue's download-preparation gap is covered by existing #4057 behavior, per the PR description, and the issue's scope is satisfied by the four paths named in the PR objective. Test coverage for each path is present in the diff (jellycompat, playback, transcodenode tests). Hardware reproduction is not a coding requirement and was not performed; that is a validation gap, not an unmet requirement. Limits: I read the diffs of transcode_startup.go and streams.go only, not the test bodies or the other changed files.

Full details: Out of Scope Changes check

Explanation

The changed hunks in internal/playback/transcode_startup.go, internal/jellycompat/streams.go, handlers_playback.go, and transcodenode/server.go connect to the four paths named in #4030 and the PR objective. The MPEG-4 Part 2 exclusion in HardwareDecodeRetryEligible is a narrowing of the same retry gate and is described in the PR. The NewSoftwareDecodeRetryPipeline refactor reuses the same predicate, so existing retry gating stays consistent. The comment and doc changes (restart-resilient-playback.md, worker-http-protocol.md, transcode_manager.go comment) describe the new rules and do not add behavior. Test changes support the new behavior. Behavior changes that the PR lists as risks (longer waits, RequireReady on node starts, lock holding during rebuild) follow directly from the in-scope fix and are not unrelated work. I did not find an unrelated change in the inspected hunks. Unread test and doc hunks were not inspected in detail.

Full details: Description check

Explanation

The description is specific and on-topic. It names the problem (an explicit NVENC backend whose GPU decoder rejects HEVC input, causing FFmpeg to exit with 'Hardware is lacking required capabilities'), lists the four affected startup and rebuild paths, and explains the approach (wait for a manifest or exit, then retry with CPU decode and the hardware encoder, then software). It also covers validation, risks, and follow-ups. These match the changeset, which touches the Jellyfin-compatible handlers, streams, transcode startup, transcode node server, and the related tests and docs.

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

Comment on lines +3287 to 3291
} else if autoPipeline.Enabled() || playback.HardwareDecodeRetryEligible(opts) {
// An explicit hardware backend has no fallback order, but its decoder
// can still reject the source, so it is waited on too.
var successor *playback.TranscodeSession
transcodeSession, successor, err = h.awaitCompatAutoTranscode(ctx, upstreamSessionID, source, requiredToneMapMode, autoPipeline, transcodeSession)

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 high

Concurrent requests can observe the failed session before decoder fallback

A concurrent manifest request can receive the failed GPU-decode session and tear down playback while CPU fallback starts. Coordinate callers through awaitCompatAutoTranscode so they receive only a ready session or its successor.

Prompt for LLM
File internal/jellycompat/streams.go, lines 3287-3291:

Concurrent requests can observe the failed session before decoder fallback

A concurrent manifest request can receive the registered GPU-decode session after it has exited but before this wait replaces it, causing manifest handling to fail and tear down the playback session while the CPU fallback is starting. Coordinate concurrent callers with the in-progress startup and return only the ready session or its successor.

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 race is real, but it predates this change and this change doesn't make it worse.

  • On main, hw_accel=auto already runs this wait-and-replace loop. A second manifest request adopts the registered session at the two existing checks in ensureTranscodeSessionWithToneMapMode, which this pull request doesn't touch.
  • For an explicit backend, main fails this start every time. Here it fails only when a second manifest request lands between FFmpeg's exit and the replacement.
  • It needs the real-manifest path (unknown duration, or more than 50,000 segments). With the generated VOD manifest the second caller never touches the session.

Closing it means making concurrent callers wait on a startup that is still in progress, which changes the Auto path as well. I'm leaving that out of this change and raising it with the maintainer.

🤖 Claude Code (claude-fable-5-2)

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. Given that the race already affects the Auto path and the explicit-backend path improves on the existing failure, it makes sense to raise it separately rather than expand this PR.

The follow-up should cover concurrent requests adopting a registered session before startup and fallback have completed, including the real-manifest conditions where the race can surface. Would you like me to create an issue to track it?

@silo-triage silo-triage Bot added bug Something isn't working go Pull requests that update go code impact: playback Can't play, stalls, or wrong media priority: P1 Core-path bug; painful workaround — next after P0 labels Nov 13, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

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: 284a1211-3c41-4dbf-85c9-3b0a996ad105
Commits

Reviewing files that changed from the base of the PR and between 2e05489 and 1f2f62e.

Files selected for processing: 11

  • docs/architecture/restart-resilient-playback.md
  • docs/architecture/worker-http-protocol.md
  • internal/jellycompat/auto_transcode_fallback_test.go
  • internal/jellycompat/handlers_playback.go
  • internal/jellycompat/streams.go
  • internal/playback/transcode_manager.go
  • internal/playback/transcode_manager_test.go
  • internal/playback/transcode_startup.go
  • internal/playback/transcode_startup_test.go
  • internal/transcodenode/auto_transcode_fallback_test.go
  • internal/transcodenode/server.go

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 1 remain after this review.

Comment on lines +104 to +105
session, err := startup.start(ctx, opts)
if err != nil || !HardwareDecodeRetryEligible(opts) {

@coderabbitai coderabbitai Bot Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Major · Performance & Scalability · Heavy lift

Keep NVENC when a reconstruct restores a CPU-decode retry.

A CPU-decode retry can start NVENC with SoftwareVideoDecode set and nvencSoftwareDecode set. NewRecipeCard persists only SoftwareVideoDecode. Under explicit NVENC, a later reconstruct uses a disabled pipeline, so nvencSoftwareDecode stays false. Normalization then selects HWAccelNone, and the rebuilt session can use libx264 instead of NVENC. The reconstruct also skips the decoder retry, because HardwareDecodeRetryEligible requires SoftwareVideoDecode to be false.

The recipe must keep the mixed-stage NVENC permission across reconstruction. Persisting a marker for this case changes the rule documented on nvencSoftwareDecode, which keeps reconstruction tied to live configuration. Choose a design that preserves that rule for auto while fixing the explicit NVENC case.

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 real, and it predates this change.

  • fix(playback): decode on the CPU when the GPU decoder rejects the source #4057 added the CPU-decode retry, and its Risks section lists this: a rebuild of a session that recovered that way re-resolves from live config and the card's CPU-decode flag, so it encodes with libx264.
  • This pull request doesn't change that path. It lets more sessions start, and the ones it adds never played before. A rebuilt session still plays, on the software encoder.
  • Keeping NVENC needs a new field on the recipe card, which also travels in the stream token. That is a design decision, so it belongs in its own change.

I'm raising it with the maintainer and leaving this thread open for them.

🤖 Claude Code (claude-fable-5-2)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working go Pull requests that update go code impact: playback Can't play, stalls, or wrong media priority: P1 Core-path bug; painful workaround — next after P0 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.

[bug] HEVC transcode fails on a GPU without HEVC decode: the startup retry repeats the same CUDA decode

1 participant