Repository navigation
fix(playback): throttle a transcode whose starting request has ended - #4121
Conversation
A transcode's first throttler start read its settings with the context of the request that started or rebuilt it. When that request had ended, the read failed, the threshold resolved to zero, and FFmpeg ran without the configured forward-buffer limit until its next restart. Start the first throttler with a context detached from the request and bounded at five seconds, for rebuilds and for native and Jellyfin fresh starts. Restart hooks keep their FFmpeg context, which Close cancels. Closes #4114 Co-Authored-By: Claude Fable 5.2 <[email protected]>
Silo Kody — review completeReview finished. Check the inline comments for findings and verify each suggestion against the code and tests. Reviewing changes in Silo
Review settingsReview OptionsThe following review options are enabled or disabled:
|
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
A transcode's first throttler start can finish after a restart hook has armed one, on the native start path that sets it up outside the session lifecycle lock. The later start overwrote the session's throttler without stopping it, leaving one that nothing could stop until the session ended. Co-Authored-By: Claude Fable 5.2 <[email protected]>
Silo Kody — review completeReview finished. Check the inline comments for findings and verify each suggestion against the code and tests. Reviewing changes in Silo
Review settingsReview OptionsThe following review options are enabled or disabled:
|
A check that had read progress before Stop took the lock could still pause FFmpeg afterwards. Stop used to precede the process ending, so that was harmless. Now that a later start stops the throttler it replaces while the process lives on, the replacement never saw the pause and would not resume it. A stopped throttler's check now returns without sending anything. Co-Authored-By: Claude Fable 5.2 <[email protected]>
Silo Kody — review completeReview finished. Check the inline comments for findings and verify each suggestion against the code and tests. Reviewing changes in Silo
Review settingsReview OptionsThe following review options are enabled or disabled:
|
…-detached-context # Conflicts: # internal/playback/transcode_manager_test.go
…-detached-context
…-detached-context
Quick104
left a comment
There was a problem hiding this comment.
Review of 19532e0 (this branch with current main merged in). One low-severity finding, below. I'm fixing it in a commit on this branch, so there's no need to change it yourself. The summary comment follows once the fix is pushed.
🤖 Claude Code in T3 Code (claude-opus-5-5)
A first start whose settings read finished during a restart bound a throttler to the old FFmpeg's stdin. If the restart hook then timed out, its fallback took that throttler for the new process's and left the new process unthrottled. The restart hook arms the new process's throttler. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Silo Kody — review completeReview finished. Check the inline comments for findings and verify each suggestion against the code and tests. Reviewing changes in Silo
Review settingsReview OptionsThe following review options are enabled or disabled:
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ccda4d0326
ℹ️ 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".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if s.stdinPipe == nil || thresholdSeconds <= 0 || s.closing || s.restarting != nil { | ||
| s.mu.Unlock() | ||
| return |
There was a problem hiding this comment.
Preserve a pending throttle start when restart validation fails
If the native initial settings read finishes while a concurrent restart is validating a tone-mapped source, this guard discards the throttle start. However, restart() sets s.restarting before validateToneMapSource, and a validation failure or probe timeout clears it and returns without replacing the existing process or invoking the restart hook. The original FFmpeg therefore remains running with no throttler, potentially encoding the entire remaining file despite throttling being enabled. Preserve or retry the pending start when validation aborts, rather than assuming every restart flight will arm a replacement throttler.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Confirmed: restart() sets restarting before the tone-map check, and a failed check clears it without replacing FFmpeg or running the hook, so ccda4d0 could drop a first start for a process that kept running.
Fixed in 1b9676e. StartThrottler arms as it did before ccda4d0. Instead, the restart hook's timeout fallback now treats a throttler on the replaced process's pipe as missing (s.throttler.stdinPipe != s.stdinPipe) and re-arms the new process with the session's previous threshold, stopping the stale one. A restart that aborts never reaches that fallback, so a start landing during it keeps its throttler on the live process.
TestRestartHookTimeoutReplacesAThrottlerOnTheOldPipe runs a restart whose hook installs a throttler on the old pipe and then times out. It fails on 19532e0 and passes on 1b9676e. internal/playback passes under -race.
🤖 Claude Code in T3 Code (claude-opus-5-5)
Review summaryReviewed head: Addressed
Remaining Nothing for the maintainers to settle. How it was checked
Validated features: no passed case regresses. #1177 C3 (remove an active worker, failover) reaches the rebuild path this PR changes, and the rebuilt transcode now gets its throttle. The failover and cleanup that the case checks are unchanged, so User manual: unaffected. The playback page already describes the throttle as applying whenever it's on, and this PR makes that true. Other clients: N/A. The change is server-side only. Evidence: refreshed for Fit: 9/10 · Readiness: 9/10 — ready (assuming CI is green)
🤖 Claude Code in T3 Code (claude-opus-5-5) |
…the old pipe ccda4d0 skipped every throttler start while a restart was in flight. A restart that fails its tone-map check clears that flag without replacing FFmpeg or running its hook, so a first start landing then was dropped and the running process stayed unthrottled. Arm as before, and have the restart hook's timeout fallback treat a throttler on the replaced process's pipe as no throttler, so it re-arms the new process with the session's previous threshold. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Silo Kody — review completeReview finished. Check the inline comments for findings and verify each suggestion against the code and tests. Reviewing changes in Silo
Review settingsReview OptionsThe following review options are enabled or disabled:
|
| // pipe. Keep the threshold this session had instead. | ||
| s.mu.Lock() | ||
| unthrottled := s.throttler == nil | ||
| unthrottled := s.throttler == nil || s.throttler.stdinPipe != s.stdinPipe |
There was a problem hiding this comment.
Timeout fallback loses a threshold armed during the restart
A delayed settings read can arm a throttler on the old pipe, but a restart-hook timeout then leaves the new process unthrottled. Preserve the old-pipe throttler's threshold instead of calling StartThrottler(0) on timeout.
Prompt for LLM
File internal/playback/transcode.go, line 4073:
Timeout fallback loses a threshold armed during the restart
If the initial settings read finishes after `StopThrottler` returned zero, the newly permitted start binds a throttler to the old pipe, but a subsequent restart-hook timeout calls `StartThrottler(0)` and leaves the new process unthrottled. Preserve the old-pipe throttler's threshold when selecting the timeout fallback.
Talk to Kody by mentioning @kody
Was this suggestion helpful? React with 👍 or 👎 to help Kody learn from this interaction.
There was a problem hiding this comment.
Confirmed. When the first start lands after StopThrottler found nothing, previousThrottleSeconds is 0, so the fallback's StartThrottler(0) armed nothing and the stale throttler stayed on the old pipe.
Fixed in 5921502. When the armed throttler is on the replaced pipe, the fallback re-arms with that throttler's threshold, which came from the newer settings read, and replacing it stops the stale one. TestRestartHookTimeoutReplacesAThrottlerOnTheOldPipe now arms no throttler before the restart and has the hook install one at 90 seconds on the old pipe. It fails on 1b9676e and on 19532e0, and passes on 5921502. That test also checks the threshold is 90 and the stale throttler stopped. internal/playback passes under -race.
🤖 Claude Code in T3 Code (claude-opus-5-5)
There was a problem hiding this comment.
Thanks for confirming. The reported fix addresses the zero-threshold fallback and adds a regression test for the stale-pipe interleaving. Based on the results you provided, the test also verifies that the stale throttler stops, and internal/playback passes under the race detector.
No further action taken.
…ook times out When the first start armed its throttler on the old pipe after the restart had stopped none, the timeout fallback re-armed with the restart's previous threshold of zero, which starts nothing, so the new process stayed unthrottled. Re-arm with the stale throttler's threshold, read after StopThrottler, which also stops the stale throttler. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Silo Kody — review completeReview finished. Check the inline comments for findings and verify each suggestion against the code and tests. Reviewing changes in Silo
Review settingsReview OptionsThe following review options are enabled or disabled:
|
| if armed != nil { | ||
| threshold = armed.thresholdSeconds | ||
| } | ||
| s.StartThrottler(threshold) |
There was a problem hiding this comment.
Restart fallback can overwrite a concurrently installed throttle threshold
Revises an earlier Kody suggestion on internal/playback/transcode.go:4073 (2026-11-14 23:05 UTC).
An initial settings read can install a newer threshold after current is checked, only for the fallback to replace it with stale previousThrottleSeconds. Recheck the active throttler under the same synchronization used to replace it, and retain its threshold if it was installed in the meantime.
Kody rule violation: Bound lifecycle hooks and retire replaced throttlers
Prompt for LLM
File internal/playback/transcode.go, line 4082:
**Revises an earlier Kody suggestion** on `internal/playback/transcode.go:4073` (2026-11-14 23:05 UTC).
Restart fallback can overwrite a concurrently installed throttle threshold
Make the check and fallback replacement atomic with respect to initial throttler startup. An initial settings read can finish after `current` is checked but before this call, installing a throttler with the newer threshold; this fallback then replaces it with the stale `previousThrottleSeconds`. Recheck the active throttler while holding the same synchronization used to replace it, and retain its threshold if it was installed in the meantime.
Kody rule violation: [Bound lifecycle hooks and retire replaced throttlers](https://kodus.siloserver.org/settings/code-review/1247142351/kody-rules/bfd957d4-ceec-4533-ac9d-d61b6185cb45?teamId=ba9922fc-c0ea-4cf8-87bb-9d4f42ffc73e)
Talk to Kody by mentioning @kody
Was this suggestion helpful? React with 👍 or 👎 to help Kody learn from this interaction.
There was a problem hiding this comment.
The window is real but its outcome is benign, so I'm leaving this as is.
If a first start arms a current throttler between the current check and StartThrottler(previousThrottleSeconds), then either previousThrottleSeconds is 0, in which case StartThrottler returns early and the new throttler stays, or it is positive, in which case the new process stays throttled at the threshold this session ran with before the restart. That threshold differs from the newer read only if an admin changed the setting within those few seconds, and the next restart re-reads it. The throttler it replaces is stopped by StartThrottler, so none is left running.
The same check-then-start gap existed before this PR (s.throttler == nil, then StartThrottler), when the replaced throttler was not stopped at all. Closing it would mean moving the check inside StartThrottler's lock for a case whose worst result is a threshold a few seconds out of date.
🤖 Claude Code in T3 Code (claude-opus-5-5)
There was a problem hiding this comment.
That’s a reasonable decision to leave this unchanged. The check-then-start window is real, but StartThrottler returns without replacing the newly installed throttler when the fallback threshold is zero; when the fallback threshold is positive, it replaces and stops the existing throttler. See internal/playback/transcode.go:4072–4083 and :4660–4675.
One qualification: the stale threshold can remain in effect until the next restart, not merely for a few seconds. The few seconds describe the settings-change window that can produce the mismatch, assuming the reads otherwise reflect the same settings. That matches the existing timeout warning and is a reasonable tradeoff if the team accepts that behavior.
I’ll withdraw the suggestion as a blocking finding; no change is necessary for this PR on that basis.
Problem
Closes #4114
Related issue: N/A
Validation tasks: none
Other clients: N/A (no client-visible change)
A transcode could run without the transcode throttle when the request that started or rebuilt it had ended before the throttler was set up. FFmpeg then encoded ahead of the viewer without the configured forward-buffer limit until the session's next restart, using the CPU, GPU, and disk the setting exists to save. With this change the throttler starts whether or not that request is still connected.
The first throttler start read its two settings with the request's context. A transcode outlives that request: other requests wait on the same rebuild, and a Jellyfin-compatible start stays registered for the client's retry. Once the request ended, the read failed and the threshold resolved to zero.
Approach
TranscodeManager.StartInitialThrottlerruns the existing throttler hook with a context detached from the request and bounded at five seconds. The rebuild, the Jellyfin-compatible fresh start, and the native fresh start all call it. The issue reports the rebuild. The two fresh starts did the same read after registering their transcode, so they are fixed here too.The bound exists because the rebuild and the Jellyfin-compatible start hold the session lifecycle lock across the read, and the rebuild also holds a reconstruct slot. Before this change, a connected client's read could hold them for as long as the database stalled. When the bound expires, the transcode runs unthrottled until its next restart, as it already does for any unreadable setting, and the server now logs a warning with the session ID.
A throttler start now also stops the throttler it replaces. The native fresh start sets its throttler up after releasing the lifecycle lock, so a restart of the same session can arm one first. Before this change the later start left that one running where nothing could stop it until the session ended. A stopped throttler's check also sends no command now: a check already under way when the stop arrived could otherwise pause FFmpeg, and the replacement would not resume it. A first start that finishes while a restart is replacing the process arms its throttler on the old FFmpeg's pipe. When the restart hook then times out, its fallback now treats a throttler on the replaced pipe as no throttler and re-arms the new process with that throttler's threshold, which came from the newer settings read; before, it took that throttler for the new process's and left the new process unthrottled.
Restart hooks are unchanged. They keep the context a restart gives them, which ends when the session closes or the restart's own five-second bound passes.
The transcode node is unaffected. It receives the resolved threshold as a number and reads no settings.
Validation
internal/playback, and the Jellyfin-compatible fresh start. Each ends the request while the transcode starts and checks the context the throttler start receives. Both fail on the unfixed base withcontext canceledand pass with the fix. The native fresh start calls the same method and has no test of its own.internal/playback,internal/jellycompat, andinternal/transcodenodepass under-race, apart from two real-FFmpeg subtitle tests that fail the same way on unfixedmainwith the host's FFmpeg.gofmt,go mod tidy -diff,go vet,make lint-changed, andmake lint-router-recoverypass.make test-gopasses except two tests that drive the host's FFmpeg 6.1.1 (subtitle rendition seek and media sample stats); both fail the same way on the unfixed base.mainis merged in three times, most recently at 91611b4; an earlier merge at 4448e40 changed the same rebuild function. The focused tests still fail on that unfixedmainand pass on the merged head; the touched packages,go vet, andmake lint-changedwere rerun there./api/v2OpenAPI, web types, contract, and fixtures checks, local paths, case collisions, size ratchet, bidi, and migrations.verify-actionlint,verify-shellcheck,verify-prometheus-rules, and the web lint, build, budget, and test targets. The change touches no workflow, shell script, alert rule, or web file.Evidence
Nothing a user sees changes. The evidence page has the failing runs of the tests on the unfixed code, the passing runs with the fix, and the commits they ran on.
Evidence: https://evidence.siloserver.org/r/silo-server/issue-4114/
Risks
Checklist
AI Disclosure
go build,go test,go vet), golangci-lint throughmake lint-changed, T3 Code delegated review tasks, Codexhigh(claude-fable-5-2 and claude-sonnet-5-5 finders and verifiers) found no blocking defect; it led to the timeout warning log and to the risks listed above. The Kody review reported that a first start finishing after a restart left the replaced throttler running, and then that the stopped throttler could still pause FFmpeg; the second and third commits fix those. A simplify pass changed nothing. After the pull request opened, gpt-6.1-sol ran an adversarial review of fc22160 (the first commit) covering cancellation, shutdown, the native, Jellyfin-compatible, and rehome callers, and the new tests; it reported no findings. It did not review the second or third commit. A maintainer review of 19532e0 (claude-opus-5-5 with claude-opus-5-5 and claude-sonnet-5-5 review agents, and a gpt-6.1-sol cross-provider round, which also ran the touched packages under-race) found that a first start finishing during a restart armed a throttler on the old process's pipe. A first fix (ccda4d0) skipped starts during a restart; Codex's review of it showed that a restart aborted by its tone-map check would then drop the start for a process that kept running, and 1b9676e replaces it with a check in the restart hook's timeout fallback. Kody then showed that fallback re-armed with a threshold of zero when no throttler preceded the restart; 5921502 uses the stale throttler's threshold. No other findings.🤖 Generated with Claude Code
Note
Fix throttler startup and cleanup when a playback transcode's request ends
TranscodeManager.StartInitialThrottler, which starts the throttler with a context detached from the request and bounded by a new five-second timeout (initialThrottleSettingsTimeout) in transcode_manager.go. Local transports, compatibility transcodes, and reconstructions now use this path instead of the request context.TranscodeSession.restartnow replaces a throttler armed on the old process pipe after a restart-hook timeout, starting one on the current pipe while preserving the threshold from the startup race.TranscodeSession.StartThrottlernow stops any throttler it replaces, andTranscodeThrottler.CheckOncereturns before sending pause/resume commands when the throttler has stopped.Macroscope summarized 5921502.