Skip to content

fix(playback): end relays when a node stops sending body data - #3269

Merged
Quick104 merged 2 commits into
Silo-Server:mainfrom
darthShadow:fix/relay-body-liveness
Oct 30, 2026
Merged

Quick104 merged 2 commits into
Silo-Server:mainfrom
darthShadow:fix/relay-body-liveness

Conversation

@darthShadow

@darthShadow darthShadow commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Related issue: #1176
Validation tasks: changes #1177 C3

When a transcode node hangs after it has started a response, playback freezes
and nothing recovers it. The node's process is stopped or deadlocked, but its
kernel keeps the connection open, so the server keeps waiting for the next
segment bytes. The viewer sees a frozen picture until their client gives up,
and the server logs nothing that names the node.

#2579 handles a node that hangs before it sends response headers. This change
covers the same failure after the headers: the server now notices the stalled
body read, aborts that response, and logs which node stopped answering. The
client's next request then takes the existing recovery path and moves the
transcode to a healthy node.

Approach

transcodeproxy.DoNode already probes a node's health endpoint while a call
waits for headers. It now does the same while a body read is waiting. A node
that misses its probes is treated as hung: the read fails with
nodepool.ErrNodeNotAnswering, and the relay aborts the partial response.
It aborts on any body copy error while the viewer's request is live, so a
chunked response such as a progressive remux breaks instead of ending cleanly
and looking complete. A
node that is slow but still answers its probes keeps streaming, so there is
still no fixed body deadline. No probe runs between reads, so a slow viewer
does not cause probes. Body data counts as an answer, the same way headers do,
so a node that was marked hung but is sending again is cleared.

The two native relays (the API playback relay and the proxy relay) log a
warning with the node and playback session when this happens. A cancelled
viewer request logs nothing. The Jellyfin-compatible manifest fetch and segment
relay switch from telemetry.DoTrustedNode to transcodeproxy.DoNode, so
Jellyfin clients get the same detection and warning. Moving a Jellyfin
playback to another node is still #2297. The Jellyfin-compatible
transcode start still uses telemetry.DoTrustedNode, and
docs/architecture/node-failure-detection.md lists it as a known gap. Moving
a stream to another node while it is mid-response is out of scope; recovery
starts with the client's retry.

No API or wire format changes. Recovery depends on the client asking again.
From reading the client code (not tested on devices): Android's player retries
a short response in place for up to 90 s, then reopens and replans. On Apple
the request goes through the engine's local relay, and AVPlayer gets either a
502 or a short body. AVPlayer's retry is not under app control, but a failed
item leads the app to replan away from the failed route.

Validation

  • go vet and make test-go on Linux: pass.
  • -race on transcodeproxy, jellycompat, proxy, and api/handlers: pass.
  • make lint-changed: 0 issues. make verify-local-paths: pass.
  • The hung-node relay test fails on the old code (no response within 45 s)
    and passes with the fix (about 8 s). The Jellyfin segment relay test and the
    body-watch unit tests also fail on the old code and pass with the fix.
  • Web checks and contract verify-* targets: not run. There are no web or
    contract changes.
  • Not tested on a real deployment with a stopped node.

Evidence

Evidence: none captured. The change affects only a hung-node failure path. The
hung-node relay test covers it: the stream froze for the full 45 s before the
fix and ends after about 8 s with it.

Risks

Each body read on a transcode node now starts a short timer. A local benchmark
put the cost at about 0.23 microseconds per read. While a node is remembered as
hung, the first read on it probes at once. One missed probe is then enough to
end the read, as it already was for header waits.

Checklist

  • I read and can explain the complete diff.
  • This pull request addresses one concern.
  • Each test this pull request adds meets "Decide what to test" in CONTRIBUTING.md.
  • The Evidence section shows every change a user can see, or says there is none.

AI Disclosure

  • Harness: Claude Code (in T3 Code); Codex CLI
  • Tool(s): Claude Code subagents; codex exec
  • Model(s): claude-opus-5-5, claude-sonnet-5-5, gpt-6.1-sol
  • Involvement: AI-assisted
  • Adversarial review: Two independent reviewers (claude-opus-5-5 and gpt-6.1-sol) and one verifier (claude-sonnet-5-5) read the full diff against the requirements. They found no production defect. Three items changed as a result: a test that passed on the old code was reworked to fail on it; body data now clears a node's hung mark, so fast reads on a recovered node stop starting probes; and the docs now name the Jellyfin-compatible transcode start as a remaining gap.

Note

End relays when a transcode node stops sending body data

  • Extends DoNode's liveness watch to cover each pending body read, not just the response-header wait. A stalled read is canceled with an error wrapping ErrNodeNotAnswering after missed probes, and body data clears the remembered-hung mark (liveness.go)
  • On a body-copy error while the viewer request is still active, the API relay (PlaybackHandler.relayToTranscodeNode), proxy relay (Server.proxyToTranscodeNode), and Jellyfin-compatible segment relay (PlaybackHandler.proxyRemoteCompatSegment) now panic with http.ErrAbortHandler instead of ending the response as a short body
  • Remote manifest requests now use transcodeproxy.DoNode so header waits and body reads are both watched
  • Updates the node-failure-detection and restart-resilient-playback architecture docs to match the new watch coverage
  • Behavioral Change: a failed body copy on an active viewer request aborts the HTTP response; a partial-body retry moves the transcode to another node. ErrNodeNotAnswering body failures also log a warning with the node and session ID

Macroscope summarized b33a144.

The liveness watch in `transcodeproxy.DoNode` ended when response
headers arrived. A node that hung partway through a segment body left
the relay, and the viewer, waiting until the client gave up.

The watch now also covers each pending body read. A read with no data
after the grace period probes the node's health endpoint, and two
missed probes end it with `nodepool.ErrNodeNotAnswering`. No watch runs
between reads, so a slow viewer does not trigger probes. Body data
clears a remembered hung node, as headers already did.

The Jellyfin-compatible manifest and segment relays now use `DoNode`,
so they get the same watch. The native, Jellyfin-compatible, and proxy
relays log the node and playback session when a body read fails this
way. The partial response cannot move to another node. On the native
API, the client's next request finds the remembered hung node and moves
the transcode to a healthy one.

Signed-off-by: Anagh Kumar Baranwal <[email protected]>
@silo-triage silo-triage Bot added the size/XL 500–999 added + deleted lines (all files); change volume, not priority. label Oct 30, 2026
@silo-kody

silo-kody Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

Silo Kody — review complete

Review finished. Check the inline comments for findings and verify each suggestion against the code and tests.

Reviewing changes in Silo
  • Include the related issue, expected behavior, and validation steps in the PR description.
  • For API changes, describe the effect on Apple and Android clients and Jellyfin compatibility.
  • For plugin changes, identify the affected SDK contract, plugin, and catalog entry.
  • Follow this repository's AGENTS.md and CONTRIBUTING.md.
  • Request another review with @kody start-review in a PR comment.
  • React with 👍 or 👎 to give feedback on individual suggestions.
Review settings
Review Options

The following review options are enabled or disabled:

Options Enabled
Bug ✅
Performance ✅
Security ✅
Business Logic ❌

@macroscopeapp

macroscopeapp Bot commented Oct 30, 2026

Copy link
Copy Markdown

Visible playback behavior lacks evidence in internal/api/handlers/playback.go and internal/proxy/server.go: stalled native relay bodies now end instead of remaining frozen. Add a before-and-after recording of the same playback failure that shows the timing and client-visible result, and name the surface and commit.

Visible Jellyfin-compatible segment behavior lacks evidence in internal/jellycompat/streams.go: a stalled segment body now ends as a partial response. Add a before-and-after recording of the same segment failure, with the surface and commit identified.

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

Posted via Macroscope — Visible change evidence

@coderabbitai

coderabbitai Bot commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Caution

Review failed

The pull request is closed.

No actionable comments were generated in the recent review.

Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 89a92cec-e080-44b7-bbe1-8a00d9fa97af
Commits

Reviewing files that changed from the base of the PR and between 0225a05 and 48980c4.

