Scope fuzzy key match to username and add lock

Tighten fuzzy matching in post-processing when no exact context is found: acquire matched_context_lock for thread-safe access and limit candidate keys to those starting with the current username prefix ("{task_username}::") while still matching the file basename. This prevents cross-album/username metadata contamination during mass downloads (e.g., multiple albums with identical track basenames) and reduces erroneous fuzzy matches.
This commit is contained in:
Broque Thomas 2026-02-22 16:21:28 -08:00
parent f772bf9e5e
commit 58df2ba33c

View file

@ -13929,7 +13929,12 @@ def _run_post_processing_worker(task_id, batch_id):
else:
print(f"❌ [Post-Processing] No context found for key: {context_key}")
# Try fuzzy matching with similar keys containing the filename
similar_keys = [k for k in matched_downloads_context.keys() if task_basename in k]
# SAFETY: Constrain to same Soulseek username to prevent cross-album
# metadata contamination during mass downloads (e.g., two albums both
# having "01 - Intro.flac" would match the wrong context without this)
with matched_context_lock:
similar_keys = [k for k in matched_downloads_context.keys()
if k.startswith(f"{task_username}::") and task_basename in k]
if similar_keys:
# Use the first similar key found
fuzzy_key = similar_keys[0]