Skip to content

fix(playback): start a rebuild's next FFmpeg attempt after the request that triggered it ends - #4110

Merged
Quick104 merged 2 commits into
mainfrom
fix/transcode-retry-detached-context
Nov 14, 2026
Merged

Quick104 merged 2 commits into
mainfrom
fix/transcode-retry-detached-context

Conversation

@Quick104

@Quick104 Quick104 commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Problem

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

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

Under Hardware acceleration set to Auto, a rebuilt transcode could fail with context canceled for every request waiting on it. It happened when the request that triggered the rebuild ended before the rebuild moved to its next fallback step, and the target was HEVC, a bitrate-capped VAAPI encode, or a stream with burned-in text subtitles. This change starts each attempt of a rebuild on a context that outlives that request, as the rebuild's wait already did.

Approach

runTranscodeStartup waited for each attempt's manifest on a context detached from the triggering request, but launched each attempt on that request's context. StartTranscode returns a cancelled context's error for those recipes before it runs FFmpeg, so the second attempt failed and the error went to every request sharing the rebuild. A rebuild now launches and waits on the same detached context. A fresh start still uses the request's context for both.

The first attempt is detached too. Once a rebuild is past admission it serves every waiting request, and detaching only the retries would leave the same failure for a request that ends just before the first start. Admission still runs on the request's context, so a cancelled request can leave the reconstruct queue as before.

The change covers the integrated manager and the transcode node, for native and Jellyfin playback. There is no API change.

Validation

  • Reported trigger with the real StartTranscode: with the request cancelled during the first attempt, the second attempt returned context canceled on main for HEVC on NVENC and for capped H.264 on VAAPI, and a session for H.264 on NVENC and uncapped VAAPI. With this change all four start.
  • Regression test: the existing rebuild test now ends the request during the first attempt. It fails on the merge base with context canceled and passes here.
  • Not reproduced on a deployment. The trigger needs a hardware backend whose first rebuild attempt exits early at the moment the triggering request ends.
  • Go gate: build, gofmt, go mod tidy -diff, go vet, make lint-changed, and make lint-router-recovery pass. make test-go passes except two real-FFmpeg tests that fail the same way on the merge base on the test host (FFmpeg 6.1.1): TestCopyRemuxSubtitleRenditionRealFFmpeg and TestRunStatsWithRealFFmpeg. Four packages needed a umask that keeps test temp directories private.
  • Web and generated-contract checks were not run; no web or contract file changed.

Evidence

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

Risks

A rebuild for these recipes now does what an H.264 rebuild already does on main: it runs to completion after its requester leaves. That extends three existing behaviors to them.

Follow-ups: #4112 for the Jellyfin stop race. #4114 for the missing throttle. #4113 for the explicit-backend start path, which has the same defect as this one on main.

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

🤖 Generated with Claude Code

…t that triggered it ends

A rebuilt transcode is shared by every request waiting on it. Its manifest
wait already ran on a context detached from the request that triggered it,
but each FFmpeg attempt was launched on that request's context. When the
request ended and the first attempt exited early, the next attempt returned
"context canceled" for an HEVC target, a capped VAAPI encode, or burned-in
text subtitles, and every waiting request got that error.

A rebuild now launches and waits on the same detached context. A fresh start
is unchanged.

Closes #4098

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 ❌

@coderabbitai

coderabbitai Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Reconstruction attempts now use a cancellation-detached context for both launching transcodes and waiting for the first manifest. Fresh starts continue to use the requester’s context. A test checks that reconstruction continues after the triggering request is canceled.

Changes: Transcode Reconstruction

Layer / File(s) Summary
Reconstruction attempt context
internal/playback/transcode_startup.go, internal/playback/transcode_startup_test.go
Reconstruction uses a detached context to start each attempt and wait for its first manifest. Fresh starts still use the request context. The test cancels the request during the first attempt and checks that later attempts run and return a session.

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

Change: Bug fix · Severity of issue fixed: Medium

Suggested reviewers: blurbery

Merge Risk: Minimal · up to ce949

Rebuilt transcodes now continue through their fallback attempts after the requesting client disconnects, matching the linked issue. The change is narrow and no merge-blocking risk is evident.

Security architecture risk: Minimal · up to ce949

The change prevents a disconnected request from aborting a rebuild shared by other requests. Existing admission, retry, session ownership and cleanup controls remain in place; no material security regression was established.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The changed lifetime affects admitted reconstruction work and requests sharing that playback session. Work may continue consuming host resources after the triggering request disconnects, but existing pacing and per-session serialization still apply.

Trust Boundaries and Controls

  • observed — Detachment occurs downstream of existing recipe and identity checks. The manager requires the recipe session ID to match; the node verifies presented stream tokens, checks transport compatibility and validates input-path authority before reconstruction startup.

Resilience and Maintainability Implications

  • observed — FFmpeg already received a session-owned cancellation context. Its monitor releases the hardware reservation, and session teardown cancels and reaps the process. Examined pre-launch work retains independent probe and staging deadlines; node shutdown serializes against reconstruction through the existing reload lock.
Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: rebuild FFmpeg attempts now run after the triggering request ends, which matches the raw summary (reconstruct attempts use a cancellation-detached context) and the obj…
Linked Issues check Passed [#4098] The defect cited in the issue is at internal/playback/transcode_startup.go. On the merge base, the wait used a detached context but each attempt launched with the request context. The diff at …
Out of Scope Changes check Passed The source change is limited to the reconstruct launch context and comments in internal/playback/transcode_startup.go, plus the existing rebuild test per the summary. The change connects directly to #…
Description check Passed The description is specific to the changeset. It names the rebuild path in runTranscodeStartup, the detached context for every attempt, the regression test, the validation runs, and the follow-up issu…
Full details: Title check

Explanation

The title names the main change: rebuild FFmpeg attempts now run after the triggering request ends, which matches the raw summary (reconstruct attempts use a cancellation-detached context) and the objectives (each attempt launches and waits on a detached context). It is specific enough for a teammate scanning history.

Full details: Linked Issues check

Explanation

[#4098] The defect cited in the issue is at internal/playback/transcode_startup.go. On the merge base, the wait used a detached context but each attempt launched with the request context. The diff at head changes the launch and the wait to one attemptCtx. For a reconstruct, attemptCtx is context.WithoutCancel(ctx), so every attempt launches and waits on a context that outlives the triggering request. A fresh start still uses the request context. The change matches the expected behavior in the issue. The author reports that the existing rebuild test now cancels the request during attempt 1 and fails on the merge base. The reported real StartTranscode trigger starts for all four configurations after the change. Uncertainty: the diff does not change internal/transcodenode/server.go. The PR description says the transcode node is covered. I did not confirm that the transcode node rebuild path calls runTranscodeStartup, so that part rests on the author's description. The issue's own technical notes say the node software retry already uses a detached context. Parts of the PR description (Jellyfin stop race, throttle) are follow-ups, not issue requirements.

Full details: Out of Scope Changes check

Explanation

The source change is limited to the reconstruct launch context and comments in internal/playback/transcode_startup.go, plus the existing rebuild test per the summary. The change connects directly to #4098. The comment changes describe the new behavior and the canceled-context error. The Jellyfin stop race (#4112), the missing throttle (#4114), and the explicit-backend start path (#4113) are named as follow-ups and are not in this diff. No unrelated file change was seen in the reviewed diff. The transcode node claim could not be checked against the diff, because server.go shows no change at head. The author describes it as covered by the same rebuild logic, so no out-of-scope change is shown.

Full details: Description check

Explanation

The description is specific to the changeset. It names the rebuild path in runTranscodeStartup, the detached context for every attempt, the regression test, the validation runs, and the follow-up issues. It matches the raw summary and the PR objectives, so it is not off-topic or vague.

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
Recent 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: 3833de2b-a3cb-4741-a2a1-fe569a5a6092
Commits

Reviewing files that changed from the base of the PR and between 4030ffb and ce949ab.

Files selected for processing: 2

  • internal/playback/transcode_startup.go
  • internal/playback/transcode_startup_test.go

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

@silo-triage silo-triage Bot added the size/S 0–49 added + deleted lines (all files); change volume, not priority. label Nov 13, 2026
@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-13T20:34:14.039616Z ce949ab New commits
🔒 Security Review ✅ Completed 2026-11-13T20:38:21.027160Z ce949ab 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.

Comment thread internal/playback/transcode_startup.go Resolved
@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
@Quick104
Quick104 merged commit 8f8e209 into main Nov 14, 2026
17 checks passed
@Quick104
Quick104 deleted the fix/transcode-retry-detached-context branch November 14, 2026 19:53
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/S 0–49 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 under Auto fails with context canceled when the request that triggered it ends before its fallback starts

1 participant