Repository navigation
Conversation
Adds the per-node credential that thin transcode nodes will sign with.
Nothing signs with it yet, so existing nodes behave as before.
- stream_nodes.node_key_ciphertext holds the key encrypted under the row
AAD. It is a credential, not configuration: issuing one moves neither
the admin revision nor the pool generation.
- POST /api/v2/admin/nodes/{id}/key issues or rotates a key and returns it
once. Node rows gain key_issued, and the node capabilities gain
node_keys. Proxies take no key (409).
- nodepool.KeyRegistry holds every node's credential, disabled nodes
included, on API servers and proxies. It reloads on node_pool_changed,
every minute, and on a lookup miss at most once a second. A proxy that
starts before the column is migrated keeps running and loads it later.
- Two transcode nodes can no longer be saved at one canonical URL, since
the registry finds a node by that address.
Co-Authored-By: Claude Fable 5.2 <[email protected]>
The core now signs every request to a transcode node with that node's key, and the node verifies with the same key from SILO_NODE_KEY. The shared secret signs only requests to proxies. - nodeauth splits signing by direction: core to node and node to core use separate HKDF labels and canonical versions, so a request captured in one direction never verifies in the other. The node-to-core signature also covers the source grant header. - Senders name the kind of node they target. The registry's keyring gives a transcode target only that node's key and gives a proxy target the shared secret only for a URL registered as a proxy. An unknown URL and a keyless node are errors; neither falls back to the shared secret. - A transcode node without a usable key stays listed and health-checked but takes no new work. - The node's signed routes accept no legacy bearer. - HTTP clients that call a node refuse redirects explicitly. The node still holds its database and Redis; later commits remove them. Co-Authored-By: Claude Fable 5.2 <[email protected]>
Adds the routes a thin transcode node will call instead of reading the database and Redis itself. Nodes do not call them yet. - nodecontrol.RequireNode verifies a node-signed request against the key registry and puts the node id in the request context. Handlers take the node's identity only from there. A disabled node is accepted; a deleted, keyless or proxy row gets 401. - GET /api/internal/nodes/self/config returns the calling node's settings with its row overrides applied, with the revision as a strong ETag. A test fails when the node reads a config field the document lacks. - POST .../self/report replaces the node's session records and telemetry snapshot, fenced on (boot_id, seq) so a replayed or older report changes nothing. Keys are scoped by the authenticated node id. - POST .../self/logs stores a log batch under the authenticated node and clamps entry timestamps to the core's clock. - POST .../self/health-changed publishes node_drain_changed. - Report, logs and health-changed share a per-node request budget. - The routes stay out of the request log, the activity log and response compression, and the worker protocol contract lists them as node_signed. miniredis is added for tests: CI has no Redis, and the report fence and session replacement are Lua scripts. Co-Authored-By: Claude Fable 5.2 <[email protected]>
Each transcode node shows whether it has a key, with a warning that a node without one takes no work. On a server that can issue keys, an admin can issue or rotate the key. Rotation asks for confirmation and says the node's running streams fail until it restarts with the new key. The new key is shown once, with the SILO_CORE_URL and SILO_NODE_KEY settings the node starts with. It is kept in the dialog's state only, and the dialog cannot be closed while the request is in flight. A refusal shows the server's reason; a lost answer says the key may have rotated. Creating a transcode node offers to issue its key. The translation pin names a local catalog commit. Re-sync to a published release before this merges. Co-Authored-By: Claude Fable 5.2 <[email protected]>
The core now makes the decisions a transcode node made from Redis and the shared secret. Nodes do not call the new routes yet. - POST /api/internal/nodes/self/resolve answers the recipe and playback identity for a node rebuilding a lost HLS session or serving a progressive remux: deny checks, token verification, and a recipe bound to the calling node. A complete stored card wins over a complete token, because a move rewrites the card while the client keeps its old token. A recipe store read error is 503. - POST /api/internal/nodes/self/revoke-recipes revokes the calling node's recipes, for the node to call inside its own force-reload teardown. - A remote stop deletes the transport's stored recipe before it tells the node, unless the recipe names another node URL. A release deletes nothing. jellycompat reuses a transport id across start candidates, so a late stop on one must not remove the next one's recipe. - Every dead-node move writes the stored recipe naming the new executor, for sessions whose URLs carry a token too. jellycompat recipes bind the node they started on. - Every relay that signs a request to a transcode node checks the deny marker first, and a move rechecks it before it commits and before it serves. - A node's 401 and a failure to sign for a node reach clients as the node being unavailable, not as a client auth failure. Neither moves the transcode: a replica with a stale key registry cannot sign for any node. /api/v2 delivery maps a relay 502 to dependency_unavailable. Co-Authored-By: Claude Fable 5.2 <[email protected]>
The core now signs a source grant for every job it sends a transcode node: a stateless capability to use one revision of one catalog file, or theme file, through one node. Nodes do not use grants yet and still approve paths against the catalog themselves. - A grant names the node, the file or theme id, the fspath-encoded catalog path, the size and the modification time, and lasts an hour. Its key is derived from auth.jwt_secret under its own label. Revisions compare the modification time at microseconds, the catalog's precision. - Native and Jellyfin-compatible starts, dead-node moves, download preparation, trickplay, chapter thumbnails and subtitle-sync samples carry source_grant. A move sends the replacement node a fresh grant. When no grant can be minted the work fails over or runs locally as a failed dispatch does. - POST /api/internal/nodes/self/sources/open exchanges a grant for the approved path and a renewed grant. It refuses another node's grant (403), a source that left the catalog or the disk (410) and a changed size or modification time (412). - Resolve checks that the catalog still has the recipe's file or theme and adds a grant for the calling node. - nodesource.Opener is the node side: it opens a grant against the node's own mount, refuses a mount whose revision differs, and renews the grant while the source is open. Co-Authored-By: Claude Fable 5.2 <[email protected]>
…crets A transcode node now starts with two settings, SILO_CORE_URL and SILO_NODE_KEY, and holds no database, Redis, data cipher, event bus or shared secret. There is one transcode node type and no legacy mode: nodes from before this change cannot work with an updated core, or the reverse. Proxies are unchanged. - MODE=transcode branches before the bootstrap. DATABASE_URL, REDIS_URL, SECRET_KEY, NODE_URL and NODE_NAME are ignored with one warning. A plain-HTTP core URL off the host logs a warning, because the node takes its FFmpeg path, directories and input paths from the core's answers. - The node reads its configuration from the core, polls it every 30 seconds, and rereads it when the core pushes a reload. The core pushes after a drain request or resume and after a change to a node's overrides. An unchanged poll keeps the configuration pointer. - Sessions and stream telemetry stay in memory and go to the core in a report every second. Logs, FFmpeg output included, ship to the core. Drain changes are reported to the core instead of the event bus. - The node verifies no stream token and reads no deny marker or recipe. A lost HLS session and every progressive remux request ask the core's resolve route, after the node's own stop fences. A force reload asks the core to revoke the node's recipes first. - Every job opens its input with the source grant it carries, at the approved path on the node's own mount. A mount whose file differs from the core's answers 409. The catalog path authorizers are gone. - Health carries the node control version and key_rejected. The core treats a transcode node without the version, or with a rejected key, as unhealthy, so a node on an older build is not placed. - The omnibus init and the shipped Compose file no longer ask a transcode node for database or Redis settings. Co-Authored-By: Claude Fable 5.2 <[email protected]>
- config now shares the per-node background budget, and resolve and sources/open get a budget of their own (200 a second, burst 600), so a node key cannot loop catalog reads without bound. A node treats 429 as transient on every route. - Log entries a node ships are normalized before they are stored: an address that does not parse is cleared and node-supplied text is capped. A bad row no longer makes the core retry the batch row by row, and the dropped-entries warning is logged at most once a minute per node. - Issuing a key publishes node_pool_changed even when the pool reload fails, and a node's 401 asks the credential registry to reload, so a replica holding a replaced key heals in seconds. - A dead-node move writes the new node's stored recipe as soon as the move commits, then retires the old node. Nodes no longer delete recipes, so the wait left a window where the new node could not rebuild. - A chapter thumbnail job a node cannot serve reports the reason the core falls back to local extraction for. - A rejected key is described with both causes: a replaced key or a clock more than 30 seconds off. - A progressive remux request checks the node's own state before it asks the core. - make dev-transcode starts a node with SILO_CORE_URL and SILO_NODE_KEY. Co-Authored-By: Claude Fable 5.2 <[email protected]>
docs/architecture/transcode-nodes.md is the authority for the design: node keys, signing in both directions, the node control routes, playback authority on the core, source grants, failure behavior and security properties. docs/update-to-1.0.md gains the operator steps for the coordinated node upgrade. Other documents link to the new one and no longer say that a transcode node reads the database, Redis or the shared secret. Co-Authored-By: Claude Fable 5.2 <[email protected]>
…e rejects - Creating, updating or deleting a node now reloads this server's credential registry before the response and publishes node_pool_changed, and reconciliation invalidates the registry when the node list changes. A deleted node kept signing and being signed for until the registry's 60-second reload. - A transcode node shutting down on SIGTERM no longer waits for its sessions while the main server rejects its key: no relay can reach them and nothing will stop them. After a key rotation without a drain, the restart waited out the 10-minute drain timeout. Co-Authored-By: Claude Fable 5.2 <[email protected]>
…te-transcode-nodes - .silo-translations, web/src/locales/*, .silo-translations-files: took main's, then regenerated with sync-translations --local from the rebased silo-translations branch (pin local-de1af480da75). - go.mod/go.sum: kept miniredis/gopher-lua beside main's bumped go-keyring and xxh3; go mod tidy. - scripts/ci/db-contracts.txt: kept both sides' entries. - contracts/api/v2/openapi.json: regenerated; the node protocol's playback_RecipeCard schema gains main's adaptation_reasons. - internal/transcodenode: main's new spawnReconstruct test passes a nodecontrol.Resolution, as this branch's spawnReconstruct takes. Co-Authored-By: Claude Fable 5.2 <[email protected]>
Co-Authored-By: Claude Fable 5.2 <[email protected]>
Co-Authored-By: Claude Fable 5.2 <[email protected]>
- A source grant check that fails for a reason other than a missing file (an I/O error, a stale network mount) now answers 503, which the node retries. It answered 410, which ends the job, so a transient stat error on the API server stopped a transcode of an unchanged file. Minting a grant classifies the error the same way. - A full log throttle searches for expired keys at most once per interval. A flood of unknown node ids paid for a pass over all 4,096 keys on every refused request. - The resume primer test from main set no node keys, so its proxy route was never taken and it passed only where a local FFmpeg was installed. Co-Authored-By: Claude Fable 5.2 <[email protected]>
…swers Co-Authored-By: Claude Fable 5.2 <[email protected]>
…te-transcode-nodes # Conflicts: # .silo-translations # web/src/locales/keys.ts
A node's request budget admits twenty log batches a second, and one batch may be 1 MiB, so a node key could write about 20 MiB a second into the operational log. Log batches now also spend a per-node byte budget on each API server: 128 KiB a second with bursts of 4 MiB. A node past it gets 429, which it already retries. Co-Authored-By: Claude Fable 5.2 <[email protected]>
A transcode node's release (a stop with fence=0) ended whatever job ran under the transport id. A move's rollback and the retire of the node a transport left both send it in the background, so it could land after another API server's move started the same transport on that node and end the newer job; the viewer stalled until the next segment request rebuilt it. A move's start now carries a start_id, and its rollback names it: the node ends only that start's job. A retire names no start, so the node ends only the job it held when the release arrived, not one a start or rebuild published while the release waited for the lifecycle lock. Fenced stops still end any job. Closes Silo-Server#4359 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Clarify the handleStop and test comments on what a release waiting for the lifecycle lock leaves running, and describe the retire as a release in the node API doc. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…there When two API servers moved one transport to the same node at once, the second move's start replaced the job the first move had started and committed. The second move's commit then failed, and it released its own start, which ended the only job left: the node ran nothing for the transport until the next segment request rebuilt it. A start that carries a start_id now answers 409 instead of replacing a job another start with a different start_id published. The losing move moves on to the next candidate, and its rollback names its own start, so the node leaves the winner's job running. A start without start_id (a fresh start or an audio switch) still replaces any job, and a node or core that predates start_id behaves as before. Closes Silo-Server#4364 Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Important Review skippedToo many files! This PR contains 291 files, which is 141 over the limit of 150. To get a review, reduce the PR to 150 files or fewer by splitting it into smaller PRs or changing its base branch. Upgrade to a paid plan to raise the limit. This organization requires a seat for paid usage-based reviews, including automatic and on-demand reviews. Ask an admin to assign a seat or enable paid usage-based reviews for users without a seat in Billing.
|
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:
|
| if err := h.nodeKeyRegistry.Refresh(refreshCtx); err != nil { | ||
| slog.WarnContext(ctx, "node credential reload after an admin change failed; this server applies the change on its next reload", | ||
| "component", "api", "node_id", nodeID, "error", err) | ||
| } |
There was a problem hiding this comment.
Failed credential reload leaves revoked node keys authorized
If KeyRegistry.Refresh fails after the commit, revoked keys remain usable until a later successful reload. Evict the affected credential locally or otherwise fail closed before returning.
Prompt for LLM
File internal/api/handlers/admin_node_key.go, lines 47-50:
Failed credential reload leaves revoked node keys authorized
If the post-commit registry refresh fails, the operation still succeeds while `KeyRegistry.Refresh` retains the old key, so a deleted node or holder of a rotated key can continue authenticating until a later successful reload. Immediately evict the affected credential from the local registry on refresh failure, or otherwise fail closed before returning.
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.
Out of scope for this PR. This line comes from #4337 (already merged into main) and shows here only because this PR is stacked on #4363, which still sits on #4337's original commits. This PR's own change is 45fbbde (the move-start rule in handleStart). I'm leaving it unresolved for the maintainers to decide on.
| // A local transport never reads the stored node card, and one left naming | ||
| // the node the transport left would let that node rebuild it. A session | ||
| // moved before carries a card even when its URLs carry a token. | ||
| h.deleteNodeRecipeV3(ctx, remoteTransportID(session)) |
There was a problem hiding this comment.
Local move can delete a concurrent successor's node recipe
A concurrent move can publish a remote successor before deleteNodeRecipeV3 deletes its recipe, preventing reconstruction after a node restart. Serialize deletion with route changes and verify that the current route is still local.
Prompt for LLM
File internal/api/handlers/playback_transcode_rehome.go, lines 481-484:
Local move can delete a concurrent successor's node recipe
The unconditional recipe deletion runs after the local route commits without checking whether another move has since published a remote successor for the same transport ID. A concurrent successor can therefore lose its newly written recipe and fail to reconstruct after a node restart; serialize the deletion with route changes and verify that the current route is still local.
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.
Out of scope for this PR. This line comes from #4337 (already merged into main) and shows here only because this PR is stacked on #4363, which still sits on #4337's original commits. This PR's own change is 45fbbde (the move-start rule in handleStart). I'm leaving it unresolved for the maintainers to decide on.
| stopCtx, cancel := context.WithTimeout(detached, compatTranscodeMoveTimeout) | ||
| defer cancel() | ||
| if err := h.tm.ReleaseRemoteTranscode(stopCtx, upstreamSessionID, deadNodeURL); err != nil { | ||
| if err := h.tm.ReleaseRemoteTranscode(stopCtx, upstreamSessionID, deadNodeURL, ""); err != nil { |
There was a problem hiding this comment.
A delayed release can stop a successor transcode on the old node
If a transport moves from node A to B and back to A, a delayed ReleaseRemoteTranscode call can stop the successor job because its start identifier is empty. Fence the release with a generation that identifies rebuilt jobs or another conditional release mechanism.
Also found in:
internal/api/handlers/playback_transcode_rehome.go:843-843
Kody rule violation: Fence transcode cleanup against adoption and successor startup
Prompt for LLM
File internal/jellycompat/transcode_failover.go, line 426:
A delayed release can stop a successor transcode on the old node
Fence this asynchronous release to the runtime generation being retired. If the transport moves from node A to B and then back to A before this request arrives, the empty start identifier allows the delayed release to stop the successor job on A. Carry a generation that also identifies rebuilt jobs, or use another conditional release mechanism that cannot remove a successor.
**Also found in:**
- `internal/api/handlers/playback_transcode_rehome.go:843-843`
Kody rule violation: [Fence transcode cleanup against adoption and successor startup](https://kodus.siloserver.org/settings/code-review/1247142351/kody-rules/bc550d90-a21e-4a7e-9d8f-c00d68eb74e8?teamId=ba9922fc-c0ea-4cf8-87bb-9d4f42ffc73e)
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.
Out of scope for this PR. This release comes from #4363 (d67b11e), and this PR's own change is 45fbbde. #4363's Risks section names this case: a release without start_id can still end a newer job that is already running on that node. This PR doesn't change it, because it only stops a move's start from replacing another move's job.
There was a problem hiding this comment.
Agreed. The unfenced retirement release comes from #4363 and is a documented risk there, not a regression introduced by #4432’s own commit. This PR addresses a separate race: preventing one move’s start from replacing another move’s job.
The delayed-release scenario remains a valid concern, but it should be tracked separately rather than treated as a blocker specific to this PR.
| if strings.TrimSpace(secret) == "" { | ||
| return nil, refuseUnavailable | ||
| } | ||
| claims, err := streamtoken.Verify(token, secret) |
There was a problem hiding this comment.
Node resolution accepts capabilities without checking the login session
streamtoken.Verify does not establish that the originating login session is still active, so a revoked session can continue resolving HLS and remux media. Validate the session on every resolution request and require account authentication for legacy unbound tokens.
Kody rule violation: Bind playback capabilities to revocable login sessions
Prompt for LLM
File internal/nodecontrol/resolve.go, line 128:
Node resolution accepts capabilities without checking the login session
Cryptographic verification alone does not establish that the login session which authorized this playback capability is still active. Both HLS and remux resolution use this result to reconstruct media, so a revoked login session can continue using an otherwise valid token. Validate the capability's originating login session on every resolution request, and require account authentication for legacy unbound tokens rather than treating them as standalone authority.
Kody rule violation: [Bind playback capabilities to revocable login sessions](https://kodus.siloserver.org/settings/code-review/1247142351/kody-rules/5e22b6f6-b2e0-41a4-ac6f-c632ec350748?teamId=ba9922fc-c0ea-4cf8-87bb-9d4f42ffc73e)
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.
Out of scope for this PR. This line comes from #4337 (already merged into main) and shows here only because this PR is stacked on #4363, which still sits on #4337's original commits. This PR's own change is 45fbbde (the move-start rule in handleStart). I'm leaving it unresolved for the maintainers to decide on.
There was a problem hiding this comment.
Agreed. The suggestion concerns code from the already-merged #4337, not PR #4432’s move-start change in 45fbbdef5. Leaving it unresolved for maintainers is reasonable.
The security concern may still warrant a separate follow-up; its being out of scope for this PR does not establish whether it is valid.
| if !themesongs.Unchanged(claims.MediaPath, claims.ThemeSize, time.Unix(0, claims.ThemeModifiedUnixNano)) { | ||
| return nil, refuseSourceChanged | ||
| } |
There was a problem hiding this comment.
Transient theme stat failures permanently reject remux requests
A transient theme file stat failure makes themesongs.Unchanged trigger refuseSourceChanged, returning 400 instead of allowing a retry. Distinguish missing or changed files from other filesystem errors and return 503 for transient failures.
Prompt for LLM
File internal/nodecontrol/resolve.go, lines 355-357:
Transient theme stat failures permanently reject remux requests
A transient stat failure on a theme file is classified as a permanent source change, so the node returns 400 instead of retrying the playback request. Distinguish missing or changed files from other filesystem errors and return 503 for transient failures.
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.
Out of scope for this PR. This line comes from #4337 (already merged into main) and shows here only because this PR is stacked on #4363, which still sits on #4337's original commits. This PR's own change is 45fbbde (the move-start rule in handleStart). I'm leaving it unresolved for the maintainers to decide on.
| http.Error(w, http.StatusText(status), status) | ||
| return | ||
| } | ||
| if _, err := claims.Check(r.Context()); err != nil { |
There was a problem hiding this comment.
Source opens check the receiving replica's filesystem
claims.Check checks the receiving replica's filesystem, which may contain a different file or produce a terminal response when the grant owner is unavailable. Route the open request to the admitting owner incarnation, preserving the grant and returning a retryable failure if that owner is unavailable or restarted.
Also found in:
internal/nodecontrol/sources_test.go:231-231internal/nodesource/grant.go:148-148internal/nodesource/source.go:363-363internal/nodesource/grant.go:80-80internal/nodecontrol/sources.go:81-81
Kody rule violation: Keep Go worker sources bound to their owner and file revision
Prompt for LLM
File internal/nodecontrol/sources.go, line 69:
Source opens check the receiving replica's filesystem
Route the open request to the grant's admitting owner incarnation before checking the source. This handler currently checks the path on whichever API server receives the request, so another replica can interpret the same path as a different file or return a terminal response for an unavailable owner. Preserve the grant and return a retryable failure if that owner is unavailable or has restarted.
**Also found in:**
- `internal/nodecontrol/sources_test.go:231-231`
- `internal/nodesource/grant.go:148-148`
- `internal/nodesource/source.go:363-363`
- `internal/nodesource/grant.go:80-80`
- `internal/nodecontrol/sources.go:81-81`
Kody rule violation: [Keep Go worker sources bound to their owner and file revision](https://kodus.siloserver.org/settings/code-review/1247142351/kody-rules/8623ef2e-b7a2-4301-91b3-59e4cd4ba3c5?teamId=ba9922fc-c0ea-4cf8-87bb-9d4f42ffc73e)
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.
Out of scope for this PR. This line comes from #4337 (already merged into main) and shows here only because this PR is stacked on #4363, which still sits on #4337's original commits. This PR's own change is 45fbbde (the move-start rule in handleStart). I'm leaving it unresolved for the maintainers to decide on.
There was a problem hiding this comment.
Understood. The source-open finding appears to come from #4337 rather than this PR’s own commit, so I’ll leave the suggestion unresolved for the maintainers to decide on. It may be worth tracking separately if they confirm it remains an issue.
| if grant, err = s.regrant(ctx, node.ID, file, grant); err != nil { | ||
| return nil, nodeLabel(node), err |
There was a problem hiding this comment.
A transient regrant failure bypasses local subtitle sampling fallback
A transient s.regrant failure after the first window fails subtitle synchronization in prefer_transcode_nodes mode, unlike an initial grant failure. Fall back locally for the remaining windows while still rejecting an actual source revision change.
Prompt for LLM
File internal/subtitles/subsync/sampler.go, lines 134-135:
A transient regrant failure bypasses local subtitle sampling fallback
A transient source-grant failure after the first window immediately fails subtitle synchronization even in `prefer_transcode_nodes` mode, despite that mode falling back locally when the initial grant fails. Fall back for the remaining windows on transient regrant failures while still rejecting an actual source revision change.
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.
Out of scope for this PR. This line comes from #4337 (already merged into main) and shows here only because this PR is stacked on #4363, which still sits on #4337's original commits. This PR's own change is 45fbbde (the move-start rule in handleStart). I'm leaving it unresolved for the maintainers to decide on.
There was a problem hiding this comment.
Agreed. The suggestion concerns code from #4337, not this PR’s move-start change, so it’s reasonable to leave it unresolved for maintainers to decide whether to address separately.
| removeCtx, cancelRemove := context.WithTimeout(context.WithoutCancel(r.Context()), sessionTrackingOperationTimeout) | ||
| s.tracker.Remove(removeCtx, trackerSessionID) | ||
| cancelRemove() | ||
| s.tracker.Remove(r.Context(), trackerSessionID) |
There was a problem hiding this comment.
Stopped session cleanup depends on the request context
A canceled request can prevent s.tracker.Remove from releasing the session record after the job has stopped. Use a context detached from request cancellation with an explicit timeout.
Also found in:
internal/transcodenode/server.go:1119-1119
Kody rule violation: Detach mandatory cleanup from request cancellation and bound its lifetime
Prompt for LLM
File internal/transcodenode/server.go, line 2707:
Stopped session cleanup depends on the request context
Run tracker removal with a context detached from request cancellation and bounded by an explicit timeout. The job has already been stopped, so a canceled request must not prevent its session record from being released.
**Also found in:**
- `internal/transcodenode/server.go:1119-1119`
Kody rule violation: [Detach mandatory cleanup from request cancellation and bound its lifetime](https://kodus.siloserver.org/settings/code-review/1247142351/kody-rules/b3c20cf3-6a41-4161-9af6-2bef16b674e9?teamId=ba9922fc-c0ea-4cf8-87bb-9d4f42ffc73e)
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.
Out of scope for this PR. This line comes from #4337 (already merged into main) and shows here only because this PR is stacked on #4363, which still sits on #4337's original commits. This PR's own change is 45fbbde (the move-start rule in handleStart). I'm leaving it unresolved for the maintainers to decide on.
There was a problem hiding this comment.
Understood. The cleanup finding is outside PR #4432’s own change and appears in the stacked diff. I’ll leave it unresolved for the maintainers to assess; no changes have been made.
| slog.Warn("remove transcode session directory", "component", "transcodenode", "session", sessionID, "error", err) | ||
| } | ||
| if s.tracker != nil { | ||
| s.tracker.Remove(context.Background(), sessionID) |
There was a problem hiding this comment.
Detached session cleanup can block indefinitely
s.tracker.Remove can block indefinitely while holding the session lifecycle lock if the backing store is unavailable. Bound the detached context with a fixed timeout and cancel it afterward.
Kody rule violation: Cancel blocking lifecycle work before waiting and bound detached cleanup
Prompt for LLM
File internal/transcodenode/source_input.go, line 150:
Detached session cleanup can block indefinitely
Bound the detached tracker removal with a fixed timeout and cancel the context afterward. An unbounded removal can block indefinitely when the backing store is unavailable, while this callback holds the session lifecycle lock.
Kody rule violation: [Cancel blocking lifecycle work before waiting and bound detached cleanup](https://kodus.siloserver.org/settings/code-review/1247142351/kody-rules/6bbefdf5-b173-4ab8-aadd-04b9c38df65e?teamId=ba9922fc-c0ea-4cf8-87bb-9d4f42ffc73e)
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.
Out of scope for this PR. This line comes from #4337 (already merged into main) and shows here only because this PR is stacked on #4363, which still sits on #4337's original commits. This PR's own change is 45fbbde (the move-start rule in handleStart). I'm leaving it unresolved for the maintainers to decide on.
|
Thanks for digging into this. I'm closing it because the race in #4364 doesn't happen as described, and the 409 makes the real race worse. I tested it with two API servers, two transcode nodes, and the session's node stopped while both servers moved the transcode at once.
A remaining gap that predates this PR: with three or more nodes, two servers could each pick a different node. That needs its own issue once it's confirmed. 🤖 Claude Code (claude-opus-5-5) |
Depends on: #4363 (which builds on #4337). Merge order: #4337, #4363, then this. #4337 has already merged. Until #4363 merges, this diff also shows #4363's commits and the feature-branch commits under it. This pull request's own commit is
45fbbdef5(6 files, +91/−4).Problem
Closes #4364
Related issue: #4363
Validation tasks: none
Other clients: N/A (no client-visible change)
When two API servers moved the same transcode to the same node at about the same time, that node could end up running nothing for it. The first move's start succeeded and it committed, so the stored recipe named the node. The second move's start then reached the node, and
handleStartclosed the first move's job and published its own under the same transport id. The second move's commit failed, because the session no longer named the dead node, so it released the start it sent. With #4363 that release names the second start, which is now the job on the node, so the node ended it. The viewer stalled until the next segment request rebuilt the job from the recipe. This affects deployments with several API servers and remote transcode nodes.With this change the second move's start leaves the first move's job running.
Approach
A start that carries a
start_id(only a move sends one) answers 409 instead of replacing a job that a start with a differentstart_idpublished. The check runs inhandleStartunder the transport's lifecycle lock, before anything is spawned. The losing move treats the 409 like any refused candidate: it rolls back with its ownstart_id, which #4363 already turns into a 404 that leaves the other job alone, and it tries the next node. Its commit would have failed anyway.A start without
start_idstill replaces any job, so a fresh start, an audio switch and a Jellyfin-compatible start behave as before. So does a move onto a job that a rebuild published. A node that predatesstart_idignores it and replaces as before. A core that predates it sends none.I chose a refusing start over a release that names its job, because #4363 already fences the release. The remaining hole was the start replacing the winner's job.
docs/transcode-node-api.md,docs/architecture/worker-http-protocol.md, the start route's protocol description and the regeneratedcontracts/api/v2/openapi.jsondescribe the 409.Validation
d466691c3) and passes with the fix.go testforinternal/transcodenodeandinternal/playback/...: pass.go test ./internal/api/handlers/: six DB tests fail before and after this change, because the local test database is missing newer columns (client_session_id,timeline_duration_seconds). No handler code changed here.make lint-changedagainst fix(nodes): end only the job a late node release was sent for #4363's head: 0 issues.make apiv2-openapiregenerated the contract, andmake verify-apiv2-openapireports it current.Evidence
Nothing visible changes. The node test, before the fix (on #4363's head
d466691c3):After the fix (
45fbbdef5):Package runs after the fix:
Risks
start_id, so this rule does not cover them.start_id.Checklist
AI Disclosure
🤖 Generated with Claude Code
Note
Keep a move's job when another move starts the transport there, and add per-node keys and source grants
nodeauth.Keyring, a credential registry with encrypted keys instream_nodes.node_key_ciphertext(migration), admin key issuance (POST /admin/nodes/{id}/key), and signing throughout playback, proxy, downloads, trickplay, chapterthumbs, and subsyncsource_grantand open inputs through the core'ssources/openroute instead of an approved input path, with mount-mismatch 409s and renewalVerifyFromNode), config/report/log/resolve/source/revoke endpoints, a standaloneMODE=transcoderunner driven bySILO_CORE_URLandSILO_NODE_KEY, and stops/releases that distinguish fenced stops from superseded releasesTranscodePool.HasKey); remote relays return 502/410 instead of falling back to the shared secret; recipe deletion on stop now keeps cards issued for another route (DeleteUnlessIssuedElsewhere);NODE_URLis no longer required in transcode modeMacroscope summarized 45fbbde.