Skip to content

fix(playback): stop transcode startup waits when the request ends - #1499

Merged
Quick104 merged 1 commit into
mainfrom
fix/transcode-startup-ctx
Sep 26, 2026
Merged

Quick104 merged 1 commit into
mainfrom
fix/transcode-startup-ctx

Conversation

@Quick104

@Quick104 Quick104 commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Related issue: N/A
Validation tasks: none (Hardware transcoding #1172 C2 and Distributed transcode nodes #1177 C3 are near this path but not yet run)

If a client disconnects while a local transcode is starting, the server keeps waiting up to 30s per attempt for the first HLS manifest, and meanwhile holds that playback session locked. This change stops the wait when the request ends.

prepareLocalTransportV3 holds LockSessionLifecycle for the whole manifest wait. With hw_accel=auto that can be up to three 30s attempts. Once the request is gone, its later steps fail and the transport is rolled back, so the wait only delays the client's retry on the same session. The non-auto path could also go on to its startup retry and set AvoidHWDevice to a GPU that had not failed. A transcode node had the same problem with the API server's start request: it kept starting a session the API had already given up on.

Approach

  • The manifest wait takes a context (WaitForManifestContext, WaitForGenerationManifestContext). The existing timeout-only methods behave as before.
  • In runTranscodeStartup, a fresh start waits with the request context. On cancellation it closes the attempt and returns without advancing or caching the hw_accel=auto pipeline, since a departed client says nothing about the device.
  • A reconstruct keeps waiting, because every segment request queued on it shares it, not just the one that triggered it.
  • The v3 handler returns before the tone-map or legacy retry when the request has ended.
  • FFmpeg still runs detached from the request once it has started. The only new behavior is that the start stops waiting when nobody will receive the result.
  • On a transcode node, an abandoned start logs at info instead of as a readiness failure. The API server already stops that remote transcode.

The idea comes from a public fork (kipsilabs#127), which went the other way and gave startup an overall budget. Jellycompat has the same timeout-only waits (internal/jellycompat/streams.go). This PR leaves them unchanged.

Validation

  • go test ./internal/playback/... ./internal/transcodenode/... ./internal/api/handlers/... passes.
  • New tests cover a fresh start that stops when its request is cancelled, for both a running and an exited process, without advancing or caching the pipeline. They also cover a reconstruct that outlives its triggering request, and the handler's non-auto path using a fake FFmpeg that never writes a manifest. On main the fresh-start test waits the full 60s timeout and fails.
  • No test covers the handler's early return before the retries.
  • make lint-changed: 0 issues.
  • A separate Claude Code review found no defects. Its two suggestions are applied: failures where FFmpeg never started keep their existing error mapping, and node log noise on disconnect is reduced.

Risks

  • A client that disconnects during startup no longer leaves a transport starting for it. A retry starts a new one without waiting for the old wait to finish.
  • A context with a deadline shorter than the startup timeout would now cut startup short. No current call site passes one.

Checklist

  • I read and can explain the complete diff.
  • This pull request addresses one concern.

AI Disclosure

  • Harness: T3 Code (Claude Code agent harness)
  • Tool(s): Claude Code, GitHub CLI
  • Model(s): claude-opus-5-5
  • Involvement: Fully AI-generated; maintainer review pending
  • Adversarial review: a separate Claude Code agent (claude-opus-5-5) reviewed the commit read-only. It checked the node and jellycompat callers, context deadlines including the server ReadTimeout, lock release on the new early return, and error classification. It found no defects. It suggested keeping the existing error for failures where FFmpeg never started and quieter node logging; both are applied.

🤖 Generated with Claude Code

Note

Stop transcode startup waits when the playback request ends

  • Adds context-aware WaitForManifestContext and WaitForGenerationManifestContext methods to playback.TranscodeSession; the shared waitForManifest polling now returns ctx.Err() when the context ends instead of waiting until the startup timeout (transcode.go)
  • Fresh transcode starts use the request context for readiness waits. If the request ends, runTranscodeStartup closes the session and returns a TranscodeStartupError without trying the software tone-map fallback or recording a cached result. Reconstruct starts use a non-canceling context so they outlive the triggering request (transcode_startup.go)
  • The playback handler checks readiness with the request context and releases the session lifecycle lock on readiness failure (playback_v3.go)
  • The transcode-node start handler no longer writes an HTTP 500 readiness failure for a start abandoned after the request ended; it logs and returns (server.go)
  • Risk: existing WaitForManifest and WaitForGenerationManifest callers now run with a background context, so their behavior is unchanged, but any caller that passes a context to the new variants must handle ctx.Err() returns
📊 Macroscope summarized fe284d2. 4 files reviewed, 1 issue evaluated, 0 issues filtered, 1 comment posted

🗂️ Filtered Issues

Fresh local transcode starts waited up to ManifestStartupTimeout (30s)
per attempt for the first manifest even after the requesting client
disconnected. The caller holds the session lifecycle lock for that
whole wait and discards the transport once its request is gone, so
the wait only blocked the client's retry on the same session. The
non-auto path also went on to its startup retry, steering it away
from a device that had not failed.

Fresh starts now wait with the request context: on cancellation the
attempt is closed without advancing or caching the hw_accel=auto
pipeline, and the v3 handler returns before any retry. Reconstructs
keep waiting, because every segment request queued on one shares it.
FFmpeg itself still runs detached from the request once started. A
transcode node whose start request is abandoned logs it at info rather
than as a readiness failure; the API server already stops that remote
transcode.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, add credits to your account and enable them for code reviews in your settings.

@coderabbitai

coderabbitai Bot commented Sep 26, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

Next included review available in 8 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 2 included reviews currently available.

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Advanced

Run ID: 54e83824-5443-4c8e-9bf4-469d9180058c

📥 Commits

Reviewing files that changed from the base of the PR and between 8d4d1f6 and fe284d2.

📒 Files selected for processing (6)
  • internal/api/handlers/playback_v3.go
  • internal/api/handlers/playback_v3_startup_cancel_test.go
  • internal/playback/transcode.go
  • internal/playback/transcode_startup.go
  • internal/playback/transcode_startup_test.go
  • internal/transcodenode/server.go

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

Comment thread internal/playback/transcode.go Resolved
@macroscopeapp

macroscopeapp Bot commented Sep 26, 2026 •

Copy link
Copy Markdown

Approvability

Verdict: Approved at fe284d2

Macroscope's review found this PR approvable — This is a focused playback bug fix that stops abandoned transcode startup waits, releases lifecycle locks, and preserves existing behavior for timeout-only callers, with targeted tests and no schema or sensitive-path changes. An unresolved Medium-severity automated finding notes a cancellation race when a manifest becomes ready concurrently with request cancellation; that finding independently blocks approval.

Notes:

  • This verdict was updated automatically after the outstanding correctness findings were resolved. Macroscope did not re-review the code.

You can add or adjust custom eligibility rules. Learn more.

@Quick104
Quick104 merged commit 633d94e into main Sep 26, 2026
15 checks passed
@Quick104
Quick104 deleted the fix/transcode-startup-ctx branch September 26, 2026 06:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant