From 58df2ba33c9a45bb4d66604f542abb946e887a2f Mon Sep 17 00:00:00 2001 From: Broque Thomas Date: Sun, 22 Feb 2026 16:21:28 -0800 Subject: [PATCH] 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. --- web_server.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/web_server.py b/web_server.py index beb6833c..c4784a0b 100644 --- a/web_server.py +++ b/web_server.py @@ -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]