Skip to content

fix(playback): enforce negotiated audio tracks - #3036

Merged
Quick104 merged 6 commits into
Silo-Server:mainfrom
ManavA:pr/required-audio-20261024
Nov 1, 2026
Merged

Quick104 merged 6 commits into
Silo-Server:mainfrom
ManavA:pr/required-audio-20261024

Conversation

@ManavA

@ManavA ManavA commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Related issue: N/A
Validation tasks: changes #1246 C1, for one outcome only: a Jellyfin-compatible transcode of an audio track the catalog lists but the file lacks now fails on its first segment instead of playing without sound. Tracks that exist play as before.

When a Jellyfin-compatible client picks an audio track, Silo maps that track into the transcode as optional. If the catalog lists a track the file doesn't have, for example after a file was replaced but not rescanned, FFmpeg drops the audio and the client plays the video with no sound and no error. This change makes the negotiated track mandatory, so the stream fails visibly instead.

Approach

A RequireAudioTrack transcode option removes the optional marker from the selected audio map. Jellyfin-compatible starts set it whenever the source has a valid selected or default audio track. The flag is stored in recipe cards and stream-token claims, sent to transcode nodes, and kept when a relay rehomes the session. A node confirms the flag from the options it actually runs. A start without that confirmation is stopped before its bytes are published, and routing tries the next node or a local transcode, the same way older nodes are already handled for the stereo-downmix recipe. Native /api/v2 playback leaves the flag off.

Recipes written before this change, by this server before the upgrade or by an older API server during a rolling upgrade, keep serving segments from their existing node with the old optional map. A new start or a new track selection makes the track mandatory.

The v2 transcode start request and response schemas each gain one optional boolean. Clients need no change: they get the same playlist, and in the missing-track case the first segment returns 404.

Validation

  • Live on an isolated sandbox with a remote transcode node behind a proxy node. One movie's catalog row was given a second audio track its file doesn't have, and that track was selected through PlaybackInfo with a forced HLS transcode. On main the first segment returned 200 with video only. On this branch it returned 404, and FFmpeg on the node exited once with "matches no streams". Selecting the real track on this branch still returned H.264 with AAC.
  • The two tests added for the upgrade cases (a recipe written before this change, and a track switch on a session rebuilt from one) failed on the head before their fixes. The earlier tests in this PR call the new field, so they don't build on main; the live check covers that behavior.
  • go build, go vet, make lint-changed, make verify-apiv2-contract, make verify-apiv2-openapi, make verify-apiv2-fixtures, make verify-playback-fixtures, and make verify-route-inventory pass. make test-go passes except TestCopyRemuxSubtitleRenditionRealFFmpeg and TestRunStatsWithRealFFmpeg, which fail the same way on main with the local FFmpeg 6.1.
  • Not covered: a Jellyfin client app on a device.

Evidence

Evidence: https://evidence.siloserver.org/r/silo-server/pr-3036/

Risks

  • Upgrade order: transcode nodes before API servers, as the worker protocol already requires. An upgraded API server skips an older node for these transcodes, and fails them when routing policy allows no other route.
  • A file whose catalog lists a missing track now fails to play that track until it is rescanned, where it used to play silently.

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: OpenAI Codex (original change); Claude Code (rebase, review, and follow-up commits)
  • Tool(s): Codex; Claude Code
  • Model(s): gpt-6.1-sol (original change; earlier preparation identifiers were not retained); claude-opus-5-5 (review and follow-up commits)
  • Involvement: Fully AI-generated; human verification pending
  • Adversarial review: Claude Code (claude-opus-5-5) reviewed the rebased branch and found that recipes written before the change made in-flight remote streams return 503 after an API upgrade; that is fixed. An independent Codex (gpt-6.1-sol) review of the result found that a track switch on a session rebuilt from such a recipe kept the optional map; that is fixed too. Both fixes have tests that failed before them. An earlier Codex review of the original change reported no outstanding findings.

@coderabbitai

coderabbitai Bot commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

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: ab0a54ba-9d08-449d-b48a-1e1fb89f4a95
Commits

Reviewing files that changed from the base of the PR and between 2448d76 and c56699c.

Files selected for processing: 12
  • contracts/api/v2/breaking-approvals.json
  • contracts/api/v2/openapi.json
  • internal/api/handlers/playback_v3.go
  • internal/jellycompat/audio_selection_test.go
  • internal/jellycompat/handlers_playback.go
  • internal/jellycompat/remote_transcode_reconstruct_test.go
  • internal/jellycompat/streams.go
  • internal/jellycompat/streams_test.go
  • internal/playback/recipecard.go
  • internal/playback/transcode.go
  • internal/streamtoken/token.go
  • internal/transcodenode/server.go

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

Walkthrough

The change adds RequireAudioTrack to transcode options, requests, recipe cards, and stream-token claims. Jellycompat derives the flag from effective audio selection and uses it when matching recipes and live transcodes. Remote transcode starts must confirm required audio.

Changes: Required audio-track playback

Layer / File(s) Summary
Transcode request and audio mapping
contracts/api/v2/openapi.json, internal/playback/transcode.go, internal/transcodenode/server.go, internal/playback/required_audio_test.go, internal/transcodenode/required_audio_test.go, contracts/api/v2/breaking-approvals.json
The API schema and transcode start request include require_audio_track. The server passes the flag into transcode options, where it controls whether a selected audio mapping is required. Tests cover mapping behavior and request handling. The breaking-approvals array is now empty.
Recipe and token persistence
internal/playback/recipecard.go, internal/streamtoken/token.go, internal/playback/required_audio_test.go, internal/api/handlers/playback_v3.go, internal/api/handlers/playback_transcode_rehome.go
Recipe cards and token claims serialize and restore the required-audio flag. Remote recipe creation and rehome requests copy the flag. Tests check JSON and token round-trips.
Jellycompat negotiation and reconstruction
internal/jellycompat/streams.go, internal/jellycompat/handlers_playback.go, internal/jellycompat/audio_selection_test.go, internal/jellycompat/playback_hevc_encoding_test.go, internal/jellycompat/streams_test.go, internal/jellycompat/remote_transcode_reconstruct_test.go
Jellycompat sets the flag from effective audio selection and checks it when matching recipes and live transcodes. Remote starts and reconstruction options retain the requirement. Tests cover selection, matching, recipe replacement, and legacy optional-audio behavior.
Remote audio confirmation and cleanup
internal/transcodenode/server.go, internal/api/handlers/playback_transcode_rehome.go, internal/api/handlers/playback_transcode_rehome_test.go, internal/jellycompat/remote_transcode_reconstruct_test.go, internal/jellycompat/auto_transcode_fallback_test.go, internal/jellycompat/manifest_tonemap_failover_test.go
Remote-start validation rejects required-audio requests without worker confirmation. Tests cover failure cleanup, rehome refusal, and accepted starts that preserve the flag.

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

Change: Bug fix

Sequence Diagram(s)

sequenceDiagram
  participant Jellycompat
  participant TranscodeNode
  participant FFmpeg
  Jellycompat->>TranscodeNode: Start with selected audio index and required-audio flag
  TranscodeNode->>FFmpeg: Apply selected audio mapping
  FFmpeg-->>TranscodeNode: Produce HLS output or return missing-track error
  TranscodeNode-->>Jellycompat: Return response with required-audio confirmation
Loading

Suggested reviewers: quick104, rhainland

Merge Risk: Moderate · up to c5669

A required default audio track can be missing while playback succeeds without sound. Resolve this before merging.

Security architecture risk: Low · up to c5669

The change strengthens selected-audio enforcement without an identified authorization or privilege expansion. Compatibility during upgrades and rollback remains partially established.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The inspected change affects existing playback sessions, their stored recipes, and media execution on their assigned workers. It adds stricter stream selection rather than a new path, credential, or execution authority. No broader tenant, data-store, or environment exposure was established.

Trust Boundaries and Controls

  • observed — A client cannot remove the requirement from a signed token without invalidating its signature. Worker reconstruction also retains transport matching and input-path authorization; the added boolean does not replace those controls.

Resilience and Maintainability Implications

  • observed — Unconfirmed required starts invoke remote stop before recipe publication. Publication is serialized against local replacement and rechecks route ownership. Durable-write failure invokes cleanup, and persistence compensation avoids overwriting a newer cached recipe. These controls contain rejected execution; the inspected tests verify cleanup requests, not guaranteed delivery during network failure.
Pre-merge checks: Passed 4
Check name Status Explanation
Title check Passed The title clearly and concisely describes the main change: enforcing negotiated audio tracks during playback.
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 negotiated-audio-track problem, implementation approach, affected playback paths, compatibility behavior, validation, and risks. It matches the changeset.
Finishing Touches
Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

@silo-kody

silo-kody Bot commented Oct 25, 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 ❌

@silo-triage silo-triage Bot added size/M 50–199 added + deleted lines (all files); change volume, not priority. bug Something isn't working go Pull requests that update go code labels Oct 25, 2026
@ManavA
ManavA marked this pull request as ready for review October 25, 2026 17:08
@macroscopeapp

macroscopeapp Bot commented Oct 25, 2026

Copy link
Copy Markdown

Playback changes from successful video-only output to a failed transcode when the negotiated audio ordinal is absent (internal/playback/transcode.go); the current FFmpeg mapping/exit evidence does not show the playback outcome. Add a before-and-after recording of the same test item in the affected Jellyfin-compatible client, naming the surface and builds/commits; if no client exposes this behavior yet, provide before-and-after response excerpts for the same request showing the client-visible result.

Suggested fix: add the playback or response evidence under ## Evidence.

Automated check: Macroscope check run agent (gpt-6-luna). Evidence was not reviewed for correctness.

Posted via Macroscope — Visible change evidence

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

Actionable comments posted: 1


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: dd783073-c42f-401a-ba84-6a1a907b2c84
Commits

Reviewing files that changed from the base of the PR and between 6de6d5e and eda6637.

Files selected for processing: 14
  • contracts/api/v2/openapi.json
  • internal/api/handlers/playback_v3.go
  • internal/jellycompat/audio_selection_test.go
  • internal/jellycompat/handlers_playback.go
  • internal/jellycompat/playback_hevc_encoding_test.go
  • internal/jellycompat/remote_transcode_reconstruct_test.go
  • internal/jellycompat/streams.go
  • internal/jellycompat/streams_test.go
  • internal/playback/recipecard.go
  • internal/playback/required_audio_test.go
  • internal/playback/transcode.go
  • internal/streamtoken/token.go
  • internal/transcodenode/required_audio_test.go
  • internal/transcodenode/server.go

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

@macroscopeapp

macroscopeapp Bot commented Oct 25, 2026

Copy link
Copy Markdown

Validation impact

Corrected line: Validation tasks: changes #1246 C1

Suggested fix: No diff; update the validation-task line.

Automated check: Macroscope check run agent (gpt-6-luna). No validation was performed.

Posted via Macroscope — v1 validation impact

@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 Oct 25, 2026
@silo-kody

silo-kody Bot commented Oct 25, 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 ❌

@ManavA ManavA changed the title fix(jellycompat): reject missing negotiated audio tracks fix(playback): enforce negotiated audio tracks Oct 25, 2026

@Quick104 Quick104 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.

Review of this branch rebased onto current main. One finding below; I'm fixing it in a commit on this branch, so there's no need to change it yourself. The summary comment that follows covers the rebase, verification, and what's left for maintainers.

🤖 Claude Code (claude-opus-5-5)

Comment thread internal/jellycompat/streams.go Resolved
@Quick104
Quick104 force-pushed the pr/required-audio-20261024 branch from 2448d76 to 8723dfe Compare November 1, 2026 17:13
@silo-kody

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

ManavA and others added 6 commits November 1, 2026 12:13
…tory

