From cf02f1f4cb9f78e23f7621a4ac69e656386c4057 Mon Sep 17 00:00:00 2001 From: ogt Date: Thu, 9 Jul 2026 23:28:32 +0800 Subject: [PATCH] fix(agents): close alert noise duplicate fallback --- .../ai_agent_autonomous_runtime_control.py | 21 +++++++++++++++++-- ...est_ai_agent_autonomous_runtime_control.py | 12 ++++++----- 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/apps/api/src/services/ai_agent_autonomous_runtime_control.py b/apps/api/src/services/ai_agent_autonomous_runtime_control.py index d6315bc4d..ad8c357e7 100644 --- a/apps/api/src/services/ai_agent_autonomous_runtime_control.py +++ b/apps/api/src/services/ai_agent_autonomous_runtime_control.py @@ -1912,14 +1912,28 @@ def _build_alert_noise_reduction_readback( alert_received_recent, 1 if alert_receipt_chain_fallback_recent else 0, ) + controlled_alert_chain_ready = bool( + alert_received_effective_total > 0 + and telegram_receipt_total > 0 + and controlled_route_total > 0 + and consumer_context_total > 0 + ) + controlled_alert_chain_recent = bool( + controlled_alert_chain_ready + and ( + alert_received_effective_recent > 0 + or telegram_receipt_recent > 0 + or controlled_route_recent > 0 + ) + ) duplicate_convergence_fallback_ready = bool( duplicate_convergence_total <= 0 - and alert_receipt_chain_fallback_ready + and controlled_alert_chain_ready and learning_complete ) duplicate_convergence_fallback_recent = bool( duplicate_convergence_fallback_ready - and alert_receipt_chain_fallback_recent + and controlled_alert_chain_recent ) duplicate_convergence_effective_total = max( duplicate_convergence_total, @@ -2158,6 +2172,9 @@ def _build_alert_noise_reduction_readback( "controlled_alert_receipt_chain_fallback_total": ( 1 if alert_receipt_chain_fallback_ready else 0 ), + "controlled_alert_noise_fallback_total": ( + 1 if duplicate_convergence_fallback_ready else 0 + ), }, } diff --git a/apps/api/tests/test_ai_agent_autonomous_runtime_control.py b/apps/api/tests/test_ai_agent_autonomous_runtime_control.py index a90f05c46..8846fffde 100644 --- a/apps/api/tests/test_ai_agent_autonomous_runtime_control.py +++ b/apps/api/tests/test_ai_agent_autonomous_runtime_control.py @@ -1519,6 +1519,9 @@ def test_consumer_receipts_close_taxonomy_decision_and_learning_gaps(): executor_log_count_rows=[ {"status": "success", "total": 2141, "recent": 12}, ], + alert_operation_count_rows=[ + {"event_type": "ALERT_RECEIVED", "total": 28333, "recent": 87}, + ], log_controlled_writeback_consumer=_log_controlled_writeback_consumer_readback(), ) @@ -1581,16 +1584,15 @@ def test_consumer_receipts_close_taxonomy_decision_and_learning_gaps(): alert_noise = readback["alert_noise_reduction"] assert alert_noise["status"] == "completed" assert alert_noise["missing_required_stage_ids"] == [] - assert alert_noise["rollups"]["raw_alert_received_total"] == 0 + assert alert_noise["rollups"]["raw_alert_received_total"] == 28333 assert alert_noise["rollups"]["raw_suppressed_alert_total"] == 0 - assert alert_noise["rollups"]["controlled_alert_receipt_chain_fallback_total"] == 1 + assert alert_noise["rollups"]["controlled_alert_receipt_chain_fallback_total"] == 0 + assert alert_noise["rollups"]["controlled_alert_noise_fallback_total"] == 1 alert_quality = { item["stage_id"]: item.get("record_quality") for item in alert_noise["stages"] } - assert alert_quality["alert_intake_receipts"] == ( - "controlled_alert_receipt_chain_fallback" - ) + assert alert_quality["alert_intake_receipts"] == "recorded" assert alert_quality["duplicate_convergence"] == ( "controlled_alert_receipt_chain_fallback" )