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(playback): relay a stale session copy to its node instead of transcoding locally - #4604
Closes#4601
Related issue: N/A
Validation tasks: none (the node failover path that #1177 C3 checks is unchanged)
Other clients: Apple N/A (no client-visible change); Android N/A (no client-visible change); Roku N/A (no client-visible change)
With two or more API replicas and no session affinity, an API replica can start its own FFmpeg for a transcode that is supposed to run on a transcode node, even with transcode routing set to "Any worker only". This change makes that replica relay the request to the node instead.
Each API replica keeps its own in-memory copy of a playback session. When a client starts direct play on replica B and then replans to a transcode on replica A, A starts the transcode on the node and hands the client a stream token whose recipe card names that node. B never sees the replan, so its copy still says "direct play, no node". When the next manifest or segment request lands on B, the serve handler only looks at B's copy, finds no node and no local runtime, and rebuilds the transcode from the token as a local FFmpeg. The node and B then both encode the same session. The same happens when B's stale copy is an earlier local transcode.
Approach
The native manifest and segment handlers now check the verified recipe card when the live session copy names no node. If the card names a node, the request is relayed to that node's transport. If the node can't be reached, the handler answers 404 so the client replans. It never rebuilds locally and never moves the transcode from that card, because the card can be older than the replica's copy. The relay goes to the node the shared node recipe store names for the card's transport, which a move to another node updates, and falls back to the card's node. A failed relay marks the node unreachable, as the session relay does.
A copy that names no node but still carries the card's transport id is not stale: it is a transcode this server moved off a dead node, which keeps the transport id and the client's token. When its local runtime is lost, it is rebuilt here from the card with the node cleared, the same rewrite the move uses.
ReconstructTranscodeWithError refuses to start a local FFmpeg for any card that names a transcode node. It still returns a runtime that is already registered for the session. Moving a transcode to this server (moveTranscodeToLocalV3) already clears the node from the card first.
The Jellyfin-compatible local start only runs once routing has put the transcode on this server, so it clears any earlier node from its copy of the recipe and keeps resuming from it as before.
The replica's stale copy is still not updated when another replica replans the session. Keeping replica copies in step after a replan is a larger change, and this one only makes the stale copy serve correctly.
Validation
New handler test: a stale direct-play copy and a stale local-transcode copy receive a token naming a node. Both relay the node's manifest and start no local transcode, and an unreachable node gives 404 with no local transcode. All three cases fail on main (a local FFmpeg starts) and pass with this change.
Focused tests for the playback reconstruct paths, the native relay, rehome and serve handlers, and the whole internal/jellycompat package pass locally. go vet is clean on the three changed packages.
Live repro on a local two-replica deployment with a transcode node and worker_only routing: main starts a second encode on the stale replica, this change does not (see Evidence).
Review commit: the stale-copy test gains a segment-route row, a moved-transport row, and a denied plan-scoped transport row, and a new test covers a transcode moved to this server that loses its runtime. The moved-transport row and the new test fail on the head before the review commit (404); the new test passes on main. A one-replica sandbox built from the final head with worker_only routing relays HLS through the API to the node, and the API runs no FFmpeg.
Main merged in after fix(playback): stop forcing a transcode for multi-PPS H.264 #5144 removed the copy-safety reconstruct refusal and its test file. The stale-copy branch keeps its relay and moved-here rebuild without that verdict call. The stale-copy test still fails on current main in every row, and the handler, playback, and jellycompat packages pass on the merged head.
Maintainer re-check on 7e2ce3740a (current main merged in): one sandbox ran two API replicas on the same Postgres and Redis, a transcode node, and worker_only routing. After a replan on replica A, the manifest from replica B started a second encode on main and was relayed from the node on this head, with no FFmpeg on B. With the node killed, B answered 404 and started no FFmpeg. The stale-copy test fails on current main in all five rows.
I reproduced the issue on a local deployment: two api replicas sharing Postgres and Redis, one transcode node, and video transcode execution set to worker_only. Each build ran on a fresh database with the same steps. Playback starts as direct play on replica B, the player's media request reaches replica A, A replans to 720p (served by the node), and then the manifest request goes to B. FFmpeg processes were matched to their parent process every 0.2 s.
main (35b0ed7f0)
This change (968331159)
Manifest from replica B
200, from B's own FFmpeg
200, relayed from the node
FFmpeg encodes for the session
2 (node and replica B)
1 (node)
Replica B log
transcode process reconstructed from recipe card, execution_mode=integrated
request line only
Surface and build: native /api/v2 playback serving, local builds of the two commits above.
Risks
A replica can now relay to the node a signed stream token names even when its own copy of the session says otherwise. That is the same trust the existing path gives a token when a replica has no copy at all. A token older than the replica's copy relays to a transport that has stopped and gets 404, as before.
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 how I checked a change nobody sees.
Fixed: recovery of a transcode moved to this server, the relay following a moved transport, the node health mark, and the refusal's ordering. Answered: the remaining stale-copy cases (a live local runtime, an older token, a node reviving a retired transport from its token) also happen on main and are left for follow-up work.
AI Disclosure
Harness: Claude Code (desktop app)
Tool(s): Claude Code, GitHub CLI
Model(s): claude-opus-5-5
Involvement: AI-assisted. AI-assisted with Claude Opus. I directed the task and designed the work.
Adversarial review: a second Claude Opus reviewer checked the approach before and after the change. It found that refusing the local rebuild alone would leave the stale replica answering 404 for the rest of playback, which led to the relay to the card's node. It also flagged the Jellyfin-compatible local start, which now clears the node from its recipe copy. The maintainer review's rounds are under Council review.
Note
Relay stale playback session copies to their node instead of transcoding locally
A replica holding a stale session copy no longer rebuilds a transport owned by another node. Instead, PlaybackHandler.relayStaleCopyToCardNode forwards manifest and segment requests to the node recorded for the card transport, preferring a validated route from the shared node recipe store and falling back to the card's node URL.
TranscodeManager.ReconstructTranscodeWithError now refuses to reconstruct a recipe card that names a transcode node, returning nil. A transport actually moved to the local server is still rebuilt, via movedHereFromCardNode and localTranscodeCard (playback_transcode_rehome.go).
PlaybackHandler.ensureTranscodeSessionWithToneMapMode clears the transcode node URL from stored compatibility recipes before local reconstruction (streams.go).
Risk: denied transports now return 410 and unreachable relay nodes return 404 in playback.go; clients that relied on local reconstruction or other status codes for these cases will see different responses.
…scoding locally
Without session affinity, a replica can keep its copy of a session after
another replica replans it onto a transcode node. The client's new stream
token names the node, but the stale copy names none, so the replica's
manifest and segment handlers rebuilt the transcode from the token as a
local FFmpeg, even under "Any worker only" routing.
The serve handlers now relay such a request to the node the verified card
names, and report the session missing if that node can't be reached so
the client replans. ReconstructTranscodeWithError refuses any card that
names a node, as a backstop for every caller. The jellycompat local start,
which only runs once the route is on this server, clears the node from its
recipe copy so it keeps resuming from it.
ClosesSilo-Server#4601
It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.
Playback handlers now relay eligible stale-copy requests to the transcode node recorded for the transport. Local reconstruction refuses node-backed recipe cards, while local moves and Jellyfin-compatible reconstruction clear node routing before rebuilding.
Handlers resolve the transport ID, check denial, and relay stale-copy manifest and segment requests to the stored node or the recipe card’s node. Tests cover successful relay, denied transport, unreachable node, moved transports, and a local move. The protocol documentation describes the relay behavior.
Reconstruction refuses a recipe card with a node URL. Local move handling and Jellyfin-compatible reconstruction clear node routing on a copied recipe before local reconstruction. Tests cover rebuilding locally after a transcode moves to this server.
sequenceDiagram
participant Client
participant PlaybackHandler
participant RecipeStore
participant TranscodeNode
Client->>PlaybackHandler: Request manifest or segment
PlaybackHandler->>RecipeStore: Resolve current node for transport
RecipeStore-->>PlaybackHandler: Return stored node or no matching recipe
PlaybackHandler->>TranscodeNode: Relay request to resolved node
TranscodeNode-->>PlaybackHandler: Return response or relay error
PlaybackHandler-->>Client: Return node response, 404, or denied response
Loading
Possibly related issues
Issue #4610 describes a related live-runtime case that this PR does not address: a replica with a local FFmpeg runtime does not read a newer stream token.
Possibly related PRs
Silo-Server/silo-server#2350: Both changes use the shared recipe store’s node information for transcode moves and playback routing.
Stale-copy playback now relays to the transcode node instead of starting a duplicate local encode. If the node cannot be signed for, the client gets a 502 or 500 instead of the 404 the change specifies. The effect is limited to that failure path, so the change is mergeable with a small follow-up.
Security architecture risk: Low · up to 0aac0
The change prevents a stale replica from starting a duplicate local encode for a worker-backed stream. A narrow handoff risk remains: if the current worker assignment is unavailable, a stale recipe can still direct playback to the previous worker while that worker is retiring the old encode.
Retained concerns
Low · architecture · inferred: After a move from a worker to the API, the shared worker recipe is deleted and retirement of the former worker is asynchronous. A stale non-node replica can interpret that deletion as a cache miss and relay to the worker named by the old card. If that worker is still serving the transport, requests can reach it after executor ownership moved. The base did not relay from this stale-copy branch; this is a new route to the former executor, not evidence of new cross-session access.
Security review details
Security Blast Radius
inferred — The demonstrated reach of the new branch is from a public manifest or segment request to the worker serving the transport named by a session-bound recipe. A shared-store override must match the session, user, and transport, and the API must be able to sign for the destination worker.
Trust Boundaries and Controls
observed — The stale-copy relay follows live-session identity, profile, and API-egress checks, and checks denial for the card's transport before contacting the worker. The relay strips the stream token from the forwarded URL and forwards it in a header only after verifying that it belongs to the requested session.
Resilience and Maintainability Implications
observed — The new stale-copy branch can refresh activity and mark a worker unreachable, but it does not publish an executor change or start a local encode. The existing move path still rechecks denial, commits against the expected route, and cleans up a replacement that loses the move.
Hardening Proposals
proposed — Distinguish a missing worker recipe from an explicit move away from the worker, so a stale card cannot route back to the previous executor after ownership has changed.
Pre-merge checks: 4
Check name
Status
Explanation
Title check
The title names the main change: a stale playback session copy is relayed to its transcode node instead of being transcoded locally. This matches the raw summary, the objectives, and the description. …
Linked Issues check
Directly linked issue #4601 requires that, with several API replicas, no session affinity, and "Any worker only" routing, an API replica does not start a local FFmpeg for a transcode that runs on a tr…
Out of Scope Changes check
All changed areas serve the stale-copy playback path that #4601 concerns: playback.go (manifest and segment serve handlers), playback_transcode_rehome.go (relay helper, stored-recipe lookup, movedHere…
Description check
The description is detailed and directly related to the changeset. It explains the stale playback-session copy problem on multiple API replicas, the relay to the transcode node named by the recipe car…
Full details: Title check
Explanation
The title names the main change: a stale playback session copy is relayed to its transcode node instead of being transcoded locally. This matches the raw summary, the objectives, and the description. The title is 84 characters, which is slightly long but still concise and specific.
Full details: Linked Issues check
Explanation
Directly linked issue #4601 requires that, with several API replicas, no session affinity, and "Any worker only" routing, an API replica does not start a local FFmpeg for a transcode that runs on a transcode node. At head 0aac0a8, relayStaleCopyToCardNode (internal/api/handlers/playback_transcode_rehome.go) serves a stale copy that names no node from the verified card's node. It prefers the node in the shared node recipe store, validated by rehomeRecipeServesV3, and falls back to the card's node. On relay failure it marks the node unreachable, writes 404, and does not rebuild locally. The code read at head confirms this path. ReconstructTranscodeWithError refuses a card with a non-empty node URL, and the jellycompat local start clears the node before local reconstruction. A node-less copy that carries the card's transport ID (movedHereFromCardNode) is a transcode moved to this server by the existing move path. That move runs only when routing policy lets the API execute, so a node-assigned transcode is not rebuilt locally. The new handler tests cover stale direct-play and local-transcode copies, the moved-transport row, and the unreachable-node 404. The author and reviewer report a two-replica repro with one encode. Limitation: the diffs of playback.go, transcode_manager.go, and streams.go could not be read in this review (changed blobs unavailable), so those conclusions rest on the change summaries and reviewer reports. The PR description line "never rebuilds locally" is broader than the moved-here exception; the code, not the description, is assessed.
Full details: Out of Scope Changes check
Explanation
All changed areas serve the stale-copy playback path that #4601 concerns: playback.go (manifest and segment serve handlers), playback_transcode_rehome.go (relay helper, stored-recipe lookup, movedHereFromCardNode, localTranscodeCard, transport deny checks), transcode_manager.go (refusal to reconstruct cards naming a node, with the existing-session check kept first), internal/jellycompat/streams.go (clears TranscodeNodeURL before local reconstruction), the handler and copy-safety tests, and docs/architecture/playback-protocol-v3.md (describes the relay behavior). The incremental changes since the previous review add tests and fixes within the same path and add no unrelated feature or client-visible change. Limitation: the playback.go, transcode_manager.go, and streams.go diffs could not be read in this review, so this verdict rests on the change summaries and the rehome file read at head.
Full details: Description check
Explanation
The description is detailed and directly related to the changeset. It explains the stale playback-session copy problem on multiple API replicas, the relay to the transcode node named by the recipe card, the 404 fallback when the node is unreachable, the change to ReconstructTranscodeWithError, and the Jellyfin-compatible local start. It also gives validation steps and evidence, so it describes the changes in the diff.
Finishing Touches
Generate unit tests (beta)
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.
…copy
A stale session copy relayed to its card's node without consulting the
video-copy safety verdict, which the path for a session with no copy
applies to node cards too. Check the verdict first.
…sport
A transcode this replica moved off a dead node keeps its transport id, and
the client keeps the token minted for that node. When its local runtime was
later lost, the stale-copy check treated the copy as stale, relayed to the
dead node and answered 404, where main rebuilt it locally. A copy that names
no node but carries the card's transport id is that moved transport, so it
now rebuilds locally from the card with the node cleared, as the move did.
A stale copy now relays to the node the shared node recipe store names for
the card's transport, which a move to another node updates, and falls back
to the card's node. A failed relay marks the node unhealthy, as the session
relay does. The node-card refusal in ReconstructTranscodeWithError now runs
after the check for a registered runtime, so a runtime that registered
concurrently is still served.
The deny check, the card transport id, and the local card rewrite are
shared helpers instead of copies.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
The reason will be displayed to describe this comment to others. Learn more.
Review of 7658bee (the two commits here plus a merge of current main, which I pushed so the review covers what would land).
The fix for #4601 holds: a replica whose copy of the session names no node now relays to the token's node instead of starting FFmpeg, and the new handler test fails on main for that reason. I found one regression and three smaller gaps on the new path, all inline. I'm fixing all four in a commit on this branch.
Left for the maintainers (summary comment to follow): a stale copy that still has a live local runtime keeps serving it, which is the case already discussed in the Kody thread; and the older-token and proxy-egress variants of the same stale-copy problem. Both predate this PR.
Code Review Completed, but its comments could not be posted ⚠️
The review produced 1 comment(s), but none could be posted to this pull request (for example, the platform rejected them with a rate limit). This is not a clean review: comment @kody review on this PR to run it again.
Kody Guide: Usage and ConfigurationInteracting with Kody
Request a Review: Ask Kody to review your PR manually by adding a comment with the @kody start-review command at the root of your PR.
Validate Business Logic: Ask Kody to validate your code against business rules by adding a comment with the @kody -v business-logic command.
Provide Feedback: Help Kody learn and improve by reacting to its comments with a 👍 for helpful suggestions or a 👎 if improvements are needed.
Current Kody ConfigurationReview Options
The following review options are enabled or disabled:
Reviewed head: 7e2ce3740a (the author's two commits, one review commit, and merges of main; the latest merges main at d858c3c01).
Fit: 8/10 · Readiness: 9/10 — conditional (assuming CI is green)
What changed in this pass
I merged current main into the branch (7e2ce3740a). The merge was clean. Three of the merged commits touch files this PR changes (#4572, #5180, #4621). None of them touch the stale-copy path, and the council checked each one. No code changes beyond the merge.
The CodeRabbit thread about a 502 on an unsignable node is answered in place. That 502 matches the existing session relay on purpose, so I left it as is.
The four review findings from the earlier pass were fixed in b77637388 and are resolved in their threads.
Verification
Live, two API replicas, main against this head. One sandbox ran two API processes on the same Postgres and Redis, a proxy node, and a transcode node. Video transcode and remux execution were set to worker_only. Playback started as direct play on replica B, replica A replanned it to 720p on the transcode node, and then the manifest was fetched from B with the new token.
On main (d858c3c0), B started its own FFmpeg, so the node and B both encoded the session. B's log shows transcode process reconstructed from recipe card with execution_mode=integrated. A second run added a second encode on B.
On this head (7e2ce374), B relayed the manifest and the first segment from the node and ran no FFmpeg. Two runs gave the same result.
With the transcode node killed, B answered 404, started no FFmpeg, and logged that the relay could not reach the node.
TestTranscodeServeStaleCopyRelaysToTheTokensNode fails on current main in all five rows ("started a local transcode for a session that runs on a node") and passes on this head. TestTranscodeServeRebuildsATranscodeMovedHereAfterItsRuntimeIsLost passes on both, as expected: it guards against the regression the review commit fixed.
The transcode serve handler tests, internal/playback, and internal/jellycompat pass on this head.
CI: ci / Go DB pins failed in internal/backup (TestRestorePluginProvisioningDB, "other clients are connected" to its test database). This PR doesn't touch backup code, and main's own run at d858c3c01 fails the same job on a different backup restore test. I reran the failed job.
The v1.0 board check ran. The only passed case the diff reaches is #1177 C3 (remove a worker during playback). On one API replica its failover path is unchanged. moveTranscodeToLocalV3 builds the same local card through the new shared helper. The body's Validation tasks: none stands.
Fit
This makes "Any worker only" hold when several API replicas run without session affinity. That closes a real gap in a documented policy without adding a setting. It stays at 8 because it handles the stale replica copy in the serve path instead of fixing the cause. Each replica keeps its own in-memory copy of the session route, and nothing shared says which copy is current. The PR description says so.
Left for the maintainers
None of these is caused by this PR. On main, the first two start a duplicate encode in the same state.
When replica A moves a transcode off a dead node to its own process, it deletes the shared node recipe for that transport. Replica B's stale copy then falls back to the dead node named in the token, answers 404, and the client replans. Writing a "moved to the API" record instead of deleting it would let B tell the two cases apart. That changes what the node-side resolve reads, so it belongs in its own change.
Two council members traced a Jellyfin-compatible case that also happens on main. The master manifest picks a local route while the shared compat recipe still names a node from an earlier start on another replica. The local rebuild then uses that node's recipe while the node may still be encoding. It was traced, not reproduced.
After a stale-copy 404, a recovery replan that lands on the same stale replica doesn't see the dead node, so it excludes the failed recipe and may step down a quality. It needs a node to die while a stale copy is serving.
Round 3 found nothing the merge or this PR introduced. Sol's three findings rest on rare double faults: a node dying while a stale copy serves, a Redis read failing during a move, and a stop landing during the store lookup. The existing session relay handles the last one the same way. Opus's and Gemini's findings are the Jellyfin-compatible case above, plus a suggestion to share the local-card rewrite between the native and compat paths.
Main (Silo-Server#5144) removed the copy-safety reconstruct refusal and its test file.
The stale-copy branch in loadTranscodeServeSession keeps its relay and the
moved-here rebuild without the removed verdict call.
Files skipped from review as they are similar to previous changes: 1
docs/architecture/playback-protocol-v3.md
Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 1 remain after this review.
Main's Silo-Server#4604 relays a request from a replica whose copy of the session
missed another replica's replan onto a transcode node. That copy still
records the transport generation of its own plan, so the superseded check
refused the client's current player before the relay could run.
When the marker differs from the copy's generation, the check now asks the
shared node recipe store whether the marker names a node transport of this
session that still runs. Every replan and teardown deletes that recipe
before stopping the transport, so a stored recipe marks the request
current and it is relayed; without one the request is still refused. A
copy with a node or local runtime of its own keeps the refusal.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ing the new stream (#4641)
* fix(playback): refuse media requests from a superseded transport
A replan can start a new HLS transport under the same playback session
id. The player being replaced keeps fetching segments by number from the
previous plan's playlist, and those requests seek-restarted the new
transport at the old player's position, so the stream the client was
switching to was destroyed (and at the end of the file the session
looped on 500/404).
Every v3 HLS stream URL now carries silo_transport, naming the transport
generation (the plan's output directory or transcode-node transport id).
The playlist echoes the query into its segment URIs, so playlist-relative
clients carry it unchanged. The session records the generation of its
current transport; a request naming another one answers 404
playback_transport_superseded before it can wait for, restart, relay to
or reconstruct a transport. The API origin and the proxy's /stream/v3
grant routes enforce it, and /api/v2 maps it to a problem type of the
same name. URLs without the marker keep the old behavior.
* refactor(playback): reuse existing query and test helpers for transport markers
Use appendPlaybackQueryV3 and playbackTestRequest instead of local copies,
and share the superseded-transport message between the API and the proxy.
* fix(playback): keep the current player's marker on a reused transport
A session rebuilt after an API restart has no recorded transport
generation. A replan that reuses its running transport republished the
old URL but recorded a fresh generation, so the server refused the
player it had just kept. The reused transport now takes its generation
from the marker of the URL it republishes.
The proxy grant routes also answer a marked HLS request against a grant
that names no transport (a replan away from HLS) as superseded, matching
the API origin. The v2 contract declares silo_transport on the HLS
operations, v2 problems drop the v1 X-Silo-Playback-Error side channel,
and the new problem type gets its catalog key.
* docs(apiv2): say when silo_transport refuses a superseded request
* fix(playback): keep a short query literal in the playlists the server builds
A header-authenticated plan URL now carries only the silo_transport marker. On a title past about 95 minutes, that query alone crossed the substitution threshold and the synthetic playlist became version 8 with EXT-X-DEFINE, which a client without hls_variable_substitution_v1 (AetherEngine) can't resolve. Apply the per-URI saving the rewritten playlists already require, so only a credential-sized query is substituted.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
* fix(playback): mark HLS URLs only for clients that opt in
The silo_transport marker went on every v3 HLS URL. Apple's player
accepts only `seek` in a header-authenticated media URL's query, so it
refused every HLS transcode and remux plan.
The marker now needs the hls delivery feature hls_transport_marker_v1,
which /api/v2 advertises. Without it the URL stays as it was, and an
unmarked request is never refused, so clients keep today's behavior
until they opt in.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
* chore(translations): sync the superseded-transport error from the catalog
Generated from silo-translations at 866636c, the merge of
Silo-Server/silo-translations#110. Re-pin to its release before merge.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
* docs(playback): note that a grant without a transport refuses marked requests
A proxy grant written after a replan away from HLS names no transport,
and the proxy refuses every marked HLS request against it. The grant
store outlives an API restart, so the restart fallback has this one
exception.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
* docs(playback): say a superseded answer can arrive during the client's own replan
The server switches to the new transport before the replan's response is
sent, so the player being replaced can be refused first. Tell clients to
wait for the replan's answer before acting, and that a failed replan
restores the previous transport and its URL.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
* fix(playback): relay a marked request a stale session copy cannot place
Main's #4604 relays a request from a replica whose copy of the session
missed another replica's replan onto a transcode node. That copy still
records the transport generation of its own plan, so the superseded check
refused the client's current player before the relay could run.
When the marker differs from the copy's generation, the check now asks the
shared node recipe store whether the marker names a node transport of this
session that still runs. Every replan and teardown deletes that recipe
before stopping the transport, so a stored recipe marks the request
current and it is relayed; without one the request is still refused. A
copy with a node or local runtime of its own keeps the refusal.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
---------
Co-authored-by: Quick <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 #4601
Related issue: N/A
Validation tasks: none (the node failover path that #1177 C3 checks is unchanged)
Other clients: Apple N/A (no client-visible change); Android N/A (no client-visible change); Roku N/A (no client-visible change)
With two or more API replicas and no session affinity, an API replica can start its own FFmpeg for a transcode that is supposed to run on a transcode node, even with transcode routing set to "Any worker only". This change makes that replica relay the request to the node instead.
Each API replica keeps its own in-memory copy of a playback session. When a client starts direct play on replica B and then replans to a transcode on replica A, A starts the transcode on the node and hands the client a stream token whose recipe card names that node. B never sees the replan, so its copy still says "direct play, no node". When the next manifest or segment request lands on B, the serve handler only looks at B's copy, finds no node and no local runtime, and rebuilds the transcode from the token as a local FFmpeg. The node and B then both encode the same session. The same happens when B's stale copy is an earlier local transcode.
Approach
ReconstructTranscodeWithErrorrefuses to start a local FFmpeg for any card that names a transcode node. It still returns a runtime that is already registered for the session. Moving a transcode to this server (moveTranscodeToLocalV3) already clears the node from the card first.The replica's stale copy is still not updated when another replica replans the session. Keeping replica copies in step after a replan is a larger change, and this one only makes the stale copy serve correctly.
Validation
main(a local FFmpeg starts) and pass with this change.internal/jellycompatpackage pass locally.go vetis clean on the three changed packages.worker_onlyrouting:mainstarts a second encode on the stale replica, this change does not (see Evidence).main. A one-replica sandbox built from the final head withworker_onlyrouting relays HLS through the API to the node, and the API runs no FFmpeg.mainin every row, and the handler, playback, and jellycompat packages pass on the merged head.7e2ce3740a(currentmainmerged in): one sandbox ran two API replicas on the same Postgres and Redis, a transcode node, andworker_onlyrouting. After a replan on replica A, the manifest from replica B started a second encode onmainand was relayed from the node on this head, with no FFmpeg on B. With the node killed, B answered 404 and started no FFmpeg. The stale-copy test fails on currentmainin all five rows.Evidence
Evidence: https://evidence.siloserver.org/r/silo-server/pr-4604/
I reproduced the issue on a local deployment: two
apireplicas sharing Postgres and Redis, onetranscodenode, and video transcode execution set toworker_only. Each build ran on a fresh database with the same steps. Playback starts as direct play on replica B, the player's media request reaches replica A, A replans to 720p (served by the node), and then the manifest request goes to B. FFmpeg processes were matched to their parent process every 0.2 s.main(35b0ed7f0)968331159)transcode process reconstructed from recipe card,execution_mode=integratedSurface and build: native
/api/v2playback serving, local builds of the two commits above.Risks
A replica can now relay to the node a signed stream token names even when its own copy of the session says otherwise. That is the same trust the existing path gives a token when a replica has no copy at all. A token older than the replica's copy relays to a transport that has stopped and gets 404, as before.
Checklist
Council review
Rounds: 3, last reviewed 7e2ce37
Fixed: recovery of a transcode moved to this server, the relay following a moved transport, the node health mark, and the refusal's ordering. Answered: the remaining stale-copy cases (a live local runtime, an older token, a node reviving a retired transport from its token) also happen on
mainand are left for follow-up work.AI Disclosure
Note
Relay stale playback session copies to their node instead of transcoding locally
A replica holding a stale session copy no longer rebuilds a transport owned by another node. Instead,
PlaybackHandler.relayStaleCopyToCardNodeforwards manifest and segment requests to the node recorded for the card transport, preferring a validated route from the shared node recipe store and falling back to the card's node URL.TranscodeManager.ReconstructTranscodeWithErrornow refuses to reconstruct a recipe card that names a transcode node, returning nil. A transport actually moved to the local server is still rebuilt, viamovedHereFromCardNodeandlocalTranscodeCard(playback_transcode_rehome.go).PlaybackHandler.ensureTranscodeSessionWithToneMapModeclears the transcode node URL from stored compatibility recipes before local reconstruction (streams.go).Macroscope summarized 7e2ce37.