Repository navigation
fix(playback): enforce negotiated audio tracks - #3036
Conversation
Silo Kody — review completeReview finished. Check the inline comments for findings and verify each suggestion against the code and tests. Reviewing changes in Silo
Review settingsReview OptionsThe following review options are enabled or disabled:
|
|
Playback changes from successful video-only output to a failed transcode when the negotiated audio ordinal is absent ( Suggested fix: add the playback or response evidence under Automated check: Macroscope check run agent (gpt-6-luna). Evidence was not reviewed for correctness. Posted via Macroscope — Visible change evidence |
There was a problem hiding this comment.
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
Files selected for processing: 14-
contracts/api/v2/openapi.jsoninternal/api/handlers/playback_v3.gointernal/jellycompat/audio_selection_test.gointernal/jellycompat/handlers_playback.gointernal/jellycompat/playback_hevc_encoding_test.gointernal/jellycompat/remote_transcode_reconstruct_test.gointernal/jellycompat/streams.gointernal/jellycompat/streams_test.gointernal/playback/recipecard.gointernal/playback/required_audio_test.gointernal/playback/transcode.gointernal/streamtoken/token.gointernal/transcodenode/required_audio_test.gointernal/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.
-
Validation impact
Corrected line: 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 Kody — review completeReview finished. Check the inline comments for findings and verify each suggestion against the code and tests. Reviewing changes in Silo
Review settingsReview OptionsThe following review options are enabled or disabled:
|
Quick104
left a comment
There was a problem hiding this comment.
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)
2448d76 to
8723dfe
Compare
Silo Kody — review completeReview finished. Check the inline comments for findings and verify each suggestion against the code and tests. Reviewing changes in Silo
Review settingsReview OptionsThe following review options are enabled or disabled:
|
…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]>
8723dfe to
c56699c
Compare
| 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}) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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.
| 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) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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.
Review summary (head
|
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
RequireAudioTracktranscode 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/v2playback 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
PlaybackInfowith 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.go build,go vet,make lint-changed,make verify-apiv2-contract,make verify-apiv2-openapi,make verify-apiv2-fixtures,make verify-playback-fixtures, andmake verify-route-inventorypass.make test-gopasses exceptTestCopyRemuxSubtitleRenditionRealFFmpegandTestRunStatsWithRealFFmpeg, which fail the same way on main with the local FFmpeg 6.1.Evidence
Evidence: https://evidence.siloserver.org/r/silo-server/pr-3036/
Risks
Checklist
AI Disclosure