@@ -126,7 +126,33 @@ def load_settings_from_file(cls) -> dict:
126126
127127 # Filter dictionary to only include valid fields for this dataclass
128128 valid_fields = {f .name for f in cls .__dataclass_fields__ .values ()}
129- return {k : v for k , v in config_dict .items () if k in valid_fields }
129+ settings = {k : v for k , v in config_dict .items () if k in valid_fields }
130+
131+ # Sanitize loaded settings against current labels from labels.txt
132+ # Remove saved 'unsafe_conditions' that are no longer in ALL_CLOUD_CONDITIONS
133+ if 'unsafe_conditions' in settings :
134+ valid_labels = set (ALL_CLOUD_CONDITIONS )
135+ original_count = len (settings ['unsafe_conditions' ])
136+ settings ['unsafe_conditions' ] = [
137+ c for c in settings ['unsafe_conditions' ]
138+ if c in valid_labels
139+ ]
140+ removed_count = original_count - len (settings ['unsafe_conditions' ])
141+ if removed_count > 0 :
142+ logger .info (f"Removed { removed_count } obsolete unsafe condition(s) from saved configuration" )
143+
144+ # Clean up stale class thresholds
145+ if 'class_thresholds' in settings :
146+ original_count = len (settings ['class_thresholds' ])
147+ settings ['class_thresholds' ] = {
148+ k : v for k , v in settings ['class_thresholds' ].items ()
149+ if k in ALL_CLOUD_CONDITIONS
150+ }
151+ removed_count = original_count - len (settings ['class_thresholds' ])
152+ if removed_count > 0 :
153+ logger .info (f"Removed { removed_count } obsolete class threshold(s) from saved configuration" )
154+
155+ return settings
130156 except Exception as e :
131157 logger .error (f"Failed to load configuration from { filepath } : { e } " )
132158 return {}
0 commit comments