Skip to content

fix(playback): throttle a transcode whose starting request has ended - #4121

Merged
Quick104 merged 9 commits into
mainfrom
fix/rebuild-throttler-detached-context
Nov 14, 2026
Merged

Quick104 merged 9 commits into
mainfrom
fix/rebuild-throttler-detached-context

Conversation

@Quick104

@Quick104 Quick104 commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

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.StartInitialThrottler runs 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

  • Focused tests cover the rebuild, in 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 with context canceled and pass with the fix. The native fresh start calls the same method and has no test of its own.
  • A third test starts two throttlers on one running session and checks that the first stops. It fails on this pull request's first commit and passes with the second. A fourth stops a throttler that is over its threshold, runs one check, and expects no command; it fails on the second commit and passes with the third. The interleaving that produces two starts, a restart landing during the settings read, was traced in the source and not reproduced.
  • A fifth test runs a restart with no throttler armed, whose hook installs one on the old pipe and then times out, and checks that the new process ends up throttled at that threshold and the old throttler stopped; it fails on 19532e0 and on 1b9676e, and passes on 5921502. internal/playback, internal/jellycompat, and internal/transcodenode pass under -race, apart from two real-FFmpeg subtitle tests that fail the same way on unfixed main with the host's FFmpeg.
  • Not reproduced on a deployment. The test sandbox had no hardware transcoding backend, and without one a rebuild returns a few milliseconds after it spawns FFmpeg, which is too short a window to end a request in on purpose.
  • 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 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.
  • main is 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 unfixed main and pass on the merged head; the touched packages, go vet, and make lint-changed were rerun there.
  • The contract and hygiene targets pass: settings bindings, playback fixtures, route inventory, the /api/v2 OpenAPI, web types, contract, and fixtures checks, local paths, case collisions, size ratchet, bidi, and migrations.
  • Not run: 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

  • A settings read that takes longer than five seconds for a connected client now skips the throttle for that FFmpeg process, where before it waited for the database. The warning log records it.
  • When a client disconnects during a Jellyfin-compatible start and the database is slow, that start now holds the session's lifecycle lock for up to five seconds, where before the read failed at once.

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): git, GitHub CLI, Go toolchain (go build, go test, go vet), golangci-lint through make lint-changed, T3 Code delegated review tasks, Codex
  • Model(s): claude-fable-5-2 (implementation and review), claude-opus-5-5 (maintainer review and its fix), claude-opus-5-5 and gpt-6.1-sol (plan review), claude-sonnet-5-5 (review agents)
  • Involvement: Fully AI-generated (not yet human verified)
  • Adversarial review: Before implementation, gpt-6.1-sol checked the root cause and the plan and found the same read on both fresh-start paths, which widened the fix from the rebuild to all three first starts. claude-opus-5-5 confirmed the timeout is needed, because the database pool sets no acquire or statement timeout, and reduced the test. A multi-agent code review of the diff at high (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

  • Adds 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.restart now 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.StartThrottler now stops any throttler it replaces, and TranscodeThrottler.CheckOnce returns before sending pause/resume commands when the throttler has stopped.
  • Adds regression tests covering throttler startup after request cancellation, stale-pipe replacement, replaced-throttler stop, and no commands from a stopped throttler.
  • Behavioral Change: initial throttler startup now has a five-second deadline; if it expires, a warning is logged and throttler setup may be incomplete.

Macroscope summarized 5921502.

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

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Initial throttler startup now uses a detached context with a five-second timeout. Replacing a throttler stops the previous one, and a stopped throttler no longer sends pause or resume commands.

Changes: Transcode throttling

Layer / File(s) Summary
Initial throttler startup with detached context
internal/playback/transcode_manager.go, internal/api/handlers/playback_v3.go, internal/jellycompat/streams.go, internal/jellycompat/handlers_playback_config_test.go, internal/playback/transcode_manager_test.go
Reconstructed and newly started transcodes use StartInitialThrottler. It detaches settings reads from request cancellation and applies a five-second timeout. Tests check that throttling starts after the initiating request is canceled.
Throttler replacement and shutdown checks
internal/playback/transcode.go, internal/playback/throttle.go, internal/playback/transcode_close_test.go, internal/playback/transcode_manifest_test.go
Starting a throttler stops the previous throttler. CheckOnce returns if shutdown has started, without sending a pause or resume command. Tests cover replacement and shutdown behavior.

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

Change: Bug fix · Severity of issue fixed: Medium

Suggested reviewers: tomislav, coffeeknyte

Merge Risk: Minimal · up to dfb81

This change keeps transcodes throttled when the request that started them has ended, and prevents replaced or stopped throttlers from sending stale commands. No concrete merge-blocking risk was found.

Security architecture risk: Minimal · up to dfb81

The change restores resource limiting after a client disconnect and stops obsolete controllers from interfering with playback. The inspected changes do not establish a new access path, additional privileges, or a materially worsened failure-containment risk.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The changed controller directly affects the selected session's FFmpeg stdin, using fixed pause and resume commands. Failure of throttling can consume shared encoding-host resources, but the inspected change does not confer a new command-execution capability or select another session's process.

Trust Boundaries and Controls

  • observed — The native call-site substitution removes no authorization check: the previous wrapper only forwarded to the settings policy. Detachment applies to resource-control setup for an existing runtime, not to the preceding route and capability decisions. Upstream authorization was not comprehensively revalidated.

Resilience and Maintainability Implications

  • inferred — The deadline limits how long a cooperative settings read can retain reconstruction capacity after request cancellation. Replacement cleanup and the stopped-check guard improve failure containment by preventing displaced controllers from remaining active or issuing a late pause after Stop completes.
Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: a transcode whose starting request has ended now gets its throttle applied. The changeset adds StartInitialThrottler with a detached 5-second context for rebuild and f…
Linked Issues check Passed [#4114] requires a rebuilt transcode to start its throttler even when the triggering request has ended. The diff at internal/playback/transcode_manager.go replaces the direct StartThrottler(ctx, ...) …
Out of Scope Changes check Passed The change set has these parts: (1) StartInitialThrottler in transcode_manager.go, which is the direct fix for #4114. (2) The same helper applied to the native and Jellyfin-compatible fresh starts (pl…
Description check Passed The description is specific and on-topic. It explains the root cause (a settings read using a request context that ends early, leaving the throttle threshold at zero). It describes the fix (a five-sec…
Full details: Title check

Explanation

The title names the main change: a transcode whose starting request has ended now gets its throttle applied. The changeset adds StartInitialThrottler with a detached 5-second context for rebuild and fresh-start paths, stops replaced throttlers, and makes stopped throttlers send no commands. The title covers the primary fix and the scope is specific enough for a teammate scanning history.

Full details: Linked Issues check

Explanation

[#4114] requires a rebuilt transcode to start its throttler even when the triggering request has ended. The diff at internal/playback/transcode_manager.go replaces the direct StartThrottler(ctx, ...) call in doReconstructTranscode with StartInitialThrottler. That helper runs the callback with context.WithoutCancel(ctx) bounded by a 5-second timeout, so the settings read no longer depends on the request's lifetime. A warning is logged if the bound expires. The restart hook is unchanged, as the issue states. The issue's acceptance criterion is a coding change with a test, and the PR adds TestReconstructTranscodeStartsThrottlerAfterTriggeringRequestEnds in transcode_manager_test.go, per the change summary. I did not run that test. The transcode node is not changed, and the PR states it reads no settings. The issue lists this as unchecked, so this is not a gap in the coding requirements. Overall, the requirement is met by the code at the reviewed head.

Full details: Out of Scope Changes check

Explanation

The change set has these parts: (1) StartInitialThrottler in transcode_manager.go, which is the direct fix for #4114. (2) The same helper applied to the native and Jellyfin-compatible fresh starts (playback_v3.go, jellycompat/streams.go). These take the same request-scoped read and are the same root cause, so they are a reasonable extension. (3) TranscodeSession.StartThrottler in transcode.go stops the throttler it replaces. This is a lifecycle fix for the same throttler start path that the fix introduces. (4) TranscodeThrottler.CheckOnce in throttle.go returns before any command once stopCh is closed. This prevents a stopped throttler from changing FFmpeg state, which affects the same throttler. (5) Tests for each path. The changes do not touch workflows, web code, or unrelated modules. The added behavior is tied to throttler startup and stop, so I found no demonstrated unrelated change.

Full details: Description check

Explanation

The description is specific and on-topic. It explains the root cause (a settings read using a request context that ends early, leaving the throttle threshold at zero). It describes the fix (a five-second detached context in StartInitialThrottler), the replaced-throttler stop, the stopped-throttler check, the tests added, and the risks. It matches the changeset in internal/playback, internal/jellycompat, and the related test files.

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: 7b562e85-d351-47c0-9d67-c3b3eedcfc8e
Commits

Reviewing files that changed from the base of the PR and between 4448e40 and dfb816e.

Files selected for processing: 9

  • internal/api/handlers/playback_v3.go
  • internal/jellycompat/handlers_playback_config_test.go
  • internal/jellycompat/streams.go
  • internal/playback/throttle.go
  • internal/playback/transcode.go
  • internal/playback/transcode_close_test.go
  • internal/playback/transcode_manager.go
  • internal/playback/transcode_manager_test.go
  • internal/playback/transcode_manifest_test.go

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

@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-14T23:13:09.233368Z 5921502 New commits
🔒 Security Review ✅ Completed 2026-11-14T23:15:29.127253Z 5921502 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/api/handlers/playback_v3.go Resolved
@silo-triage silo-triage Bot added bug Something isn't working go Pull requests that update go code priority: P2 Limited scope, workaround exists, or polish labels Nov 13, 2026
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

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 ❌

Comment thread internal/playback/transcode.go Resolved
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

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 left a comment

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.

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)

Comment thread internal/playback/transcode.go Resolved
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

silo-kody Bot commented Nov 14, 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 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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".

Comment thread internal/playback/transcode.go Outdated
Comment on lines 4655 to 4657
if s.stdinPipe == nil || thresholdSeconds <= 0 || s.closing || s.restarting != nil {
s.mu.Unlock()
return

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge 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 👍 / 👎.

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.

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)

@Quick104

Quick104 commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor Author

Review summary

Reviewed head: 5921502dbe (19532e030d reviewed, then the fix below, revised twice). I merged current main into the branch first (19532e030d), because #1770 had since rewritten much of transcode.go around restarts.

Addressed

  • A first start whose settings read finished during a restart armed a throttler on the pipe that restart was replacing, and a timed-out restart hook then took it for the new process's throttler. Fixed in 5921502dbe: the hook's timeout fallback treats a throttler on the replaced process's pipe as no throttler and re-arms the new process with that throttler's threshold, which stops it. TestRestartHookTimeoutReplacesAThrottlerOnTheOldPipe fails on 19532e030d and passes on 5921502dbe. The first version of this fix (ccda4d0326) skipped every start during a restart; Codex's review showed that a restart aborted by its tone-map check then dropped the start for a process that kept running, so it was replaced (1b9676e4c8). Kody then showed that version re-armed with a threshold of zero when no throttler preceded the restart, which 5921502dbe fixes.

Remaining

Nothing for the maintainers to settle.

How it was checked

  • All four of the PR's own tests fail on unfixed main with the expected messages (context canceled for the rebuild and Jellyfin-compatible starts, the replaced throttler still running, a pause written after Stop) and pass on the head.
  • internal/playback, internal/jellycompat, and internal/transcodenode pass under -race, apart from two real-FFmpeg subtitle tests that fail the same way on main on the test host. make lint-changed is clean.
  • The restart path was traced: restart hooks already get a context detached from the request and bounded by restartHookTimeout, so leaving them unchanged is correct. Remote node starts read the threshold with the request context, but the node dispatch uses the same context and fails with it, so no remote transcode starts with a zero threshold. Rehome carries the threshold on the recipe card.
  • A multi-agent code review at high and a cross-provider round (gpt-6.1-sol) reviewed 19532e030d. All three reviewers independently reported the restart-window finding above, and nothing else held up. A delayed start that re-arms after an admin turns throttling off was set aside: the old code had the same window for a connected client.
  • Not reproduced live: the sandbox has no hardware transcoder, as the PR body says.

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 Validation tasks: none stands.

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 5921502dbe.

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

Fit: 9/10 · Readiness: 9/10 — ready (assuming CI is green)

  • Fit: it fixes a bug that silently switched off an on-by-default setting meant to save CPU, GPU, and disk on every transcode. The fix sits at the throttler boundary all three start paths share, with no new setting or API surface.
  • Readiness: tests that failed on the unfixed code now pass, the one review finding is fixed and covered, and the five-second bound improves on the old unbounded lock hold. It was not reproduced on a deployment.

🤖 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-triage silo-triage Bot added size/L 200–499 added + deleted lines (all files); change volume, not priority. and removed size/M 50–199 added + deleted lines (all files); change volume, not priority. labels Nov 14, 2026
@silo-kody

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

Comment thread internal/playback/transcode.go Outdated
// pipe. Keep the threshold this session had instead.
s.mu.Lock()
unthrottled := s.throttler == nil
unthrottled := s.throttler == nil || s.throttler.stdinPipe != s.stdinPipe

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

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.

​

​

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.

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)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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

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

if armed != nil {
threshold = armed.thresholdSeconds
}
s.StartThrottler(threshold)

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 Kody Rules high

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.

​

​

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.

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)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.

@Quick104
Quick104 merged commit e444af6 into main Nov 14, 2026
36 of 38 checks passed
@Quick104
Quick104 deleted the fix/rebuild-throttler-detached-context branch November 14, 2026 23:41
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 priority: P2 Limited scope, workaround exists, or polish 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] A rebuilt transcode runs without the throttle when the request that triggered it has ended

1 participant