fix(worker): evict removed-seed contributions + clear scan worklist on abandon

Two row-leak bugs found in whole-branch review:

- discovery.run_discovery now prunes DiscoverySeedContribution rows whose
  seedMbid is no longer a WatchedArtist (unfollow/removal has no FK cascade)
  and recomputes the touched candidates' scores this sweep, instead of
  letting a dead seed's contribution inflate the aggregate forever.

- maybe_run_scan's exception handler around scan_chunk now calls
  clear_worklist and clears scan.id, matching the drain path. Previously
  an exception mid-chunk left the already-done rows plus the remaining
  worklist for that scan_id orphaned forever, since the next scan mints a
  fresh uuid. Also clear scan.id in the build_worklist failure handler for
  consistency.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Jonathan
2026-07-13 15:39:38 +02:00
parent 0115b82867
commit 6f325d30b9
4 changed files with 69 additions and 2 deletions
+4 -1
View File
@@ -76,6 +76,7 @@ def maybe_run_scan(conn, resolver, probe, browser, config, dest_root: str = DEST
except Exception as e: # a scan error must never kill the worker
print(f"worker: library scan worklist build failed: {e}", flush=True)
conn.rollback()
_set_config(conn, "scan.id", "")
_set_config(conn, "scan.inProgress", "false")
_set_config(conn, "scan.requested", "false")
return
@@ -91,7 +92,9 @@ def maybe_run_scan(conn, resolver, probe, browser, config, dest_root: str = DEST
except Exception as e: # a scan error must never kill the worker
print(f"worker: library scan chunk failed: {e}", flush=True)
conn.rollback()
_set_config(conn, "scan.inProgress", "false")
clear_worklist(conn, scan_id)
_set_config(conn, "scan.id", "")
_set_config(conn, "scan.inProgress", "false") # abandon the scan; a new request restarts it
_set_config(conn, "scan.requested", "false")
return
imported_total = imported_so_far + imp