Repository navigation
fix(playback): avoid restarting active transcodes - #52
Conversation
📝 WalkthroughWalkthroughThis PR adds a ChangesTranscode segment recovery restart-on-timeout flag
🎯 3 (Moderate) | ⏱️ ~20 minutes
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@internal/api/handlers/playback.go`:
- Line 2301: Other callers of SegmentRecoveryDecision are restarting
unconditionally on playback.ErrSegmentNotFound; update the ErrSegmentNotFound
handling in internal/transcodenode/server.go and internal/jellycompat/streams.go
so that calls to RestartSeekTarget(...) and session.Restart(...) /
transcodeSession.Restart(...) only execute when decision.RestartOnTimeout is
true (i.e., add the same errors.Is(err, playback.ErrSegmentNotFound) &&
decision.RestartOnTimeout gating used in playback.go), leaving all other logic
unchanged.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 7b32572a-2ad0-4ee2-a223-eb972907e681
📒 Files selected for processing (3)
internal/api/handlers/playback.gointernal/playback/transcode.gointernal/playback/transcode_manifest_test.go
| // timeline position or return 404 for copy-mode segments outside the | ||
| // current manifest window. | ||
| if err != nil && errors.Is(err, playback.ErrSegmentNotFound) { | ||
| if err != nil && errors.Is(err, playback.ErrSegmentNotFound) && decision.RestartOnTimeout { |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "Locate SegmentRecoveryDecision call sites and restart logic context:"
rg -n --type=go -C6 'SegmentRecoveryDecision\(|RestartSeekTarget\('
echo
echo "Inspect ErrSegmentNotFound handling blocks for RestartOnTimeout gating:"
rg -n --type=go -C8 'ErrSegmentNotFound'Repository: Silo-Server/silo-server
Length of output: 41065
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "== Search RestartOnTimeout usage =="
rg -n --type=go 'RestartOnTimeout' internal/transcodenode/server.go internal/jellycompat/streams.go internal/api/handlers/playback.go
echo
echo "== Inspect transcodenode/server.go ErrSegmentNotFound restart block =="
# Show a focused window around the restart execution path
sed -n '300,430p' internal/transcodenode/server.go
echo
echo "== Inspect jellycompat/streams.go ErrSegmentNotFound restart block =="
sed -n '250,420p' internal/jellycompat/streams.goRepository: Silo-Server/silo-server
Length of output: 12140
Propagate RestartOnTimeout gating to all ErrSegmentNotFound segment-recovery restart paths.
internal/api/handlers/playback.go is now gated correctly:
if err != nil && errors.Is(err, playback.ErrSegmentNotFound) && decision.RestartOnTimeout {But the other SegmentRecoveryDecision consumers still restart unconditionally on ErrSegmentNotFound:
internal/transcodenode/server.go:RestartSeekTarget(...)/session.Restart(...)inside theErrSegmentNotFoundblock do not checkdecision.RestartOnTimeout.internal/jellycompat/streams.go:RestartSeekTarget(...)/transcodeSession.Restart(...)inside theErrSegmentNotFoundblock do not checkdecision.RestartOnTimeout.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@internal/api/handlers/playback.go` at line 2301, Other callers of
SegmentRecoveryDecision are restarting unconditionally on
playback.ErrSegmentNotFound; update the ErrSegmentNotFound handling in
internal/transcodenode/server.go and internal/jellycompat/streams.go so that
calls to RestartSeekTarget(...) and session.Restart(...) /
transcodeSession.Restart(...) only execute when decision.RestartOnTimeout is
true (i.e., add the same errors.Is(err, playback.ErrSegmentNotFound) &&
decision.RestartOnTimeout gating used in playback.go), leaving all other logic
unchanged.
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (2)
internal/transcodenode/server.go (1)
338-399:⚠️ Potential issue | 🟠 Major | ⚡ Quick winAdd
restart_on_timeoutto structured logs.The PR objectives state that
restart_on_timeoutshould be added to structured logs in missing-segment/wait and seek-restart paths. This field is missing from all four log statements in the segment recovery flow:
- Line 338: "transcode segment missing"
- Line 351: "transcode segment wait"
- Line 365: "transcode segment wait timeout"
- Line 387: "transcode node seek restart"
Including this field in logs is critical for understanding recovery decisions and debugging why transcodes restart or wait.
📊 Proposed fix to add restart_on_timeout to logs
slog.Info("transcode segment missing", "segment", name, "requested_segment", segNum, "produced_head", decision.Progress.ProducedHead, "last_requested_segment", decision.Progress.LastRequestedSegment, "start_segment_number", decision.Progress.StartSegmentNumber, "last_produced_age_ms", lastProducedAgeMS, "wait_timeout_ms", decision.WaitTimeout.Milliseconds(), "reason", decision.Reason, + "restart_on_timeout", decision.RestartOnTimeout, "session", sessionID, "playback_session_id", sessionID, ) if decision.Wait { slog.Info("transcode segment wait", "segment", name, "requested_segment", segNum, "produced_head", decision.Progress.ProducedHead, "last_requested_segment", decision.Progress.LastRequestedSegment, "start_segment_number", decision.Progress.StartSegmentNumber, "last_produced_age_ms", lastProducedAgeMS, "wait_timeout_ms", decision.WaitTimeout.Milliseconds(), "reason", decision.Reason, + "restart_on_timeout", decision.RestartOnTimeout, "session", sessionID, "playback_session_id", sessionID, ) segPath, err = session.WaitForSegment(name, decision.WaitTimeout) if err != nil && err == playback.ErrSegmentNotFound { slog.Info("transcode segment wait timeout", "segment", name, "requested_segment", segNum, "produced_head", decision.Progress.ProducedHead, "last_requested_segment", decision.Progress.LastRequestedSegment, "start_segment_number", decision.Progress.StartSegmentNumber, "last_produced_age_ms", lastProducedAgeMS, "wait_timeout_ms", decision.WaitTimeout.Milliseconds(), "reason", decision.Reason, + "restart_on_timeout", decision.RestartOnTimeout, "session", sessionID, "playback_session_id", sessionID, ) } } if err != nil && err == playback.ErrSegmentNotFound && decision.RestartOnTimeout { seekSeconds, ok, seekErr := session.RestartSeekTarget(segNum) if seekErr != nil && !errors.Is(seekErr, playback.ErrManifestNotReady) { slog.Error("resolve transcode node seek target", "error", seekErr, "segment", name, "session", sessionID, "playback_session_id", sessionID) } if ok { slog.Info("transcode node seek restart", "segment", name, "requested_segment", segNum, "produced_head", decision.Progress.ProducedHead, "last_requested_segment", decision.Progress.LastRequestedSegment, "start_segment_number", decision.Progress.StartSegmentNumber, "last_produced_age_ms", lastProducedAgeMS, "wait_timeout_ms", decision.WaitTimeout.Milliseconds(), "reason", decision.Reason, + "restart_on_timeout", decision.RestartOnTimeout, "seek_seconds", seekSeconds, "session", sessionID, "playback_session_id", sessionID, )🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@internal/transcodenode/server.go` around lines 338 - 399, The structured logs for the segment recovery flow are missing the restart_on_timeout field; update each slog.Info call for "transcode segment missing", "transcode segment wait", "transcode segment wait timeout" and "transcode node seek restart" to include "restart_on_timeout", decision.RestartOnTimeout so the logs record the RestartOnTimeout decision; locate the slog.Info invocations in the transcode branch around session.WaitForSegment, the ErrSegmentNotFound handling and the RestartSeekTarget handling and add the restart_on_timeout key with decision.RestartOnTimeout to each log call.internal/jellycompat/streams.go (1)
295-366:⚠️ Potential issue | 🟠 Major | ⚡ Quick winAdd
restart_on_timeoutto structured logs.The PR objectives state that
restart_on_timeoutshould be added to structured logs in missing-segment/wait and seek-restart paths. This field is missing from all four log statements in the segment recovery flow:
- Line 295: "transcode segment missing"
- Line 309: "transcode segment wait"
- Line 324: "transcode segment wait timeout"
- Line 353: "transcode seek restart"
Including this field in logs is critical for understanding recovery decisions and debugging why transcodes restart or wait.
📊 Proposed fix to add restart_on_timeout to logs
slog.Info("transcode segment missing", "segment", segmentFile, "requested_segment", segNum, "produced_head", decision.Progress.ProducedHead, "last_requested_segment", decision.Progress.LastRequestedSegment, "start_segment_number", decision.Progress.StartSegmentNumber, "last_produced_age_ms", lastProducedAgeMS, "wait_timeout_ms", decision.WaitTimeout.Milliseconds(), "reason", decision.Reason, + "restart_on_timeout", decision.RestartOnTimeout, "play_session", playSessionID, "session", playSession.UpstreamSessionID, "playback_session_id", playSession.UpstreamSessionID, ) if decision.Wait { slog.Info("transcode segment wait", "segment", segmentFile, "requested_segment", segNum, "produced_head", decision.Progress.ProducedHead, "last_requested_segment", decision.Progress.LastRequestedSegment, "start_segment_number", decision.Progress.StartSegmentNumber, "last_produced_age_ms", lastProducedAgeMS, "wait_timeout_ms", decision.WaitTimeout.Milliseconds(), "reason", decision.Reason, + "restart_on_timeout", decision.RestartOnTimeout, "play_session", playSessionID, "session", playSession.UpstreamSessionID, "playback_session_id", playSession.UpstreamSessionID, ) segmentPath, err = transcodeSession.WaitForSegment(segmentFile, decision.WaitTimeout) if err != nil && errors.Is(err, playback.ErrSegmentNotFound) { slog.Info("transcode segment wait timeout", "segment", segmentFile, "requested_segment", segNum, "produced_head", decision.Progress.ProducedHead, "last_requested_segment", decision.Progress.LastRequestedSegment, "start_segment_number", decision.Progress.StartSegmentNumber, "last_produced_age_ms", lastProducedAgeMS, "wait_timeout_ms", decision.WaitTimeout.Milliseconds(), "reason", decision.Reason, + "restart_on_timeout", decision.RestartOnTimeout, "play_session", playSessionID, "session", playSession.UpstreamSessionID, "playback_session_id", playSession.UpstreamSessionID, ) } } if err != nil && errors.Is(err, playback.ErrSegmentNotFound) && decision.RestartOnTimeout { seekSeconds, ok, seekErr := transcodeSession.RestartSeekTarget(segNum) if seekErr != nil && !errors.Is(seekErr, playback.ErrManifestNotReady) { slog.Error("resolve transcode seek target", "error", seekErr, "segment", segmentFile, "play_session", playSessionID, "session", playSession.UpstreamSessionID, "playback_session_id", playSession.UpstreamSessionID, ) } if ok { slog.Info("transcode seek restart", "segment", segmentFile, "requested_segment", segNum, "produced_head", decision.Progress.ProducedHead, "last_requested_segment", decision.Progress.LastRequestedSegment, "start_segment_number", decision.Progress.StartSegmentNumber, "last_produced_age_ms", lastProducedAgeMS, "wait_timeout_ms", decision.WaitTimeout.Milliseconds(), "reason", decision.Reason, + "restart_on_timeout", decision.RestartOnTimeout, "seek_seconds", seekSeconds, "play_session", playSessionID, "session", playSession.UpstreamSessionID, "playback_session_id", playSession.UpstreamSessionID, )🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@internal/jellycompat/streams.go` around lines 295 - 366, The structured logs for segment recovery are missing the restart_on_timeout field; update the four slog.* calls in the segment recovery flow ("transcode segment missing", "transcode segment wait", "transcode segment wait timeout", and "transcode seek restart") to include "restart_on_timeout" with the boolean value decision.RestartOnTimeout so the logs show whether restart-on-timeout was considered — locate these messages in the transcode/segment handling code around the decision variable and add the key/value "restart_on_timeout", decision.RestartOnTimeout to each slog.Info call (and slog.Info inside the wait-timeout branch) so all four log entries include that field.
🧹 Nitpick comments (1)
internal/transcodenode/server.go (1)
329-380: ⚡ Quick winPrefer
errors.Is()for error comparison.Lines 329, 364, and 380 use
err == playback.ErrSegmentNotFoundfor error comparison. In Go,errors.Is()is the preferred approach because it handles wrapped errors correctly. The jellycompat handler (internal/jellycompat/streams.go line 340) already useserrors.Is()consistently.♻️ Proposed refactor
segPath, err := session.GetSegment(name) - if err != nil && err == playback.ErrSegmentNotFound { + if err != nil && errors.Is(err, playback.ErrSegmentNotFound) { segNum, parseErr := playback.ParseSegmentNumber(name) if parseErr == nil { now := time.Now() decision := session.SegmentRecoveryDecision(segNum, now) lastProducedAgeMS := int64(-1) if !decision.Progress.LastProducedAt.IsZero() { lastProducedAgeMS = now.Sub(decision.Progress.LastProducedAt).Milliseconds() } slog.Info("transcode segment missing", "segment", name, "requested_segment", segNum, "produced_head", decision.Progress.ProducedHead, "last_requested_segment", decision.Progress.LastRequestedSegment, "start_segment_number", decision.Progress.StartSegmentNumber, "last_produced_age_ms", lastProducedAgeMS, "wait_timeout_ms", decision.WaitTimeout.Milliseconds(), "reason", decision.Reason, "session", sessionID, "playback_session_id", sessionID, ) if decision.Wait { slog.Info("transcode segment wait", "segment", name, "requested_segment", segNum, "produced_head", decision.Progress.ProducedHead, "last_requested_segment", decision.Progress.LastRequestedSegment, "start_segment_number", decision.Progress.StartSegmentNumber, "last_produced_age_ms", lastProducedAgeMS, "wait_timeout_ms", decision.WaitTimeout.Milliseconds(), "reason", decision.Reason, "session", sessionID, "playback_session_id", sessionID, ) segPath, err = session.WaitForSegment(name, decision.WaitTimeout) - if err != nil && err == playback.ErrSegmentNotFound { + if err != nil && errors.Is(err, playback.ErrSegmentNotFound) { slog.Info("transcode segment wait timeout", "segment", name, "requested_segment", segNum, "produced_head", decision.Progress.ProducedHead, "last_requested_segment", decision.Progress.LastRequestedSegment, "start_segment_number", decision.Progress.StartSegmentNumber, "last_produced_age_ms", lastProducedAgeMS, "wait_timeout_ms", decision.WaitTimeout.Milliseconds(), "reason", decision.Reason, "session", sessionID, "playback_session_id", sessionID, ) } } - if err != nil && err == playback.ErrSegmentNotFound && decision.RestartOnTimeout { + if err != nil && errors.Is(err, playback.ErrSegmentNotFound) && decision.RestartOnTimeout {🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@internal/transcodenode/server.go` around lines 329 - 380, The code compares errors using equality (err == playback.ErrSegmentNotFound) in the transcode segment handling (around calls to playback.ParseSegmentNumber, session.SegmentRecoveryDecision, session.WaitForSegment and the RestartOnTimeout branch); update those comparisons to use errors.Is(err, playback.ErrSegmentNotFound) so wrapped errors are detected, and add the "errors" import if missing; ensure every occurrence (the checks before logging, after WaitForSegment, and before the RestartOnTimeout branch) uses errors.Is and retains the existing nil checks and logic.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In `@internal/jellycompat/streams.go`:
- Around line 295-366: The structured logs for segment recovery are missing the
restart_on_timeout field; update the four slog.* calls in the segment recovery
flow ("transcode segment missing", "transcode segment wait", "transcode segment
wait timeout", and "transcode seek restart") to include "restart_on_timeout"
with the boolean value decision.RestartOnTimeout so the logs show whether
restart-on-timeout was considered — locate these messages in the
transcode/segment handling code around the decision variable and add the
key/value "restart_on_timeout", decision.RestartOnTimeout to each slog.Info call
(and slog.Info inside the wait-timeout branch) so all four log entries include
that field.
In `@internal/transcodenode/server.go`:
- Around line 338-399: The structured logs for the segment recovery flow are
missing the restart_on_timeout field; update each slog.Info call for "transcode
segment missing", "transcode segment wait", "transcode segment wait timeout" and
"transcode node seek restart" to include "restart_on_timeout",
decision.RestartOnTimeout so the logs record the RestartOnTimeout decision;
locate the slog.Info invocations in the transcode branch around
session.WaitForSegment, the ErrSegmentNotFound handling and the
RestartSeekTarget handling and add the restart_on_timeout key with
decision.RestartOnTimeout to each log call.
---
Nitpick comments:
In `@internal/transcodenode/server.go`:
- Around line 329-380: The code compares errors using equality (err ==
playback.ErrSegmentNotFound) in the transcode segment handling (around calls to
playback.ParseSegmentNumber, session.SegmentRecoveryDecision,
session.WaitForSegment and the RestartOnTimeout branch); update those
comparisons to use errors.Is(err, playback.ErrSegmentNotFound) so wrapped errors
are detected, and add the "errors" import if missing; ensure every occurrence
(the checks before logging, after WaitForSegment, and before the
RestartOnTimeout branch) uses errors.Is and retains the existing nil checks and
logic.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 363e6694-d1c6-4b2e-acfa-c8c1079e5060
📒 Files selected for processing (2)
internal/jellycompat/streams.gointernal/transcodenode/server.go
* fix(playback): avoid restarting active transcodes * fix(playback): propagate transcode restart gating --------- Co-authored-by: RXWatcher <[email protected]>
* fix(playback): avoid restarting active transcodes * fix(playback): propagate transcode restart gating --------- Co-authored-by: rxwatcher <[email protected]>
* fix(playback): avoid restarting active transcodes * fix(playback): propagate transcode restart gating --------- Co-authored-by: RXWatcher <[email protected]>
* fix(playback): avoid restarting active transcodes * fix(playback): propagate transcode restart gating --------- Co-authored-by: rxwatcher <[email protected]>
Summary
restart_on_timeoutin playback segment logs and cover the recovery decisions with testsContext
This is a playback resiliency improvement. It avoids amplifying transient startup/current-head segment delays by restarting ffmpeg while it is still actively producing output. It is not framed as the root-cause fix for the recent slow-playback incident; that was resolved by fixing the ns18 VLAN 400 jumbo path.
Test Plan
go test ./internal/playback ./internal/api/handlers -count=1Summary by CodeRabbit
Bug Fixes
Tests