A recipe card stored before this change, or written by an older API pod
during a rolling upgrade, has RequireAudioTrack false. The segment path
rejected it, so every in-flight remote compat stream answered 503 after
the API upgrade. Accept those cards on the segment path; new starts still
compare strictly and replace the legacy runtime.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A local runtime rebuilt from a recipe written before negotiated audio
became mandatory kept its optional map when the user picked another
track, so a missing ordinal could still play as video only and the
re-persisted recipe stayed optional. Set the requirement from the newly
selected source and restore it with the rest on rollback.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@Quick104
Quick104 force-pushed the pr/required-audio-20261024 branch from 8723dfe to c56699c Compare November 1, 2026 17:16
func remoteTranscodeRecipeCardV3(session *playback.Session, file *models.MediaFile, nodeURL, transportID string, req transcodenode.TranscodeStartRequest, nodeResp transcodenode.TranscodeStartResponse, toneMapFilter string) playback.RecipeCard {
hw := firstNonEmptyHandlerV3(strings.TrimSpace(nodeResp.HWAccel), strings.TrimSpace(req.HWAccel))
card := playback.NewRecipeCard(session.UserID, session.ProfileID, file.ID, nodeURL, playback.TranscodeOpts{InputPath: req.InputPath, SessionID: session.ID, TranscodeTransportID: transportID, SourceVideoCodec: req.SourceVideoCodec, SourceVideoProfile: req.SourceVideoProfile, SourceVideoBitDepth: req.SourceVideoBitDepth, SourceAudioChannels: req.SourceAudioChannels, SoftwareVideoDecode: req.SoftwareVideoDecode || nodeResp.SoftwareVideoDecode, ToneMapPolicy: req.ToneMapPolicy, ToneMapMode: req.ToneMapMode, ToneMapSourceKind: req.ToneMapSourceKind, ToneMapFilter: toneMapFilter, ToneMapRecipeVersion: req.ToneMapRecipeVersion, ToneMapPreflightRequired: req.ToneMapPreflightRequired, ToneMapSourceRevision: req.ToneMapSourceRevision, VideoBitstreamFilter: req.VideoBitstreamFilter, VideoSampleEntry: req.VideoSampleEntry, VideoRange: req.VideoRange, SeekSeconds: req.SeekSeconds, StreamOriginSeconds: req.StreamOriginSeconds, CopySeekAnchorResolved: req.CopySeekAnchorResolved, StartSegmentNumber: req.StartSegmentNumber, TargetResolution: req.TargetResolution, TargetCodecVideo: req.TargetCodecVideo, TargetCodecAudio: req.TargetCodecAudio, TargetAudioChannels: req.TargetAudioChannels, TargetAudioBitrateKbps: req.TargetAudioBitrateKbps, TargetBitrateKbps: req.TargetBitrateKbps, SegmentDuration: req.SegmentDuration, KeyframePlaylist: req.KeyframePlaylist, HWAccel: hw, AudioTrackIndex: req.AudioTrackIndex, SubtitleTrackIndex: req.SubtitleTrackIndex, SubtitleBurnIn: req.SubtitleBurnIn, SubtitleCodec: req.SubtitleCodec, SubtitleRendition: req.SubtitleRendition, TotalDuration: req.TotalDuration, ThrottleSeconds: req.ThrottleSeconds})
card := playback.NewRecipeCard(session.UserID, session.ProfileID, file.ID, nodeURL, playback.TranscodeOpts{InputPath: req.InputPath, SessionID: session.ID, TranscodeTransportID: transportID, SourceVideoCodec: req.SourceVideoCodec, SourceVideoProfile: req.SourceVideoProfile, SourceVideoBitDepth: req.SourceVideoBitDepth, SourceAudioChannels: req.SourceAudioChannels, SoftwareVideoDecode: req.SoftwareVideoDecode || nodeResp.SoftwareVideoDecode, ToneMapPolicy: req.ToneMapPolicy, ToneMapMode: req.ToneMapMode, ToneMapSourceKind: req.ToneMapSourceKind, ToneMapFilter: toneMapFilter, ToneMapRecipeVersion: req.ToneMapRecipeVersion, ToneMapPreflightRequired: req.ToneMapPreflightRequired, ToneMapSourceRevision: req.ToneMapSourceRevision, VideoBitstreamFilter: req.VideoBitstreamFilter, VideoSampleEntry: req.VideoSampleEntry, VideoRange: req.VideoRange, SeekSeconds: req.SeekSeconds, StreamOriginSeconds: req.StreamOriginSeconds, CopySeekAnchorResolved: req.CopySeekAnchorResolved, StartSegmentNumber: req.StartSegmentNumber, TargetResolution: req.TargetResolution, TargetCodecVideo: req.TargetCodecVideo, TargetCodecAudio: req.TargetCodecAudio, TargetAudioChannels: req.TargetAudioChannels, TargetAudioBitrateKbps: req.TargetAudioBitrateKbps, TargetBitrateKbps: req.TargetBitrateKbps, SegmentDuration: req.SegmentDuration, KeyframePlaylist: req.KeyframePlaylist, HWAccel: hw, AudioTrackIndex: req.AudioTrackIndex, RequireAudioTrack: req.RequireAudioTrack, SubtitleTrackIndex: req.SubtitleTrackIndex, SubtitleBurnIn: req.SubtitleBurnIn, SubtitleCodec: req.SubtitleCodec, SubtitleRendition: req.SubtitleRendition, TotalDuration: req.TotalDuration, ThrottleSeconds: req.ThrottleSeconds})

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

Missing required-audio enforcement in native playback lets missing selected audio produce successful video-only native HLS: the local options at line 4133 and remote request at line 4394 set AudioTrackIndex but omit RequireAudioTrack, so this recipe copy always preserves false and its stored recipe and rehomed executor retain optional mapping. Set RequireAudioTrack from the negotiated audio selection in both startup constructors.

Prompt for LLM

File internal/api/handlers/playback_v3.go:

Line 4630:

Missing required-audio enforcement in native playback lets missing selected audio produce successful video-only native HLS: the local options at line 4133 and remote request at line 4394 set AudioTrackIndex but omit RequireAudioTrack, so this recipe copy always preserves false and its stored recipe and rehomed executor retain optional mapping. Set RequireAudioTrack from the negotiated audio selection in both startup constructors.

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

Choose a reason for hiding this comment

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

Not changing this here. Native /api/v2 playback is outside this PR's scope on purpose: the PR body says native leaves the flag off, so native behavior is the same as on main. This line only copies the request's value into the recipe card, so a future native change that sets the flag will have it persisted and rehomed without touching this code. Making native playback fail on a missing track is a separate product change for the native clients, and the summary comment lists it as a follow-up.

🤖 Claude 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.

Agreed—my suggestion was out of scope for this PR and should be disregarded.

Native /api/v2 intentionally keeps RequireAudioTrack off, preserving existing behavior. The changed line correctly copies req.RequireAudioTrack into the recipe card; it does not decide whether native playback requires audio.

Setting the flag in the native startup constructors would introduce a separate behavior change, not fix a regression introduced here. No change is needed for this finding.

Comment on lines 1049 to +1054
if audioTrackIndex >= 0 {
args = append(args, "-map", fmt.Sprintf("0:a:%d?", audioTrackIndex))
audioMap := fmt.Sprintf("0:a:%d", audioTrackIndex)
if !opts.RequireAudioTrack {
audioMap += "?"
}
args = append(args, "-map", audioMap)

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

Required-audio enforcement ignores RequireAudioTrack when AudioTrackIndex is -1, although TranscodeOpts documents -1 as the default first track; because the worker confirms enforcement directly from the Boolean, a required-audio worker request can receive positive confirmation while FFmpeg successfully emits video-only HLS. Normalize the default index to zero before applying the mandatory/optional mapping suffix.

if audioTrackIndex < 0 {
	audioTrackIndex = 0
}
audioMap := fmt.Sprintf("0:a:%d", audioTrackIndex)
if !opts.RequireAudioTrack {
	audioMap += "?"
}
args = append(args, "-map", audioMap)
Prompt for LLM

File internal/playback/transcode.go:

Line 1049 to 1054:

Required-audio enforcement ignores RequireAudioTrack when AudioTrackIndex is -1, although TranscodeOpts documents -1 as the default first track; because the worker confirms enforcement directly from the Boolean, a required-audio worker request can receive positive confirmation while FFmpeg successfully emits video-only HLS. Normalize the default index to zero before applying the mandatory/optional mapping suffix.

Suggested Code:

	if audioTrackIndex < 0 {
		audioTrackIndex = 0
	}
	audioMap := fmt.Sprintf("0:a:%d", audioTrackIndex)
	if !opts.RequireAudioTrack {
		audioMap += "?"
	}
	args = append(args, "-map", audioMap)

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

Choose a reason for hiding this comment

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

No caller can send this combination. Only Jellyfin-compatible starts set RequireAudioTrack to true (compatRequiresAudioTrack in handlers_playback.go and streams.go), and they always set AudioTrackIndex from compatAudioTrackIndexOrDefault in the same literal. That function never returns -1, and when the flag is true it returns the resolved, catalog-valid track. Every other site (recipecard.go, playback_transcode_rehome.go, playback_v3.go, the node's handleStart) copies an existing card or request, so it can't create the pair. Native starts leave the flag false. No change here.

🤖 Claude 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.

Agreed—given the caller invariant you described, the RequireAudioTrack=true / AudioTrackIndex=-1 combination is not reachable through the current start paths. Copying those values through recipes, rehoming, and worker requests does not introduce that combination.

My suggestion identified a hypothetical mismatch between the option fields, but did not establish a reachable playback failure. That does not justify a high-severity bug finding. I withdraw the suggestion; no code change is warranted on that basis.

The proposed normalization also changes mapping for AudioTrackIndex=-1 when RequireAudioTrack is false, so it should not be treated as a behavior-neutral fix.

@Quick104

Quick104 commented Nov 1, 2026

Copy link
Copy Markdown
Contributor

Review summary (head c56699c5)

I rebased this branch onto current main, so its history was rewritten with force-pushes. The author's commits keep their authorship. The merge commit is gone, and the conflict with main's newer recipe-card fields was resolved. The approvals cleanup now removes the two #3298 entries that verify-apiv2-contract reports as stale against this branch's merge base.

Addressed findings

  • In-flight remote streams would answer 503 after an API upgrade, because the segment path rejected recipe cards written before this change. Fixed in 1b3761e: those cards keep serving with the old optional map, and a new start still replaces them.
  • A track switch on a local session rebuilt from such a card kept the optional map. Fixed in c56699c: the newly selected track is mandatory, and a failed restart restores the old value.

Each fix has a test that failed on the head before it.

Verification

  • Live on an isolated sandbox with a remote transcode node behind a proxy node, after giving one movie's catalog row a second audio track its file doesn't have. Selecting that track returned a video-only first segment with HTTP 200 on main, and HTTP 404 on this head, where FFmpeg on the node exited once with "matches no streams". Selecting the real track on this head still returned H.264 with AAC.
  • Go build, vet, make lint-changed, make verify-apiv2-contract, make verify-apiv2-openapi, make verify-apiv2-fixtures, make verify-playback-fixtures, and make verify-route-inventory pass. make test-go passes except two real-FFmpeg tests that fail the same way on main with the local FFmpeg 6.1.
  • Cross-provider review: one adversarial round by Codex (gpt-6.1-sol) on the rebased branch found the track-switch issue above. Nothing else was reported.

Validated features

#1246 C1 passed on 2026-10-23 with audio present. This change leaves that path alone (the real-track control above) and changes only the missing-track outcome, from silent video to a failed first segment. C1 needs a re-test after merge.

Remaining for maintainers

  • Maintainer decision: in the missing-track case, the client now gets the master playlist and then a 404 on the first segment, where it used to play without sound. This matches the 1.0 release definition's requirement that a failed transcode be visible rather than a silent no-op. The trade-off is that a stale catalog entry now blocks playback of that track until a rescan.
  • Upgrade order: transcode nodes must be upgraded before API servers, which the worker protocol already requires. An upgraded API server skips older nodes for these transcodes.

Other checks

Fit: 8/10 · Readiness: 9/10, conditional (assuming CI is green)

Fit: the change turns a silent failure on the Jellyfin-compatible path into a visible one, which is the direction the 1.0 release definition sets. It costs a new transcode-node protocol flag and two optional v2 schema fields, and one product decision above is open. Readiness: the behavior was shown live before and after, both upgrade fixes have tests that failed before them, and no verified defect remains.

🤖 Claude Code (claude-opus-5-5)

@Quick104
Quick104 merged commit 1faea5e into Silo-Server:main Nov 1, 2026
19 checks passed
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 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.

2 participants