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
fix(jellycompat): keep the keyframe playlist when audio switches on a node - #4434
Closes#4044
Related issue: N/A
Validation tasks: none
Other clients: Apple N/A (server-side restart recipe); Android N/A (server-side restart recipe); Roku N/A (server-side restart recipe)
Depends on: none. Builds on #1770 (merged). Merge order with #4400 (open) is free, but see Risks.
With Complete playlists for copied video on, a Jellyfin-compat client that switched audio mid-stream on a keyframe-planned copy session running on a transcode node got FFmpeg's growing playlist and fixed-grid segment numbers from the node. The client still held the planned VOD playlist for the same URL, so planned segment N and the node's segment N were different media. A session running locally was not affected.
Approach
The node path in restartCompatTranscodeForAudioSelection asked the node to start at the player's position. The node starts the replacement in a new output directory and plans only a run that starts at the beginning (planCopySegments), so it served FFmpeg's playlist. The keyframe-playlist attestation still passed, because the node attests the requested flag, not whether it planned.
The node now reports whether it planned. StartTranscode sets KeyframePlanned from the plan it resolved, the node returns it as keyframe_planned in the start response, and the core keeps it in the session's recipe. When the recipe says the node planned a run from the beginning, the audio switch restarts the node from that start, as RecipeOpts already does for a local session's recipe. The node plans the same segments again. The player's next segment request then restarts FFmpeg at the planned segment for its position through the node's planned segment recovery, after the from-start run has set the timeline. The node's rebuild of a copy card works the same way. The persisted recipe keeps the from-start start and the flag, so later rebuilds and switches stay planned.
The replacement of a planned session must plan too. The node writes it into a new output directory, where planning can still fail: the keyframe index can't be read, the start probe fails, or the plan record can't be written. A reply without keyframe_planned stops the remote job before the recipe is persisted, and the audio switch fails and rolls back the selection. The player doesn't get segments its playlist doesn't list, but it needs a new playback session, the same limit as ErrKeyframePlanChanged on a rebuild.
Any other node session restarts at the position, as on main. That covers a copy the node couldn't plan (no or unusable keyframe index), a session that resumed mid-stream, and a session on a node too old to send the field. Restarting a session on FFmpeg's playlist from the beginning would leave the throttled run far behind the player.
A reviewer may ask why the node doesn't start the new run directly at the planned segment, like the local path. The new directory has no recorded timeline. A run started mid-stream would set its own timeline, which is off by the source's B-frame delay (TestPlannedRestartKeepsTheFromStartTimeline). Starting there would also need a new start-request field.
Validation
New core test: its planned case fails on main, its "kept FFmpeg's playlist" case fails on the PR's first commit, its "replacement lost the plan" case fails without the third commit's check, and all pass now. New node and StartTranscode cases check keyframe_planned for a source with and without a keyframe index.
make verify-apiv2-openapi: current after regeneration (two keyframe_planned fields). The web type check was not run here; the generated web types don't include these schemas.
go test for internal/jellycompat, internal/playback/..., internal/transcodenode and internal/api/handlers: the same tests fail before and after the change, and only those. All of them are DB tests that fail because the local test database is not migrated to current main (relation "watchlist_title_promotions" does not exist):
internal/playback: TestInvalidateHWProbeCacheSupersedesAnInFlightProbe timed out once on main (hardware encoder probe deadline on this VM) and passed in both runs after the change.
make lint-changed with golangci-lint v2.15.0 (the CI version): 0 issues.
Not run: a real deployment with a transcode node and a Jellyfin client. The node side is unchanged and is covered by its existing planned-recovery tests.
Evidence
Nothing a user sees changes apart from the fixed playback, so this is how the change was checked.
Before the fix, on main at 217ff25 plus the new test:
Package runs after the second commit; the third changes only internal/jellycompat, rerun with internal/api/handlers with the same DB failures (as listed above, the same set as on main):
FAIL github.com/Silo-Server/silo-server/internal/jellycompat 31.528s
ok github.com/Silo-Server/silo-server/internal/playback 147.917s
ok github.com/Silo-Server/silo-server/internal/playback/connectionstore
ok github.com/Silo-Server/silo-server/internal/playback/contract 5.937s
ok github.com/Silo-Server/silo-server/internal/playback/dovirpu
ok github.com/Silo-Server/silo-server/internal/playback/keyframes
ok github.com/Silo-Server/silo-server/internal/playback/planstore 2.120s
ok github.com/Silo-Server/silo-server/internal/transcodenode 14.861s
FAIL github.com/Silo-Server/silo-server/internal/api/handlers 65.748s
lint-changed: 4 package(s) changed since 217ff25ab
0 issues.
contracts/api/v2/openapi.json is current
Risks
After the audio switch, the node's FFmpeg starts at the beginning, and the player's next segment request moves it to the player's position. A copy run gets there quickly, but the switch costs one extra FFmpeg start on the node.
When a planned session's replacement can't plan, the audio switch now fails and the node's job is stopped. Before, the switch went through with mismatched segments. In both cases the player needs a new playback session; this makes the failure visible instead of playing the wrong media.
A recipe written before this change has no keyframe_planned, so an audio switch on such a node session restarts at the position, as on main. The bug stays for those sessions until they start again.
The start response and the recipe card each gain an optional field. Older nodes and cores ignore or omit it.
The session recipe persists KeyframePlanned via RecipeCard round-tripping, and playback.StartTranscode sets it from the resolved copy plan rather than the caller-supplied value (transcode.go, recipecard.go).
When Jellyfin switches audio on a remote session whose recipe records a planned-from-zero keyframe playlist, PlaybackHandler.restartCompatTranscodeForAudioSelection restarts at seek zero and requires the node to attest a plan; if the node does not, the replacement is stopped and the original session is kept (streams.go, handlers_playback.go).
Other remote restarts keep starting at the requested position with no plan requirement.
Risk: nodes running older software omit keyframe_planned; for planned sessions, an audio switch against such a node fails the restart instead of silently losing the keyframe playlist.
… node
An audio switch on a keyframe-planned copy session running on a transcode
node restarted the node at the player's position. The node starts the
replacement in a new output directory and plans only a run from the
beginning, so it served FFmpeg's growing playlist and fixed-grid segment
numbers while the player held the planned VOD playlist for the same URL.
The node restart now sends the recipe's from-start start when the session
was planned from the beginning, as RecipeOpts keeps a local session's
recipe. The node plans the same segments again, and the player's next
segment request restarts FFmpeg at the planned segment for its position
once the from-start run has set the timeline. A session that resumed
mid-stream still restarts at the position.
ClosesSilo-Server#4044
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Remote transcode sessions now report whether keyframe planning succeeded. Recipes store that result. Remote audio-selection restarts use time zero only when the recipe confirms a planned playlist that began at seek and segment zero; other restarts retain the playback position.
Changes: Remote keyframe-planned audio restart
Layer / File(s)
Summary
Resolve and report plan status internal/playback/transcode.go, internal/transcodenode/server.go, internal/playback/copy_keyframe_plan_test.go, internal/transcodenode/server_test.go
TranscodeOpts records whether a plan was resolved. The node start response reports that result separately from the requested playlist flag. Tests cover successful and unavailable planning.
Persist and enforce plan status internal/playback/recipecard.go, internal/playback/recipecard_test.go, internal/jellycompat/handlers_playback.go, contracts/api/v2/openapi.json, docs/transcode-node-api.md
Recipe cards preserve KeyframePlanned, and the Jellyfin handler records the node’s result. When a replacement must preserve a plan but the node does not attest one, the handler stops the remote transcode and returns an error. The API schema and documentation describe the response field.
Select remote restart position internal/jellycompat/streams.go, internal/jellycompat/audio_selection_test.go
A planned recipe that began at seek and segment zero restarts at time zero. Other cases use the playback position and corresponding segment. Tests cover from-start, unplanned, and resumed recipes, and verify that a rejected replacement does not change the stored recipe.
sequenceDiagram
participant JellyfinHandler
participant TranscodeNode
participant RecipeCard
participant AudioRestart
JellyfinHandler->>TranscodeNode: Start transcode request
TranscodeNode-->>JellyfinHandler: Report KeyframePlanned result
JellyfinHandler->>RecipeCard: Store plan status
AudioRestart->>RecipeCard: Read recipe
RecipeCard-->>AudioRestart: Return plan status and start position
AudioRestart->>TranscodeNode: Start replacement transcode
Silo-Server/silo-server#1770: Adds mid-stream FFmpeg restarts for keyframe-planned copy streams, which this change uses for planned-segment recovery.
Suggested reviewers:quick104, rhainland
Merge Risk: Moderate · previous review 53178
If a planned copy session switches audio and the replacement node cannot produce a keyframe plan, the switch is refused. The current playback can then stop serving segments until the client starts playback again. The case is uncommon, but the refused switch should leave the old stream playable before this merges.
Security architecture risk: Low · up to 53178
The new check prevents incompatible media from being served under an existing playlist. However, rejecting a replacement can leave playback stopped while the saved audio selection is rolled back. This appears confined to the affected stream; no expanded access or privilege boundary was identified.
Retained concerns
Low · reliability · inferred: A required-plan refusal rolls back the selected audio track but not executable playback. Cleanup removes the node reconstruction recipe and stops and fences the replacement transport. The retained playback recipe does not automatically restore service through subsequent segment requests, so a failed switch can terminate the existing stream rather than return it to a working prior state.
Security review details
Security Blast Radius
inferred — The identified failure is scoped to the affected playback transport. The inspected change does not introduce a new destination, credential, cross-user operation, or broader start/stop authority.
Trust Boundaries and Controls
observed — The core checks the node's reported plan before publishing the replacement recipe. Rejected replacements use existing cleanup that withdraws the node recipe and requests a fenced stop, preventing successful cleanup from silently reconstructing the rejected transport.
Pre-merge checks: 4
Check name
Status
Explanation
Title check
The title names the fix and its scope: keeping the keyframe playlist when audio switches on a transcode node in jellycompat. The diff adds a keyframe_planned attestation, a planned-from-start restart …
Linked Issues check
Directly linked issue #4044 is open and active. Its coding requirement: after an audio switch on a node-backed, keyframe-planned copy session, the node must serve the planned playlist and planned segm…
Out of Scope Changes check
The changes listed in the PR summary support the #4044 fix. They include the conditional from-start restart and planned-rejection logic in internal/jellycompat/streams.go and handlers_playback.go; the…
Description check
The description states the problem (audio switch on a node-backed keyframe-planned copy session served FFmpeg's growing playlist instead of the planned VOD playlist), the approach (the node now report…
Full details: Title check
Explanation
The title names the fix and its scope: keeping the keyframe playlist when audio switches on a transcode node in jellycompat. The diff adds a keyframe_planned attestation, a planned-from-start restart for audio-selection restarts, and tests for that path, so the title matches the main change.
Full details: Linked Issues check
Explanation
Directly linked issue #4044 is open and active. Its coding requirement: after an audio switch on a node-backed, keyframe-planned copy session, the node must serve the planned playlist and planned segment numbers for the player's position, as the local path does. The reviewed head implements this through a node-reported keyframe_planned flag. The node sets it in TranscodeStartResponse (internal/transcodenode/server.go). StartTranscode sets KeyframePlanned from the plan it resolved (internal/playback/transcode.go). RecipeCard persists it (internal/playback/recipecard.go). restartCompatTranscodeForAudioSelection (internal/jellycompat/streams.go) restarts from zero only when the recipe is planned with seek 0 and start segment 0. A planned replacement that does not report keyframe_planned is stopped and rejected. Other sessions restart at the requested position, which covers resumed mid-stream and unplanned copies. The mechanism differs from the issue's wording. The issue expects a restart at the planned segment. The PR restarts from zero and relies on planned-segment recovery for the next request. The PR gives a reason: a mid-stream start in a new output directory sets an off-by-B-frame timeline (TestPlannedRestartKeepsTheFromStartTimeline). The resulting behavior, planned segments at the player's position, matches the issue. Test coverage: TestRestartCompatAudioSelectionKeepsANodeSessionsKeyframePlan, TestStartTranscodeRecordsWhetherItPlanned, TestRecipeCardRoundTripOpts, and TestHandleStartAttestsRecipeVersions. The PR reports that the planned-case and kept-playlist cases fail on the earlier commit and pass now. Limits: the incremental diff since the previous reviewed heads and the streams.go diff could not be read, because changed blobs are missing from the checkout. The current streams.go content was read in part only. The node-side planned-recovery behavior is taken from the PR text, not from a source read. The PR description's statement that the node side is unchanged is stale. The #4400 mid-stream follow-up is excluded, as the PR states.
Full details: Out of Scope Changes check
Explanation
The changes listed in the PR summary support the #4044 fix. They include the conditional from-start restart and planned-rejection logic in internal/jellycompat/streams.go and handlers_playback.go; the KeyframePlanned field in TranscodeOpts, RecipeCard, and StartTranscode (internal/playback); the keyframe_planned field in TranscodeStartResponse and handleStart (internal/transcodenode/server.go); the matching tests; the openapi.json properties, which mirror the node response contract; and the docs/transcode-node-api.md update that describes that contract. The node response field and its OpenAPI property are required so the core can tell a planned session from an FFmpeg-playlist session. No change in the summaries is tied to unrelated behavior. The PR's disclosed risks (one extra FFmpeg start on audio switch; no-field recipes keep the prior behavior) follow from the fix and do not add separate work. The #4400 follow-up is excluded. Limits: the incremental diff could not be read, so this verdict relies on the whole-PR summaries and the reported tests.
Full details: Description check
Explanation
The description states the problem (audio switch on a node-backed keyframe-planned copy session served FFmpeg's growing playlist instead of the planned VOD playlist), the approach (the node now reports whether it planned, and the core persists that flag in the recipe), the validation runs, and the risks. It describes the changed code paths in the changeset, so it is clearly related to the changeset.
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.
The configured keyframe flag is mistaken for an active keyframe plan
When planCopySegments falls back to FFmpeg's growing playlist because the keyframe index is missing or unusable, an audio switch restarts at zero and may change segment boundaries. Reset seekSeconds only when the node session has an actual keyframe plan.
Prompt for LLM
File internal/jellycompat/streams.go, lines 3985-3987:
The configured keyframe flag is mistaken for an active keyframe plan
`KeyframePlaylist` records that planning was requested, not that a plan was created: `planCopySegments` falls back to FFmpeg's growing playlist when the keyframe index is missing or unusable. In that common fallback case an audio switch now restarts at zero instead of the playback position, replacing the current-position run with a from-start playlist and potentially forcing the client onto different segment boundaries; only reset the seek when the actual node session has a keyframe plan.
The reason will be displayed to describe this comment to others. Learn more.
Confirmed. The node's keyframe_playlist echo only says it understood the request (KeyframePlaylist: session.Opts().KeyframePlaylist in handleStart), and planCopySegments returns no plan when the keyframe index is missing or unusable. So the first commit restarted a node session that kept FFmpeg's playlist from 0, where the throttler holds the run far behind the player.
Fixed in d7c5aa9. StartTranscode records KeyframePlanned from the plan it resolved, the node returns it as keyframe_planned, and the core keeps it in the recipe. The audio switch resets the seek only when the recipe says the node planned the session from the start. Any other session restarts at the position, as on main. The new "kept FFmpeg's playlist" case in TestRestartCompatAudioSelectionKeepsANodeSessionsKeyframePlan fails on the first commit and passes now.
The reason will be displayed to describe this comment to others. Learn more.
Thanks for confirming. The reported issue is addressed in d7c5aa97f: the restart decision now uses the node’s actual planning result rather than the requested flag, and the new fallback test covers sessions that retained FFmpeg’s playlist.
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: dbfbac58-86b6-4849-bdd3-f81d2c01a88f
Commits
Reviewing files that changed from the base of the PR and between bac725a and 42d4c0e.
Files selected for processing: 2
internal/jellycompat/audio_selection_test.go
internal/jellycompat/streams.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.
The node's keyframe_playlist echo confirms it understood the request, not
that it planned: a copy without a usable keyframe index keeps FFmpeg's
growing playlist. The audio-switch fix for Silo-Server#4044 read the echo as a plan, so
a node session on FFmpeg's playlist restarted from the beginning, where the
throttler holds FFmpeg far behind the player.
StartTranscode now records KeyframePlanned from the plan it resolved. The
node returns it as keyframe_planned, the core keeps it in the recipe, and the
audio switch restarts from the beginning only a session the node planned. An
older node omits the field, so its sessions restart at the position as
before.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
silo-triageBot
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 17, 2026
The reason will be displayed to describe this comment to others. Learn more.
Older planning nodes are recorded as serving FFmpeg playlists
Audio switches can replace a playlist the player still holds because older nodes may omit keyframe_planned even when they planned it. Distinguish an absent attestation from explicit false and preserve compatibility with those nodes.
Prompt for LLM
File internal/jellycompat/handlers_playback.go, line 2219:
Older planning nodes are recorded as serving FFmpeg playlists
Older nodes can serve a keyframe-planned playlist but omit `keyframe_planned`, so their sessions are recorded as unplanned and an audio switch restarts at the current position, replacing the playlist already held by the player. Distinguish an absent attestation from an explicit false value and preserve compatibility with nodes that can plan but do not report the result.
The reason will be displayed to describe this comment to others. Learn more.
Keeping this as it is. A session on an older node restarts at the position, which is main's behaviour, so the bug stays for that session but nothing gets worse. An absent field can't be told apart from an explicit false, because keyframe_planned is omitempty, and an older node's silence doesn't say whether it planned. Treating absent as planned would restart an older node's unplanned session from 0, where the throttler holds the run far behind the player: the stall from the first review finding. The PR's Risks section lists the older-node case.
The reason will be displayed to describe this comment to others. Learn more.
Agreed—keeping the current behavior is a reasonable compatibility tradeoff. An omitted keyframe_planned value does not establish whether the node planned the session, and assuming it did could stall an unplanned session after the restart.
The older-node case remains a known limitation, as documented in the PR’s Risks section. I withdraw the suggestion.
The reason will be displayed to describe this comment to others. Learn more.
Audio restart accepts a replacement that lost the existing keyframe plan
The player can retain the original playlist while resolveCopyPlan falls back to an unplanned replacement if the index is unavailable or the plan cannot be written. Reject or recover a replacement that lacks plan attestation when the original session was planned.
Prompt for LLM
File internal/jellycompat/streams.go, lines 3986-3988:
Audio restart accepts a replacement that lost the existing keyframe plan
A previously planned session can restart from zero but receive an unplanned replacement when the keyframe index becomes unavailable or the new plan record cannot be written; `resolveCopyPlan` explicitly falls back in both cases, while the player still holds the original complete playlist. Reject or recover the replacement when the original recipe was planned and the node does not attest a plan, rather than publishing the incompatible session.
The reason will be displayed to describe this comment to others. Learn more.
Confirmed and fixed in 5317803. A planned restart now passes requireKeyframePlan to startRemoteTranscodeWithToneMapMode. If the node's reply lacks keyframe_planned, the core stops the remote job and returns errRemoteTranscodeStartFailed wrapping errRemoteKeyframePlanLost. That happens before the recipe is persisted, so the audio switch fails and the selection rolls back. The new "replacement lost the plan" case in TestRestartCompatAudioSelectionKeepsANodeSessionsKeyframePlan covers it: without the check, the restart returned true, <nil>.
This refuses the mismatch but doesn't recover the stream: the node has already replaced its old session, so the player needs a new playback session, the same limit as ErrKeyframePlanChanged on a rebuild.
The reason will be displayed to describe this comment to others. Learn more.
Thanks for confirming. The fix addresses the reported mismatch by rejecting a replacement that loses the keyframe plan before its recipe is persisted. The new test covers that failure path.
The remaining limitation is clear: rejection prevents incompatible segments from being served, but the player needs a new playback session because the old node session has already been replaced.
An audio switch on a planned node session restarts the node from the
beginning so it plans the same segments. The replacement runs in a new
output directory and can still keep FFmpeg's playlist: the keyframe index
can't be read, the start probe fails, or the plan can't be recorded. The
core accepted that replacement, and the player held a planned playlist the
node no longer served.
A planned restart now requires the node to report keyframe_planned. A
replacement without it is stopped and the switch fails, so the selection
rolls back instead of serving segments the playlist doesn't list.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The reason will be displayed to describe this comment to others. Learn more.
Rejecting an unplanned replacement terminates the original playback
Revises an earlier Kody suggestion on internal/jellycompat/streams.go:3986 (2026-11-17 16:26 UTC).
The node has already retired the original session, so stopping the replacement leaves playback without a running transcode even though applyCompatAudioSelection rolls back the track selection. Preserve or restore the original planned session when rejecting a replacement.
Prompt for LLM
File internal/jellycompat/handlers_playback.go, lines 2153-2155:
**Revises an earlier Kody suggestion** on `internal/jellycompat/streams.go:3986` (2026-11-17 16:26 UTC).
Rejecting an unplanned replacement terminates the original playback
The node has already retired the original session before returning this response, so stopping the replacement leaves playback without a running transcode even though `applyCompatAudioSelection` rolls the selection back to the original track. Preserve or restore the original planned session when rejecting a replacement; this revises the earlier rejection suggestion because rejection after node publication destroys the session it was intended to protect.
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: 3fa6780c-3acf-49fa-bbff-619d6cfc15e5
Commits
Reviewing files that changed from the base of the PR and between d7c5aa9 and 5317803.
Files selected for processing: 3
internal/jellycompat/audio_selection_test.go
internal/jellycompat/handlers_playback.go
internal/jellycompat/streams.go
Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 2 remain after this review.
The reason will be displayed to describe this comment to others. Learn more.
Major · Stability & Availability · Heavy lift
A refused planned audio switch leaves the current playback unservable.
When the same-node replacement start returns KeyframePlanned=false, startRemoteTranscodeWithToneMapMode stops the remote job for the upstream session. That deletes the node recipe and fences the transport. The audio-selection rollback restores only the selected audio index. It does not restart the old track or restore the node job. The compat recipe still points at the node, so the next segment request relays there and fails with 502 TranscodeUnavailable. The old track stops serving until the client starts playback again.
Restore the old run before the refusal stops it, or refuse before stopping the transport. The node's replacement semantics decide which is safe, and this repository does not show them.
Resolve conflicts with Silo-Server#4400, which added KeyframePlanResume beside this
branch's KeyframePlanned in the transcode options, recipe card, node start
response, and the jellycompat recipe. Both fields are kept. The node API doc
keeps Silo-Server#4400's resume conditions and describes the audio switch restart for a
session planned from the beginning. The OpenAPI contract is regenerated.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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
bugSomething isn't workinggoPull requests that update go codeimpact: playbackCan't play, stalls, or wrong mediapriority: P2Limited scope, workaround exists, or polishsize/L200–499 added + deleted lines (all files); change volume, not priority.
2 participants
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
Closes #4044
Related issue: N/A
Validation tasks: none
Other clients: Apple N/A (server-side restart recipe); Android N/A (server-side restart recipe); Roku N/A (server-side restart recipe)
Depends on: none. Builds on #1770 (merged). Merge order with #4400 (open) is free, but see Risks.
With Complete playlists for copied video on, a Jellyfin-compat client that switched audio mid-stream on a keyframe-planned copy session running on a transcode node got FFmpeg's growing playlist and fixed-grid segment numbers from the node. The client still held the planned VOD playlist for the same URL, so planned segment N and the node's segment N were different media. A session running locally was not affected.
Approach
The node path in
restartCompatTranscodeForAudioSelectionasked the node to start at the player's position. The node starts the replacement in a new output directory and plans only a run that starts at the beginning (planCopySegments), so it served FFmpeg's playlist. The keyframe-playlist attestation still passed, because the node attests the requested flag, not whether it planned.The node now reports whether it planned.
StartTranscodesetsKeyframePlannedfrom the plan it resolved, the node returns it askeyframe_plannedin the start response, and the core keeps it in the session's recipe. When the recipe says the node planned a run from the beginning, the audio switch restarts the node from that start, asRecipeOptsalready does for a local session's recipe. The node plans the same segments again. The player's next segment request then restarts FFmpeg at the planned segment for its position through the node's planned segment recovery, after the from-start run has set the timeline. The node's rebuild of a copy card works the same way. The persisted recipe keeps the from-start start and the flag, so later rebuilds and switches stay planned.The replacement of a planned session must plan too. The node writes it into a new output directory, where planning can still fail: the keyframe index can't be read, the start probe fails, or the plan record can't be written. A reply without
keyframe_plannedstops the remote job before the recipe is persisted, and the audio switch fails and rolls back the selection. The player doesn't get segments its playlist doesn't list, but it needs a new playback session, the same limit asErrKeyframePlanChangedon a rebuild.Any other node session restarts at the position, as on
main. That covers a copy the node couldn't plan (no or unusable keyframe index), a session that resumed mid-stream, and a session on a node too old to send the field. Restarting a session on FFmpeg's playlist from the beginning would leave the throttled run far behind the player.A reviewer may ask why the node doesn't start the new run directly at the planned segment, like the local path. The new directory has no recorded timeline. A run started mid-stream would set its own timeline, which is off by the source's B-frame delay (
TestPlannedRestartKeepsTheFromStartTimeline). Starting there would also need a new start-request field.Validation
main, its "kept FFmpeg's playlist" case fails on the PR's first commit, its "replacement lost the plan" case fails without the third commit's check, and all pass now. New node andStartTranscodecases checkkeyframe_plannedfor a source with and without a keyframe index.make verify-apiv2-openapi: current after regeneration (twokeyframe_plannedfields). The web type check was not run here; the generated web types don't include these schemas.go testforinternal/jellycompat,internal/playback/...,internal/transcodenodeandinternal/api/handlers: the same tests fail before and after the change, and only those. All of them are DB tests that fail because the local test database is not migrated to currentmain(relation "watchlist_title_promotions" does not exist):TestDeletedProfileCompatSessionsEndPostgres,TestSignInRacingProfileDeleteKeepsNoSessionPostgresTestAdminAPIKeyCreationHoldsOwnerRulesAgainstPromotionDB,TestLiveSessionReadsTheSyncedRowDB,TestNativeSessionsListLifecycleDB,TestLifecycleSweepSelectsWhatItCanEndDB,TestLifecycleSweepPassesLiveJellyfinPlaysDB,TestLifecycleSweepBacksOffFailedEndsDB,TestLifecycleSweepEndsReportedPlaysDB,TestProfileAuditDB,TestProfileWritesQueueBehindAccountLockDBinternal/playback:TestInvalidateHWProbeCacheSupersedesAnInFlightProbetimed out once onmain(hardware encoder probe deadline on this VM) and passed in both runs after the change.make lint-changedwith golangci-lint v2.15.0 (the CI version): 0 issues.Evidence
Nothing a user sees changes apart from the fixed playback, so this is how the change was checked.
Before the fix, on
mainat 217ff25 plus the new test:The PR's first commit, with the session the node kept on FFmpeg's playlist:
Without the third commit's check, with a planned session whose replacement the node can't plan:
After all three commits:
Package runs after the second commit; the third changes only
internal/jellycompat, rerun withinternal/api/handlerswith the same DB failures (as listed above, the same set as onmain):Risks
keyframe_planned, so an audio switch on such a node session restarts at the position, as onmain. The bug stays for those sessions until they start again.KeyframePlanResumefor a node session that resumed mid-stream. Once it merges, such a session is planned too, and this change still restarts it at the new position. That restart would need to resend the recipe's original resume start. This PR does not cover it. It is a follow-up after fix(playback): serve a resumed copy stream from a complete keyframe playlist #4400, which could also share one node-reported field with this one.Checklist
AI Disclosure
🤖 Generated with Claude Code
Note
Keep keyframe playlist across remote audio-selection restarts
keyframe_plannedboolean in the transcode-start response (server.go), and the API contract documents it (openapi.json, transcode-node-api.md).KeyframePlannedviaRecipeCardround-tripping, andplayback.StartTranscodesets it from the resolved copy plan rather than the caller-supplied value (transcode.go, recipecard.go).PlaybackHandler.restartCompatTranscodeForAudioSelectionrestarts at seek zero and requires the node to attest a plan; if the node does not, the replacement is stopped and the original session is kept (streams.go, handlers_playback.go).keyframe_planned; for planned sessions, an audio switch against such a node fails the restart instead of silently losing the keyframe playlist.Macroscope summarized 3c07fb6.