Skip to content

fix(playback): rebuild a transcode after the request that triggered it ends - #4125

Merged
Quick104 merged 2 commits into
mainfrom
fix/detach-rebuild-transcode-start
Nov 13, 2026
Merged

Quick104 merged 2 commits into
mainfrom
fix/detach-rebuild-transcode-start

Conversation

@Quick104

@Quick104 Quick104 commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Closes #4113
Related issue: N/A
Validation tasks: changes #1177 C3; changes #1178 C2

Other clients: Apple N/A (server-side recovery fix, no client change needed); Android N/A (same); Roku N/A (same)

When a transcode has to be rebuilt (after a server or node restart, or a lost FFmpeg process), every request for that session waits on one rebuild. If the request that triggered it ended before FFmpeg started, for example because the player seeked or timed out, the rebuild failed with context canceled and the other requests got an error instead of the stream. This change lets the rebuild finish once it has been admitted, whether or not that request is still connected.

It affects a rebuild that starts FFmpeg once: an explicit hardware backend, software, and any tone-mapped stream. StartTranscode returns an ended request's error before FFmpeg runs for an HEVC target, a bitrate-capped VAAPI encode, a tone-mapped stream, and burned-in text subtitles. #4110 fixes the later attempts of a rebuild under Hardware acceleration = Auto; this is the path it leaves alone.

Approach

Once a rebuild holds its reconstruct slot, TranscodeManager.doReconstructTranscode and the transcode node's spawnReconstruct run the rest of their preparation on a context detached from the request: the tone-map executor check, the choice of fallback order, and the FFmpeg start. The node already detached its tone-map check and its software retry; this makes the rest of the rebuild match.

Notes for review:

  • The context is detached in the two callers, not inside StartReconstructTranscode, because the steps that run before it also failed the rebuild. On the manager, the tone-map executor check returns the ended request's error when its probe cache is cold, which is the state after a restart. Under Auto, choosing the fallback order on an ended request can return a disabled pipeline, so a failed GPU attempt gets no CPU retry.
  • It does not edit runTranscodeStartup, so it merges cleanly with fix(playback): start a rebuild's next FFmpeg attempt after the request that triggered it ends #4110 in either order.
  • Waiting for a reconstruct slot still ends with the request, and that request's error still goes to every request sharing the rebuild. That is existing behavior and a separate design question; this change leaves it alone.

Jellyfin clients reach the same manager and node code, so they get the same fix. No API, setting, or client change.

Validation

  • Reproduced on a Silo dev deployment (single server, software encoding), then gone on a build of this change. Steps and results are on the evidence page.
  • Two new tests, one on the manager and one on the transcode node, fail on the merge base with context canceled and pass here. Reverting any one of the six detached call sites makes one of them fail.
  • Go gate: build, gofmt, go mod tidy -diff, go vet, make lint-changed, and make lint-router-recovery pass. make test-go passes for internal/transcodenode. It fails in internal/playback (one real-FFmpeg subtitle test), internal/api/handlers, internal/backup, internal/ebookconvert, internal/mediasample, and internal/uploads. The same packages fail on the merge base on this host; the failures I read come from the host's temp directory mode and FFmpeg build.
  • Not checked live: the transcode node path (covered by its test only), and the HEVC, capped VAAPI, and tone-mapped recipes (no GPU on the test deployment). Web checks were not run; the change has no web code.

Evidence

Nothing visible changes. With a burned-in text subtitle, the session lost to a server restart, and two manifest requests 10 ms apart:

First request dropped after Second request, main at 4030ffb Second request, this change at cd64abe
30 ms 404, log reconstruct transcode start failed error="context canceled" 200, log transcode process reconstructed from recipe card
45 ms 404, same log line 200, same log line
5000 ms (control) 200 200

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

Risks

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 subagents, T3 Code delegated review tasks (Codex and Claude), git, Go (go test), GitHub CLI
  • Model(s): claude-fable-5-2 (implementation, review), gpt-6.1-sol and claude-opus-5-5 (plan review), claude-sonnet-5-5 (review subagents)
  • Involvement: Fully AI-generated (not yet human verified)
  • Adversarial review: Plan review before implementation: gpt-6.1-sol proposed detaching once per caller after admission instead of at the two start calls, and found the fallback-order and tone-map steps that the narrower change missed; adopted. claude-opus-5-5 cut the tests from three to two and confirmed the tone-map step belongs here. Code review at high (three finder agents and a validation agent; I checked each finding against the source myself): no defect introduced by the diff; the dropped deadline, the missing overall time limit, and the [bug] A transcode rebuild that finishes after a Jellyfin client stops playback leaves FFmpeg running #4112 and [bug] A rebuilt transcode runs without the throttle when the request that triggered it has ended #4114 extensions are listed under Risks. A simplify pass changed one test comment. Background adversarial review after opening (gpt-6.1-sol, reviewed cd64abe): no new findings, nothing posted; it confirmed both tests fail on the merge base and pass on the change. The later commit only moves a test, so it was not reviewed again.

🤖 Generated with Claude Code

Note

Fix transcode reconstruction being canceled when the triggering request ends

Rebuilds triggered by playback now outlive the request that started them. After a reconstruction slot is acquired, playback.TranscodeManager.doReconstructTranscode and transcodenode.Server.spawnReconstruct create a context without the request's cancellation or deadline, and use it for pipeline creation, tone-map executor resolution, transcode start, and the software-encoding retry.

  • Slot admission and request validation still respect the request context, so canceled requests cannot start new reconstructions
  • Adds tests covering reconstruction success when the triggering request is canceled after admission, in both transcode_manager_test.go and auto_transcode_fallback_test.go

Macroscope summarized 8dae501.

…t ends

A rebuilt transcode serves every request waiting on it, but its tone-map
check, fallback order and FFmpeg start ran on the context of the request that
triggered it. When that request ended, StartTranscode returned its error
before FFmpeg ran for an HEVC target, a capped VAAPI encode, a tone-mapped
stream and burned-in text subtitles, and the other requests got the error.

Once a rebuild holds its reconstruct slot, the manager and the transcode node
now run those steps on a context detached from the request. Waiting for the
slot still ends with the request.

Closes #4113

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

coderabbitai Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

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

  • Ask an admin to enable usage-based reviews

Open in CodeRabbit

Reviews can continue after your included limit without a manual trigger. An admin must approve usage-based billing.

Next included review available in 2 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: 687b886b-421a-4b53-863b-df3cf9d072d8
Commits

Reviewing files that changed from the base of the PR and between b6b7dd3 and 8dae501.

Files selected for processing: 4

  • internal/playback/transcode_manager.go
  • internal/playback/transcode_manager_test.go
  • internal/transcodenode/auto_transcode_fallback_test.go
  • internal/transcodenode/server.go
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

@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-13T21:26:05.415722Z 8dae501 New commits
🔒 Security Review ✅ Completed 2026-11-13T21:31:22.535331Z 8dae501 New commits
ℹ️ 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.

@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
Comment thread internal/playback/transcode_manager.go Resolved
…quest's test

Moves TestReconstructTranscodeOutlivesTriggeringRequest above its neighbour.
Another open pull request adds a test at the same spot, and the two would
conflict whichever merged second. No test or code changes.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
@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 ❌

@Quick104
Quick104 merged commit 968d814 into main Nov 13, 2026
22 checks passed
@Quick104
Quick104 deleted the fix/detach-rebuild-transcode-start branch November 13, 2026 22:57
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/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] A rebuilt transcode on an explicit hardware backend fails with context canceled when the request that triggered it ends before FFmpeg starts

1 participant