Discard in-flight break generation when the station changes #4

Merged
gthelding merged 0 commits from fix/stale-break-race into main 2026-07-20 00:09:28 +00:00
gthelding commented 2026-07-19 23:15:04 +00:00 (Migrated from codeberg.org)

_clear_stale_break() removes a finished pending break, but a break still being generated (Claude + TTS, 15-60s) can't be cancelled — it lands after the clear and becomes the new station's first break, narrating the previous station's songs. The new station's own generation task sees break_generating=True and gives up, guaranteeing the stale break plays. Same window applies to skips: an in-flight break can reference the skipped song.

Fix: a station_epoch counter bumped in _clear_stale_break() (covers genre switch, artist station, and skip — all existing call sites).
_maybe_generate_break() captures the epoch and discards its own result if the epoch moved, checking after script generation (saving the TTS cost) and again after synthesis. The next due /api/next re-triggers generation for the current station as it already does today.

_clear_stale_break() removes a finished pending break, but a break still being generated (Claude + TTS, 15-60s) can't be cancelled — it lands after the clear and becomes the new station's first break, narrating the previous station's songs. The new station's own generation task sees break_generating=True and gives up, guaranteeing the stale break plays. Same window applies to skips: an in-flight break can reference the skipped song. Fix: a station_epoch counter bumped in _clear_stale_break() (covers genre switch, artist station, and skip — all existing call sites). _maybe_generate_break() captures the epoch and discards its own result if the epoch moved, checking after script generation (saving the TTS cost) and again after synthesis. The next due /api/next re-triggers generation for the current station as it already does today.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
thelinuxcast/dj!4
No description provided.