From b92c9e285f880c50893adeac9f55ab7b5170e303 Mon Sep 17 00:00:00 2001 From: Your Name Date: Thu, 14 May 2026 19:13:32 +0800 Subject: [PATCH] fix(governance): scope adr100 automation metrics --- .../services/adr100_slo_metrics_service.py | 34 ++++++++++++++----- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/apps/api/src/services/adr100_slo_metrics_service.py b/apps/api/src/services/adr100_slo_metrics_service.py index c0dbef9c..0221ebe5 100644 --- a/apps/api/src/services/adr100_slo_metrics_service.py +++ b/apps/api/src/services/adr100_slo_metrics_service.py @@ -146,17 +146,35 @@ def _escape_label(value: str) -> str: _AUTOMATION_OPERATION_SQL = """ + WITH automation_scope AS ( + SELECT + CASE + WHEN status <> 'success' THEN status + WHEN actor = 'approval_execution' + AND COALESCE(input->>'requested_by', '') NOT ILIKE 'auto%%' + THEN 'human_required' + ELSE 'auto_executed' + END AS outcome, + operation_type + FROM automation_operation_log + WHERE operation_type IN ( + 'playbook_executed', + 'remediation_executed', + 'remediation_verified', + 'remediation_rolled_back', + 'self_correction_attempted' + ) + UNION ALL + SELECT + CASE WHEN success THEN 'auto_executed' ELSE 'failed' END AS outcome, + 'auto_repair_executed' AS operation_type + FROM auto_repair_executions + ) SELECT - CASE - WHEN status <> 'success' THEN status - WHEN actor = 'approval_execution' - AND COALESCE(input->>'requested_by', '') NOT ILIKE 'auto%%' - THEN 'human_required' - ELSE 'auto_executed' - END AS outcome, + outcome, operation_type, count(*) AS count - FROM automation_operation_log + FROM automation_scope GROUP BY outcome, operation_type ORDER BY outcome, operation_type """