Files selected for processing: 9
  • docs/architecture/node-failure-detection.md
  • docs/architecture/restart-resilient-playback.md
  • internal/api/handlers/playback.go
  • internal/api/handlers/playback_hung_node_test.go
  • internal/jellycompat/remote_relay_transport_test.go
  • internal/jellycompat/streams.go
  • internal/proxy/server.go
  • internal/transcodeproxy/liveness.go
  • internal/transcodeproxy/liveness_test.go

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

Walkthrough

The liveness watch now covers pending response-body reads as well as waits for headers. Jellyfin-compatible relays use the watch. Active relay responses abort when body copying fails, and playback tests cover partial responses and retry behavior.

Changes: Playback node liveness

Layer / File(s) Summary
Watch pending body reads
internal/transcodeproxy/liveness.go, internal/transcodeproxy/liveness_test.go
DoNode wraps response bodies and watches each pending read. A hung read returns an error classified as ErrNodeNotAnswering. Body data or a successful health probe clears remembered hung state. Tests cover stalled reads, slow live responses, probe timing, and recovery.
Apply liveness monitoring and abort incomplete relays
internal/jellycompat/streams.go, internal/jellycompat/remote_relay_transport_test.go, internal/api/handlers/playback.go, internal/api/handlers/playback_hung_node_test.go, internal/api/handlers/playback_proxy_test.go, internal/proxy/server.go, internal/proxy/segment_completion_test.go
Jellyfin-compatible manifest and segment relays use DoNode. Native, proxy, and Jellyfin-compatible relays abort active responses when body copying fails. Playback tests cover header and body freezes, partial responses, retry, and failover.
Document probe and playback behavior
docs/architecture/node-failure-detection.md, docs/architecture/restart-resilient-playback.md
The architecture documentation describes probe timing, body-read monitoring, relay failure behavior, client retry, and calls that remain unwatched.

Priority: Not assessed

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

Change: Bug fix

Sequence Diagram(s)

sequenceDiagram
  participant PlaybackClient
  participant PlaybackRelay
  participant transcodeproxy.DoNode
  participant TranscodeNode
  participant watchedBody
  PlaybackClient->>PlaybackRelay: Request playback data
  PlaybackRelay->>transcodeproxy.DoNode: Send node request
  transcodeproxy.DoNode->>TranscodeNode: Forward request
  TranscodeNode-->>transcodeproxy.DoNode: Return response headers and body
  transcodeproxy.DoNode-->>PlaybackRelay: Return watched response
  PlaybackRelay->>watchedBody: Copy response body
  watchedBody-->>PlaybackRelay: Return body data or read error
  PlaybackRelay-->>PlaybackClient: Send data or abort incomplete response
Loading

Possibly related issues

  • Silo-Server/silo-server#1176 — The change detects a stopped transcode node during a body read and ends the stalled relay, allowing a later client request to retry. Failover itself is not shown as complete.

Possibly related PRs

Suggested reviewers: rhainland, quick104

Merge Risk: Minimal · up to b33a1

No merge-blocking risk is established by the supplied evidence.

Security architecture risk: Low · up to b33a1

The change improves containment of stalled playback without changing the inspected access checks or who selects playback destinations. Recovery still depends on another client request, and compatibility-client migration remains outside this change. Deployment-level behavior has not been validated.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — Liveness effects are shared across requests to the same normalized node within a serving process, rather than isolated to one playback session. A remembered failure accelerates probing for other sessions on that node, but does not itself grant destination-selection or session-access authority.

Trust Boundaries and Controls

  • observed — The inspected native relay remains downstream of session ownership and API-egress checks. It signs the selected node request and forwards a reconstruction token only after verification and a matching session ID. The changed copy-error branch does not select a replacement destination.
  • observed — Jellyfin-compatible callers require an authenticated context and a playback session bound to that compatibility token. They derive remote destinations from the session recipe and sign requests. The dedicated proxy likewise uses the node named in its claims and signs the outbound request; the PR retains these controls in the inspected relay blocks.
  • observed — Health probes use a separate connection pool, refuse redirects, and target the selected node's health endpoint without copying playback credentials. An HTTP answer establishes process responsiveness, not authorization or application health.

Resilience and Maintainability Implications

  • observed — Finishing an operation signals its watcher and stops its grace timer; closing the wrapped body cancels the request context. Shared probes have their own bounded lifetime, so cancellation by one viewer does not cancel the probe used by other requests.
  • observed — A committed response is not moved between executors. The documented recovery contract requires a subsequent native API request to trigger rehome; proxy playback requires client replanning, while Jellyfin-compatible playback still requires retry or replanning rather than gaining automatic migration here.
Pre-merge checks: Passed 5
Check name Status Explanation
Title check Passed The title clearly and concisely describes the main change: ending playback relays when a node stops sending body data.
Description check Passed The description directly explains the playback freeze, the body-read liveness checks, affected relays, recovery behavior, validation, and known limitations.
Docstring Coverage Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 4 functions across 7 files. (2 skipped: 2 unsupported.)

Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

@silo-triage silo-triage Bot added bug Something isn't working evidence-required Needs before-and-after evidence before the Evidence check passes go Pull requests that update go code impact: playback Can't play, stalls, or wrong media priority: P1 Core-path bug; painful workaround — next after P0 labels Oct 30, 2026
@silo-triage

silo-triage Bot commented Oct 30, 2026

Copy link
Copy Markdown

Please add before-and-after evidence of playback when a transcode node stops sending body data after headers: show the previous stall and the new response termination/client retry, naming the client surface and builds. The Evidence section says nothing was captured; the reported relay-test timings do not show the user-visible playback behavior. Include the Jellyfin relay behavior or state its remaining recovery limitation alongside the capture.

@darthShadow

Copy link
Copy Markdown
Contributor Author

No playback capture for this one. The change only affects a node that hangs mid-response, and reproducing that on a real deployment means freezing a transcode node process during playback. The behavior is covered by tests instead:

  • Native relay: TestRelayMovesTranscodeOffHungNode/body stops the node after it sends headers and part of the body. Before the fix, the client got nothing and timed out after 45 s. With the fix, the response ends after about 8 s and the retry moves the transcode to a healthy node.
  • Jellyfin-compatible relay: TestRemoteCompatSegmentEndsHungBodyBeforeViewerCancellation shows the segment response now ends instead of hanging until the viewer gives up. Moving a Jellyfin playback to another node is still [bug] Jellyfin-protocol playback never recovers when its transcode node dies #2297, so a Jellyfin client gets an ended segment, not a recovered stream.

The client sees a frozen stream end in seconds rather than staying frozen. What happens next depends on the client's retry, which this PR does not change.

Comment thread internal/proxy/server.go Resolved
When the body copy from a transcode node failed, the relay handler
returned normally. net/http then closed the chunked response cleanly,
so a player could take a stalled progressive remux as the end of the
movie.

The native API, proxy, and Jellyfin-compatible relays now abort the
response with panic(http.ErrAbortHandler) when io.Copy fails and the
viewer's request is still live. This covers the hung-body error
nodepool.ErrNodeNotAnswering and any other copy failure. The client
sees a broken connection, not a short body that looks complete. A
canceled viewer request still returns quietly.

The hung-node test now serves a chunked body larger than net/http's
4 KiB response buffer and requires a client read error. The direct
relay tests expect the abort. The node failure and restart-resilient
playback docs describe the abort.

Signed-off-by: Anagh Kumar Baranwal <[email protected]>
@silo-kody

silo-kody Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

Silo Kody — review complete

Review finished. Check the inline comments for findings and verify each suggestion against the code and tests.

Reviewing changes in Silo
  • Include the related issue, expected behavior, and validation steps in the PR description.
  • For API changes, describe the effect on Apple and Android clients and Jellyfin compatibility.
  • For plugin changes, identify the affected SDK contract, plugin, and catalog entry.
  • Follow this repository's AGENTS.md and CONTRIBUTING.md.
  • Request another review with @kody start-review in a PR comment.
  • React with 👍 or 👎 to give feedback on individual suggestions.
Review settings
Review Options

The following review options are enabled or disabled:

Options Enabled
Bug ✅
Performance ✅
Security ✅
Business Logic ❌

@macroscopeapp

macroscopeapp Bot commented Oct 30, 2026

Copy link
Copy Markdown

The new relay-abort handling changes the visible result from a clean short-body end to an interrupted transfer, but the Evidence section still contains only test timing. For the native API/proxy playback and Jellyfin segment surfaces, add before-and-after recordings of the same stalled-body playback showing this distinction and name each surface and capture commit. The earlier reply explains why real-device captures were unavailable; this request is for the additional client-visible behavior introduced by the abort change.

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

Posted via Macroscope — Visible change evidence

@darthShadow

Copy link
Copy Markdown
Contributor Author

No recording for the abort change either. I have no deployment with a separate transcode node, so I cannot stall a node mid-body under a real player on any of the three surfaces.

The hung-node relay test shows the client-visible change. Its body phase serves a chunked partial response from a node that then stops answering. Before b33a144 the client read status 200 and the partial body with a clean end, so it would accept the body as complete. With b33a144 the client gets the same partial body followed by a read error. The direct relay tests for the proxy and Jellyfin segment paths check for the same abort.

@Quick104

Copy link
Copy Markdown
Contributor

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

Review summary

Reviewed head: b33a144

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

Findings

  • Clean end of a chunked response after a hung body read (high; raised by Kody, confirmed in the thread). The proxy relays /remux/ streams, which are chunked. On 48980c4, a hung node's stream ended as a clean end of stream. b33a144 fixed this before I pushed my own version: all three relays now panic with http.ErrAbortHandler on any body copy error while the viewer is still connected. chi's Recoverer re-panics that value, and the subtitle extract paths already end failed responses the same way.

No other defects turned up. I traced watchedBody.Read, beginNodeWatch, and watchNode through these cases: the race between a node answering and a missed probe, a node already remembered as hung, the grace timer stopping before it fires, and Close cancelling the call. The per-read timer does not run between reads, so a slow viewer causes no probes.

Tests that fail on the base

  • On main (0225a05): TestDoNodeFailsHungBodyRead, TestDoNodeWaitsOnSlowLiveBody, TestDoNodeDoesNotProbeBetweenBodyReads, TestRemoteCompatSegmentEndsHungBodyBeforeViewerCancellation, and TestRelayMovesTranscodeOffHungNode/body (the stream froze for the full 45 s).
  • On 48980c4: the abort assertions in the hung-node relay test, the Jellyfin segment test, and both …DoesNotAcknowledgeFailedDownstreamWrite tests.
  • On b33a144: -race passes in transcodeproxy, jellycompat, proxy, and api/handlers, and make lint-changed reports 0 issues.

Left for maintainers

  • The Evidence check fails. The author says capturing a frozen node during live playback isn't practical, and the tests cover the behavior. A viewer does see this change, though (a frozen stream now fails within seconds), so whether test evidence is enough here is a maintainer call.
  • Not exercised on a real deployment with a stopped node, and the client retry behavior described in the PR body comes from reading the client code, not from devices.

Validated features: #1177 C3 (remove an active worker during playback) has not been run yet, so this PR can't regress a passed case. It is the case to walk once this merges.

User manual: the transcode nodes guide doesn't describe hung-node behavior. Silo-Server/siloserver.org#162, which is open, already asks the guide to say what happens when a node goes away. It can cover this: a stream on a node that stops answering now fails within seconds instead of freezing, and native clients recover on retry. No new docs issue is needed.

Apple/Android parity: server-only. No API or wire change. Both clients already treat a failed transfer as retryable.

Why these scores: Fit 9: Silo treats a node dying mid-stream as a normal event, and this closes the gap #2579 left after headers, inside the existing liveness watch, with no new setting. Readiness 8: tests that fail on the base prove the behavior, and the code holds up under review. The open evidence decision keeps it at conditional.

@Quick104
Quick104 merged commit aca67ef into Silo-Server:main Oct 30, 2026
27 of 29 checks passed
@darthShadow
darthShadow deleted the fix/relay-body-liveness branch October 30, 2026 14:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working evidence-required Needs before-and-after evidence before the Evidence check passes go Pull requests that update go code impact: playback Can't play, stalls, or wrong media priority: P1 Core-path bug; painful workaround — next after P0 size/XL 500–999 added + deleted lines (all files); change volume, not priority.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants