Skip to content

fix: Verify stream state before triggering VOD recording (#552)#569

Merged
filthyrake merged 1 commit intodevfrom
fix/vod-stream-end-verification-552
Feb 7, 2026
Merged

fix: Verify stream state before triggering VOD recording (#552)#569
filthyrake merged 1 commit intodevfrom
fix/vod-stream-end-verification-552

Conversation

@filthyrake
Copy link
Owner

Summary

  • Re-fetches stream from the database after the ending -> ended status update to verify the state actually persisted before triggering VOD recording
  • Prevents VODs from being created with incomplete or inconsistent stream data if the update was rolled back or lost
  • Logs a warning when verification fails so the issue is observable

Closes #552

Test plan

  • Verify normal VOD recording flow still works when stream correctly transitions to "ended"
  • Confirm that VOD recording is skipped (with warning log) if stream status doesn't match after update
  • Check that the fetch_one_with_retry re-fetch handles database contention gracefully

🤖 Generated with Claude Code

Re-fetch stream after ending->ended update to confirm the status
persisted before triggering VOD recording, preventing VODs from
incomplete or inconsistent stream data.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Improves reliability of live stale-stream cleanup by verifying the stream’s persisted state after transitioning ending -> ended before triggering VOD recording, addressing Issue #552.

Changes:

  • Adds fetch_one_with_retry usage to re-fetch the stream row after the ended update.
  • Gates VOD finalization/recording on the verified post-update stream status.
  • Logs a warning when post-update status verification fails.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +185 to 190
if updated_stream and updated_stream["status"] == "ended" and updated_stream["auto_record_vod"]:
try:
await finalize_playlists_for_vod(stream["id"])
await trigger_vod_recording(stream["id"])
except Exception as e:
logger.error(f"Failed to create VOD for stream {stream['slug']}: {e}")
Copy link

Copilot AI Feb 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The VOD trigger condition is now based on updated_stream["auto_record_vod"], which can change behavior if that flag is modified between the initial SELECT and the re-fetch. Elsewhere (e.g., end_live_stream) the decision to trigger VOD recording is based on the original row that drove the transition, using the re-fetched row only for verification/response. Consider keeping the verification limited to status == "ended" and using the original stream["auto_record_vod"] for the VOD decision to avoid unexpected skips/starts due to concurrent edits.

Suggested change
if updated_stream and updated_stream["status"] == "ended" and updated_stream["auto_record_vod"]:
try:
await finalize_playlists_for_vod(stream["id"])
await trigger_vod_recording(stream["id"])
except Exception as e:
logger.error(f"Failed to create VOD for stream {stream['slug']}: {e}")
if updated_stream and updated_stream["status"] == "ended":
if stream["auto_record_vod"]:
try:
await finalize_playlists_for_vod(stream["id"])
await trigger_vod_recording(stream["id"])
except Exception as e:
logger.error(f"Failed to create VOD for stream {stream['slug']}: {e}")

Copilot uses AI. Check for mistakes.
Comment on lines +180 to +183
# Re-fetch stream after update to verify state before VOD recording (Issue #552)
updated_stream = await fetch_one_with_retry(
live_streams.select().where(live_streams.c.id == stream["id"])
)
Copy link

Copilot AI Feb 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fetch_one_with_retry(...) can raise (e.g., DatabaseTimeoutError / DatabaseRetryableError). As written, a failure to re-fetch will abort detect_stale_streams() and prevent processing any remaining ending streams, even though the status update already succeeded. Consider wrapping the re-fetch + verification in a try/except and treating exceptions as a verification failure (log warning + skip VOD) so stale detection continues for other streams.

Copilot uses AI. Check for mistakes.
@filthyrake filthyrake merged commit 2080307 into dev Feb 7, 2026
8 of 9 checks passed
@filthyrake filthyrake deleted the fix/vod-stream-end-verification-552 branch February 7, 2026 18:03
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.

[Reliability] VOD Recording Triggered Without Stream End Verification

1 participant

Comments