From 107947495debe3465efb0e5fcd80c19b6a1629dd Mon Sep 17 00:00:00 2001 From: SBCrumb Date: Thu, 12 Feb 2026 09:12:50 -0500 Subject: [PATCH] Fix duplicate HMS error notifications from race condition Move _notified_hms_errors tracking update before the async notification send to prevent concurrent status callbacks from both seeing the same errors as new. This mirrors the existing milestone tracking pattern which correctly updates before the await. --- backend/app/main.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/backend/app/main.py b/backend/app/main.py index b9f6e88a2..7cda9c49e 100644 --- a/backend/app/main.py +++ b/backend/app/main.py @@ -410,6 +410,9 @@ async def on_printer_status_change(printer_id: int, state: PrinterState): # Find new errors that haven't been notified yet new_error_codes = current_error_codes - previously_notified + # Update tracking immediately to prevent duplicate notifications from concurrent callbacks + _notified_hms_errors[printer_id] = current_error_codes + if new_error_codes: # Get the actual new errors for the notification # Filter to severity >= 2 (skip informational/status messages like H2D sends) @@ -480,8 +483,6 @@ async def on_printer_status_change(printer_id: int, state: PrinterState): except Exception as e: logging.getLogger(__name__).warning(f"HMS error notification failed: {e}") - # Update tracking with all current errors - _notified_hms_errors[printer_id] = current_error_codes else: # No HMS errors - clear tracking so future errors get notified if printer_id in _notified_hms_errors: