From 2ef0c75a25662171f34e7391e01e89bb3b518a0c Mon Sep 17 00:00:00 2001 From: Broque Thomas <26755000+Nezreka@users.noreply.github.com> Date: Sat, 7 Mar 2026 22:53:15 -0800 Subject: [PATCH] Fix sync completion not reaching UI after WebSocket reconnect --- web_server.py | 7 ++++++- webui/static/script.js | 11 +++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/web_server.py b/web_server.py index 5ef61772..edd065f6 100644 --- a/web_server.py +++ b/web_server.py @@ -22925,7 +22925,12 @@ def _run_sync_task(playlist_id, playlist_name, tracks_json, automation_id=None): # Run the sync (this is a blocking call within this thread) result = run_async(sync_service.sync_playlist(playlist, download_missing=False)) - + + # Clear progress callback immediately to prevent race condition where a + # late-firing progress callback overwrites the "finished" state below + if sync_service: + sync_service.clear_progress_callback(playlist.name) + sync_duration = (time.time() - sync_start_time) * 1000 total_duration = (time.time() - task_start_time) * 1000 print(f"⏱️ [TIMING] Sync completed at {time.strftime('%H:%M:%S')} (sync: {sync_duration:.1f}ms, total: {total_duration:.1f}ms)") diff --git a/webui/static/script.js b/webui/static/script.js index eb4d8627..1b79abb2 100644 --- a/webui/static/script.js +++ b/webui/static/script.js @@ -147,6 +147,17 @@ function initializeWebSocket() { console.log('WebSocket connected'); socketConnected = true; resubscribeDownloadBatches(); + // Re-subscribe to any active sync/discovery rooms after reconnect + const activeSyncIds = Object.keys(_syncProgressCallbacks); + if (activeSyncIds.length > 0) { + socket.emit('sync:subscribe', { playlist_ids: activeSyncIds }); + console.log('🔄 Re-subscribed to sync rooms:', activeSyncIds); + } + const activeDiscoveryIds = Object.keys(_discoveryProgressCallbacks); + if (activeDiscoveryIds.length > 0) { + socket.emit('discovery:subscribe', { ids: activeDiscoveryIds }); + console.log('🔄 Re-subscribed to discovery rooms:', activeDiscoveryIds); + } // Join profile room for scoped watchlist/wishlist count updates if (currentProfile) { socket.emit('profile:join', { profile_id: currentProfile.id });