Skip to content

refactor(playback): share one alternate-version fallback between start and replan - #3947

Merged
Quick104 merged 5 commits into
mainfrom
refactor/playback-alternate-fallback
Nov 11, 2026
Merged

Quick104 merged 5 commits into
mainfrom
refactor/playback-alternate-fallback

Conversation

@Quick104

@Quick104 Quick104 commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

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

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

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

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

🤖 Generated with Claude Code

Note

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

Macroscope summarized 478f1d9.

Quick104 and others added 2 commits November 10, 2026 21:08
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]>
@silo-triage silo-triage Bot added the size/XL 500–999 added + deleted lines (all files); change volume, not priority. label Nov 11, 2026
@coderabbitai

coderabbitai Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

Warning

Review limit reached

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

  • Ask an admin to enable usage-based reviews

Open in CodeRabbit

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

Next included review available in 10 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 4 included reviews currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 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.

Estimated code review effort: 4 (Complex) | ~45 minutes

Change: Refactor

Sequence Diagram(s)

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
Loading

Possibly related issues

Possibly related PRs

  • 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: Passed 4

Check name Status Explanation
Title check Passed The title clearly and concisely identifies the main change: sharing alternate-version fallback logic between start and replan paths.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Description check Passed 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

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 11, 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-11T19:06:16.403301Z 478f1d9 New commits
🔒 Security Review ✅ Completed 2026-11-11T19:08:46.742346Z 478f1d9 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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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 main November 11, 2026 19:19
@silo-kody

silo-kody Bot commented Nov 11, 2026 •

Copy link
Copy Markdown

Silo Kody — review complete

Review finished. Check the inline comments for findings and verify each suggestion against the code and tests.

Reviewing changes in Silo
  • Include the related issue, expected behavior, and validation steps in the PR description.
  • For API changes, describe the effect on Apple and Android clients and Jellyfin compatibility.
  • For plugin changes, identify the affected SDK contract, plugin, and catalog entry.
  • Follow this repository's AGENTS.md and CONTRIBUTING.md.
  • Request another review with @kody start-review in a PR comment.
  • React with 👍 or 👎 to give feedback on individual suggestions.
Review settings
Review Options

The following review options are enabled or disabled:

Options Enabled
Bug ✅
Performance ✅
Security ✅
Business Logic ❌

@Quick104
Quick104 merged commit 2e142f0 into main Nov 11, 2026
17 checks passed
@Quick104
Quick104 deleted the refactor/playback-alternate-fallback branch November 11, 2026 19:35
Quick104 added a commit that referenced this pull request Nov 15, 2026
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/XL 500–999 added + deleted lines (all files); change volume, not priority.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant