Skip to content

Studio video stream encode: a failed final flush falls back instead of hanging the render - #14413

Merged
danielhanchen merged 1 commit into
mainfrom
studio-video-stream-encode-flush-fail
Oct 20, 2026
Merged

danielhanchen merged 1 commit into
mainfrom
studio-video-stream-encode-flush-fail

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Follow-up to #14405. If the streaming encoder fails during its final flush (for example the disk fills up while libx264 drains its last frames), the render hangs for good.

What was broken

StreamEncode._encode takes the stop marker off the queue, then flushes the encoder. When stream.encode() or container.mux() raises during that flush, the exception handler drains the queue until it sees another stop marker. _join has already put the only one and is blocked in thread.join(), so neither the fallback encode nor cancel cleanup can finish.

The fix

_encode records that it already took the stop marker and only drains the queue when it has not. _failed is still set, so take() returns None and the clip is encoded the normal way.

Tests

  • New test_a_failed_final_flush_falls_back_without_hanging: a fake container whose flush raises OSError(28). On main take() never returns (the test fails on its 60 s join); with the fix it returns None and close() removes the temp file.
  • tests/test_video_stream_encode.py: 10 passed.

Found by an outside review of #14405, which reproduced the hang with the production _encode / _join and an encoder that fails only on flush.

@danielhanchen danielhanchen self-assigned this Oct 20, 2026
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-20T22:57:18.336407Z 5ff433c Manual request
🔒 Security Review ⚠️ Failed 2026-10-20T22:55:18.659987Z
We couldn’t complete this review. Comment @codex security review to try again.
5ff433c PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🎉

Reviewed commit: 5ff433c397

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@danielhanchen
danielhanchen merged commit 731cb16 into main Oct 20, 2026
@danielhanchen
danielhanchen deleted the studio-video-stream-encode-flush-fail branch October 20, 2026 23:31
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