You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
refactor(playback): share one alternate-version fallback between start and replan - #3947
Related issue: #3407
Validation tasks: none. #1177 C3 (worker failover) replans through this code, with no intended change.
A start and a replan both look for another version of the item when the planner refuses the one they planned. They try each version, hold back one that drops the viewer's subtitle in case none keeps it, then try the refused file without its subtitle. The two handlers held that algorithm as two loops of about 100 lines each that differed in a handful of details, so a fix to one had to be repeated in the other. The planner input was also written out inline at eleven call sites, each a one-line struct literal of ten to thirteen fields.
This change keeps one loop and one input builder. It is stacked on #3946 and is the second of three pull requests for #3407.
Approach
planAlternateVersionV3 is the one search. What differs between a start and a replan is passed in through alternateFallbackV3: which versions to try, how the viewer's tracks move onto each, the replan's fixed refusal message, and the replan's rule that the requested edition outranks other held-back versions.
plannerInputV3 builds the planner input from what the planning passes of one start or replan share.
Behaviour is unchanged, including the places where a start and a replan differ today: they still move tracks from different files, and only a replan skips the refused file among the alternates. Those differences are now visible as parameters; reconciling them is a product decision for later, not part of this change.
Each call site still lists downloaded subtitles and creates its Dolby Vision probe as often as before. The lower-bitrate version probe and the audio-track refinement still plan without a lower version or attempted keys, and the escalation of a refused progressive remux still reads settings again.
Validation
Go gate (go build, go vet, gofmt, make lint-changed): pass on this branch.
Playback, handler, watch-together and v2 API package tests: pass, with the same two FFmpeg-dependent exceptions as the first pull request. The handler playback tests also pass under the race detector.
make verify-playback-fixtures: no diff.
The full Go and generated-contract gate ran at the top of the stack. The web gate was not run; no web file changes.
As part of the stack, 4,392 start and replan requests were replayed against the merge base and the stack's tip on two sandboxes with worker nodes: identical decisions. The replay included 366 starts on items with several versions, with alternate versions allowed and disallowed, a subtitle only one version has, and a bandwidth estimate that only a lower version fits.
Not reached by the replay: the subtitle_not_shown warning and the subtitle_unavailable_in_version refusal; the test library has no item that triggers them. An existing handler test covers the first; no test covers the second.
The fallback decides which version plays after a refusal. An unintended difference would show as a different version, a dropped subtitle, or a refusal where a version used to play. The merged search was compared branch by branch with both originals in review.
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 says there is none.
AI Disclosure
Harness: Claude Code in T3 Code
Tool(s): Claude Code
Model(s): claude-fable-5-2, with claude-opus-5-5 subagents
Involvement: Fully AI-generated at the maintainer's direction; the maintainer has not yet reviewed the diff
Adversarial review: one independent read-only review of all three pull requests in this stack by a claude-opus-5-5 subagent. It found no defects and six comment or doc inaccuracies, all corrected before opening. A simplify pass ran on each commit.
Share one alternate-version fallback between start and replan in playback V3
Consolidates start and replan planning into a shared planningV3 state and shared PlannerInputV3 constructors (plannerInputV3, plannerInputWithSubtitlesV3) in playback_v3.go
Adds a common alternate-version loop (planAlternateVersionV3, alternateFallbackV3) used by both start and replan paths. It probes and access-checks candidates, holds back playable candidates that drop subtitles, and prefers the requested edition
Moves refusal classification from handler-local reason matching to PlannerResultV3 methods (AnotherVersionMayPlay, SubtitleRefusal, ToneMapDependentRefusal) in plan_refusal_v3.go, with exported terminal constants in protocol_v3.go
Adds SettingsDependentRefusal to PlannerResultV3. HDR and 4K-setting refusals now carry it, so retryIncompletePlaybackSettingsV3 converts only setting-driven refusals to retryable failures instead of matching on messages
Risk: retry behavior in retryIncompleteToneMapPlanningV3 and retryIncompletePlaybackSettingsV3 changes — refusals no longer marked as settings- or tone-map-dependent stay terminal. Check that all setting-driven refusals in planVideoTranscodeV3 go through settingsRefusalV3
The start and replan handlers decide what to try after a planner refusal:
another version, the same file without its subtitle, or a retry when
settings or tone-map capabilities failed to load. They decided it from
the planner's strings. Two reasons were re-declared as literals in the
handler, and the settings case matched message text.
The answers now live in internal/playback next to the code that produces
the refusals, as AnotherVersionMayPlay, SubtitleRefusal and
ToneMapDependentRefusal on PlannerResultV3. The planner marks the four
refusals a setting decides with SettingsDependentRefusal, which replaces
the message matching. no_alternate_version and
subtitle_conversion_unsupported are declared once and shared with the
watch-together source fallback.
No change in planner output or in what a client receives.
Part of #3407.
Co-Authored-By: Claude Fable 5.2 <[email protected]>
…t and replan
A start and a replan both look for another version of the item when the
planner refuses the one they planned: try each version, hold back one
that drops the subtitle, then try the refused file without its subtitle.
The two handlers held that algorithm as two near-identical loops, and
the planner input was written out inline at eleven sites.
planAlternateVersionV3 is now the one loop. What differs between a start
and a replan is passed in: which versions to try, how the viewer's
tracks move onto each, the replan's fixed refusal message and its
preference for the requested edition. plannerInputV3 builds the planner
input from what the passes of one start or replan share.
Each site lists downloaded subtitles and creates its Dolby Vision probe
as often as before. The escalation of a refused progressive remux still
reads settings again, as it did.
No change in what a client receives.
Part of #3407.
Co-Authored-By: Claude Fable 5.2 <[email protected]>
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).
File: No configuration file from this repository applied
Commit: Unavailable
Layers: Organization UI
Review profile: CHILL
Plan: Advanced
Run ID: a2218148-7410-4b0d-82b4-1a17a707ca26
Commits
Reviewing files that changed from the base of the PR and between 478f1d9 and ac9bba9.
Files selected for processing: 2
internal/api/handlers/playback_connection.go
internal/api/handlers/playback_v3.go
Walkthrough
Start and replan flows now share planner-input state and alternate-version fallback logic. Candidate planning checks access and preflight results, remaps track selections, and prefers playable alternatives that retain subtitles. Audio-track planning and progressive-remux escalation also reuse shared planner inputs.
Changes: Playback planning
Layer / File(s)
Summary
Shared planning state and inputs internal/api/handlers/playback_v3.go
A shared planning snapshot now carries requested-file data, settings, lower-version information, and attempted keys. Start and replan paths use planner-input helpers.
Alternate-version selection and planning internal/api/handlers/playback_v3.go
Start and replan paths use shared alternate selection. Candidate planning checks access, remaps tracks, skips preflight failures, and applies subtitle-aware fallback behavior.
Other planner call sites internal/api/handlers/playback_connection.go, internal/api/handlers/playback_v3.go
Audio-track candidates and progressive-remux escalation reuse planner inputs. Alternate-version connection planning uses the shared input helper.
sequenceDiagram
participant planStartV3
participant planAlternateVersionV3
participant planAlternateCandidateV3
participant PlaybackPlanner
planStartV3->>planAlternateVersionV3: Provide candidates and track mapping
planAlternateVersionV3->>planAlternateCandidateV3: Plan an alternate candidate
planAlternateCandidateV3->>PlaybackPlanner: Submit accessible candidate with remapped tracks
PlaybackPlanner-->>planAlternateCandidateV3: Return candidate plan
planAlternateCandidateV3-->>planAlternateVersionV3: Return candidate result
planAlternateVersionV3-->>planStartV3: Return selected plan or fallback
Silo-Server/silo-server#3009: Both changes preserve audio and subtitle selections during media-version fallback. This change also prefers candidates that retain subtitles.
Suggested reviewers:blurbery
Merge Risk: Minimal · previous review 478f1
The change consolidates start and replan alternate-version fallback without an intended user-visible change, and no concrete defect was found. The one remaining suggestion is to add a test for the subtitle refusal path, which is currently untested. This does not block merge.
Security architecture risk: Minimal · up to 478f1
The refactor preserves existing access restrictions and recovery safeguards. No material security risk introduced or worsened by this change was found.
Retained concerns
No architecture-level concerns identified.
Security review details
Security Blast Radius
inferred — The affected authority remains playback selection for the requesting viewer. Alternate discovery is bounded to the source content or episode and applies existing library, quality, edition, and presentation restrictions; replan additionally checks session ownership against the authenticated user and profile.
Trust Boundaries and Controls
observed — Start and replan continue supplying a request-derived access filter to sibling discovery. The shared candidate planner rechecks authorization after probing, before track mapping and planning, including appended requested-edition candidates. These controls existed in both base loops. The inspected access-filter test asserts rejection of disallowed-library, excessive-quality, and missing siblings.
Resilience and Maintainability Implications
observed — The refactor leaves replan serialization, stale-plan checks, idempotency leases, and cancellation-independent lease release unchanged. Failed replacement commits retain transport-cancellation-before-session-restore rollback; successful transport commit and route-event handling remain after durable completion. Planning extraction does not introduce a new partial-commit path.
Pre-merge checks: 4
Check name
Status
Explanation
Title check
The title clearly and concisely identifies the main change: sharing alternate-version fallback logic between start and replan paths.
Linked Issues check
Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check
Check skipped because no linked issues were found for this pull request.
Description check
The description directly explains the consolidation of alternate-version fallback logic and shared planner-input construction described in the changeset.
Finishing Touches
Generate docstrings
Commit to this branch
Create a new PR
Generate unit tests (beta)
Commit to this branch
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
The reason will be displayed to describe this comment to others. Learn more.
Nitpick comments: 1
internal/api/handlers/playback_v3.go: 1
1957-1957: Trivial · Maintainability & Code Quality · Heavy lift
Add a regression test for an alternate whose subtitle selection cannot move.
Line 1957 makes the mapping error a non-retryable refusal. The shared planner can retain that refusal or select a later playable alternate. The reported replay did not reach this branch, and no test was reported for the refusal. Test both outcomes in start and replan planning. (raw.githubusercontent.com)
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: 56f8c59a-0e92-45ea-b3f8-e9b8a00d90a8
Commits
Reviewing files that changed from the base of the PR and between 39e90da and 478f1d9.
Files selected for processing: 2
internal/api/handlers/playback_connection.go
internal/api/handlers/playback_v3.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.
Base automatically changed from
refactor/playback-refusal-contract to
mainNovember 11, 2026 19:19
Main replaced the planner's route walk with a candidate list (#3948), so
the surround conversion moves from a branch in the walk to a candidate
route that ranks ahead of the original file. It stays one candidate: it
converts to the first of E-AC-3 and AC-3 that the sink validates and an
HLS executor offers, so a tried conversion falls back to the route it
improved on, and an AC-3-only executor pool still converts. The start
and replan fallbacks take main's shared planner input (#3947).
Co-Authored-By: Claude Opus 5.5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Related issue: #3407
Validation tasks: none. #1177 C3 (worker failover) replans through this code, with no intended change.
A start and a replan both look for another version of the item when the planner refuses the one they planned. They try each version, hold back one that drops the viewer's subtitle in case none keeps it, then try the refused file without its subtitle. The two handlers held that algorithm as two loops of about 100 lines each that differed in a handful of details, so a fix to one had to be repeated in the other. The planner input was also written out inline at eleven call sites, each a one-line struct literal of ten to thirteen fields.
This change keeps one loop and one input builder. It is stacked on #3946 and is the second of three pull requests for #3407.
Approach
planAlternateVersionV3is the one search. What differs between a start and a replan is passed in throughalternateFallbackV3: which versions to try, how the viewer's tracks move onto each, the replan's fixed refusal message, and the replan's rule that the requested edition outranks other held-back versions.plannerInputV3builds the planner input from what the planning passes of one start or replan share.Behaviour is unchanged, including the places where a start and a replan differ today: they still move tracks from different files, and only a replan skips the refused file among the alternates. Those differences are now visible as parameters; reconciling them is a product decision for later, not part of this change.
Each call site still lists downloaded subtitles and creates its Dolby Vision probe as often as before. The lower-bitrate version probe and the audio-track refinement still plan without a lower version or attempted keys, and the escalation of a refused progressive remux still reads settings again.
Validation
go build,go vet,gofmt,make lint-changed): pass on this branch.make verify-playback-fixtures: no diff.Not reached by the replay: the
subtitle_not_shownwarning and thesubtitle_unavailable_in_versionrefusal; the test library has no item that triggers them. An existing handler test covers the first; no test covers the second.No test is added or removed.
Evidence
Evidence: https://evidence.siloserver.org/r/silo-server/pr-3947/
No user-visible change.
Risks
The fallback decides which version plays after a refusal. An unintended difference would show as a different version, a dropped subtitle, or a refusal where a version used to play. The merged search was compared branch by branch with both originals in review.
Checklist
AI Disclosure
🤖 Generated with Claude Code
Note
Share one alternate-version fallback between start and replan in playback V3
planningV3state and sharedPlannerInputV3constructors (plannerInputV3,plannerInputWithSubtitlesV3) in playback_v3.goplanAlternateVersionV3,alternateFallbackV3) used by both start and replan paths. It probes and access-checks candidates, holds back playable candidates that drop subtitles, and prefers the requested editionPlannerResultV3methods (AnotherVersionMayPlay,SubtitleRefusal,ToneMapDependentRefusal) in plan_refusal_v3.go, with exported terminal constants in protocol_v3.goSettingsDependentRefusaltoPlannerResultV3. HDR and 4K-setting refusals now carry it, soretryIncompletePlaybackSettingsV3converts only setting-driven refusals to retryable failures instead of matching on messagesretryIncompleteToneMapPlanningV3andretryIncompletePlaybackSettingsV3changes — refusals no longer marked as settings- or tone-map-dependent stay terminal. Check that all setting-driven refusals inplanVideoTranscodeV3go throughsettingsRefusalV3Macroscope summarized 478f1d9.