From fa60318c19376e61407cc1a59678fb970e6c6c38 Mon Sep 17 00:00:00 2001 From: Sharang Parnerkar <30073382+mighty840@users.noreply.github.com> Date: Sat, 28 Nov 2026 12:34:25 +0100 Subject: [PATCH] fix(scan): removing a target's last controller clears its components and alerts Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01Q9inRcu428A2iNjDHPEAT9 --- compliance-agent/src/pipeline/orchestrator.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/compliance-agent/src/pipeline/orchestrator.rs b/compliance-agent/src/pipeline/orchestrator.rs index 0addf3a..6b8df66 100644 --- a/compliance-agent/src/pipeline/orchestrator.rs +++ b/compliance-agent/src/pipeline/orchestrator.rs @@ -1928,7 +1928,9 @@ impl PipelineOrchestrator { // A control application known only by the Siemens controllers // it runs on (SPS item 4a): they are its SBOM, matched against // Siemens' advisories as with a project. - if !target.devices.is_empty() { + // Also when the last one was removed, so its components and + // alerts go with it. + if target.target_type == TargetType::PlcSps || !target.devices.is_empty() { let devices = crate::pipeline::sbom::devices::entries(&target.devices, &target_id); if let Err(e) = self @@ -2321,9 +2323,8 @@ impl PipelineOrchestrator { scan_run_id: &str, mut entries: Vec, ) -> Result<(), AgentError> { - if entries.is_empty() { - return Ok(()); - } + // Empty entries are stored too: the components and alerts of the + // last scan are then gone (callers skip it when nothing was read). crate::pipeline::component_changes::record( &self.db, scan_run_id,