From 4c3e0fdea9fea84eb8524040e1fbeca96815c5f4 Mon Sep 17 00:00:00 2001 From: Josh Hawkins <32435876+hawkeye217@users.noreply.github.com> Date: Thu, 16 Jul 2026 09:37:15 -0500 Subject: [PATCH] don't drop batched camera add/remove config updates TrackedObjectProcessor drained all pending camera config updates at once but handled them in a mutually exclusive if/elif on enabled/add/remove, so only one topic was processed per drain. When an add arrived in the same batch as an enabled update, the add was skipped and the new camera never got a camera state. Adding a camera reliably produced that batch: config_set now re-applies runtime overrides, which republishes an enabled update for every previously toggled camera immediately before the add, in the same request. The dashboard and camera capture still saw the camera (the maintainer does not subscribe to enabled, so it got a clean add-only batch), but object_processing did not, and disabling the camera then crashed with a KeyError on the unguarded camera_states lookup. Handle add and remove independently instead of as exclusive branches so a batched add is no longer dropped, and guard the remove lookup so a missing state is skipped rather than raising. Drop the enabled branch entirely: it only ever set prev_enabled when it was None, but prev_enabled is seeded to a bool at camera state creation and is never None (mypy flags the body as unreachable), and the actual enable/disable transition is already driven by the disabled-state loop from config.enabled. --- frigate/track/object_processing.py | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/frigate/track/object_processing.py b/frigate/track/object_processing.py index 5832d8cdb8..999ec5c04b 100644 --- a/frigate/track/object_processing.py +++ b/frigate/track/object_processing.py @@ -684,22 +684,21 @@ class TrackedObjectProcessor(threading.Thread): # check for config updates updated_topics = self.camera_config_subscriber.check_for_updates() - if "enabled" in updated_topics: - for camera in updated_topics["enabled"]: - if self.camera_states[camera].prev_enabled is None: - self.camera_states[camera].prev_enabled = self.config.cameras[ - camera - ].enabled - elif "add" in updated_topics: - for camera in updated_topics["add"]: - self.config.cameras[camera] = ( - self.camera_config_subscriber.camera_configs[camera] - ) - self.create_camera_state(camera) - elif "remove" in updated_topics: + # a single drain can carry several topics at once, so add and + # remove are handled independently rather than as exclusive branches + for camera in updated_topics.get("add", []): + self.config.cameras[camera] = ( + self.camera_config_subscriber.camera_configs[camera] + ) + self.create_camera_state(camera) + + if "remove" in updated_topics: for camera in updated_topics["remove"]: - removed_camera_state = self.camera_states[camera] - removed_camera_state.shutdown() + camera_state = self.camera_states.get(camera) + if camera_state is None: + continue + + camera_state.shutdown() self.camera_states.pop(camera) self.camera_activity.pop(camera, None) self.last_motion_detected.pop(camera, None)