fix: Verify stream state before triggering VOD recording (#552)#569
fix: Verify stream state before triggering VOD recording (#552)#569filthyrake merged 1 commit intodevfrom
Conversation
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>
There was a problem hiding this comment.
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_retryusage to re-fetch the stream row after theendedupdate. - 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.
| 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}") |
There was a problem hiding this comment.
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.
| 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}") |
| # 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"]) | ||
| ) |
There was a problem hiding this comment.
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.
Summary
ending -> endedstatus update to verify the state actually persisted before triggering VOD recordingCloses #552
Test plan
fetch_one_with_retryre-fetch handles database contention gracefully🤖 Generated with Claude Code