soulsync/core/automation/handlers
Broque Thomas 01a867e589 Auto-Sync: fix LB pipelines stuck on "Refreshing:" for 5+ minutes
Pipeline-driven Auto-Sync runs against any ListenBrainz playlist
(Weekly Jams, Weekly Exploration, Top Discoveries, etc.) would sit
on ``Refreshing: "<name>"`` with no UI updates for 5-7 minutes
before the pipeline progressed. Two real bugs stacked:

1. **Double discovery.** The refresh handler called
   ``_maybe_discover`` (matching engine, per-track Spotify/iTunes/
   Deezer matches) inline for any source returning
   ``needs_discovery=True`` tracks. Phase 2 of the pipeline then
   ran the SAME matching engine via ``run_playlist_discovery_worker``
   on the same tracks. The refresh-side run blocked the loop with
   zero progress emission; Phase 2's already has the timed
   progress-poll pattern. So LB tracks discovered twice, the first
   time silently.

   Pipeline now sets ``skip_discovery=True`` on its refresh config.
   The handler honors the flag and lets Phase 2 handle discovery
   end-to-end. Standalone callers (Sync-page tab, registration
   action) leave the flag unset so they still get matched_data
   on refresh.

2. **No targeted LB refresh.** The LB adapter's ``refresh_playlist``
   called ``manager.update_all_playlists()`` — the only refresh
   entry-point the manager exposed — which re-pulls every cached
   LB playlist's details from the API (~12+ round-trips) even
   when only one playlist needed refreshing. Wasteful;
   tax-on-everyone for one-playlist work.

   Added ``LBManager.refresh_playlist(mbid)`` — reads the cached
   playlist_type, fetches just that playlist's details, runs the
   normal ``_update_playlist`` upsert path. Defaults type to
   ``user`` for un-cached mbids so new-playlist discovery still
   works. Skips ``_cleanup_old_playlists`` and
   ``_ensure_rolling_mirrors_from_cache`` (wasted work for a
   single-playlist refresh).

Also: killed a silent ``except Exception: pass`` in the LB
adapter's old refresh wrapper that was masking every LB API
failure as a stale-cache hit. Refresh errors now log with full
traceback at warning level and propagate ``None`` so the outer
handler at ``refresh_mirrored.py:104`` counts the error and
surfaces it to the run-history error tally.

Pinned with 12 new unit tests across:
  - ``tests/test_listenbrainz_manager.py`` (8): targeted refresh
    happy path, unauthenticated guard, empty-mbid guard, upstream
    ``None`` return, default playlist_type for unknown mbid,
    exception propagation, cost guard skipping cleanup, skipped-
    when-unchanged signal
  - ``tests/test_playlist_sources_adapters.py`` (3): adapter uses
    targeted call (not legacy), adapter returns ``None`` on manager
    error (not silent swallow), adapter resolves synthetic series
    ids before calling the manager
  - ``tests/automation/test_handlers_playlist.py`` (1):
    skip_discovery flag bypasses ``_maybe_discover`` end-to-end
2026-05-27 18:04:55 -07:00
..
__init__.py Personalized playlist pipeline: auto-sync discover-page playlists 2026-05-15 18:41:08 -07:00
_pipeline_shared.py Harden playlist pipeline source refresh 2026-05-24 19:31:00 -07:00
database_update.py Extract automation handlers (3/3): maintenance + misc, finishing the lift 2026-05-15 11:24:35 -07:00
discover_playlist.py Extract automation handlers (2/N): playlist lifecycle group 2026-05-15 10:47:46 -07:00
download_cleanup.py Extract automation handlers (3/3): maintenance + misc, finishing the lift 2026-05-15 11:24:35 -07:00
duplicate_cleaner.py Extract automation handlers (3/3): maintenance + misc, finishing the lift 2026-05-15 11:24:35 -07:00
maintenance.py Extract automation handlers (3/3): maintenance + misc, finishing the lift 2026-05-15 11:24:35 -07:00
personalized_pipeline.py Preserve personalized playlist metadata for wishlist 2026-05-15 21:50:32 -07:00
playlist_pipeline.py Move mirrored playlist pipeline into playlist domain 2026-05-24 19:44:13 -07:00
process_wishlist.py Extract automation handlers (1/N): infrastructure + 3 simple handlers 2026-05-15 10:25:41 -07:00
progress_callbacks.py Extract automation handlers (4/3 — finish): progress callbacks + scan-completion emitter 2026-05-15 11:59:32 -07:00
quality_scanner.py Extract automation handlers (3/3): maintenance + misc, finishing the lift 2026-05-15 11:24:35 -07:00
refresh_mirrored.py Auto-Sync: fix LB pipelines stuck on "Refreshing:" for 5+ minutes 2026-05-27 18:04:55 -07:00
registration.py Personalized playlist pipeline: auto-sync discover-page playlists 2026-05-15 18:41:08 -07:00
run_script.py Extract automation handlers (3/3): maintenance + misc, finishing the lift 2026-05-15 11:24:35 -07:00
scan_library.py Extract automation handlers (1/N): infrastructure + 3 simple handlers 2026-05-15 10:25:41 -07:00
scan_watchlist.py Extract automation handlers (1/N): infrastructure + 3 simple handlers 2026-05-15 10:25:41 -07:00
search_and_download.py Extract automation handlers (3/3): maintenance + misc, finishing the lift 2026-05-15 11:24:35 -07:00
sync_playlist.py Extract automation handlers (2/N): playlist lifecycle group 2026-05-15 10:47:46 -07:00