diff --git a/apps/api/src/api/v1/webhooks.py b/apps/api/src/api/v1/webhooks.py index e1beccce..0b919ab2 100644 --- a/apps/api/src/api/v1/webhooks.py +++ b/apps/api/src/api/v1/webhooks.py @@ -871,6 +871,18 @@ async def receive_alert( } risk_level = risk_mapping.get(analysis_result.risk_level.value, RiskLevel.MEDIUM) + # 2026-04-21 ogt: NO_ACTION/INVESTIGATE/OBSERVE 強制 LOW risk,避免卡 PENDING + # 根因:_validate_deployment_inventory 降級後若原 risk 為 HIGH/CRITICAL, + # 會等 Telegram 批准,但無任何可執行動作 → 永久積壓 PENDING + _non_destructive_actions = {"NO_ACTION", "INVESTIGATE", "OBSERVE"} + _sa_val = ( + analysis_result.suggested_action.value + if hasattr(analysis_result.suggested_action, "value") + else str(analysis_result.suggested_action) + ) + if _sa_val in _non_destructive_actions: + risk_level = RiskLevel.LOW + impact_mapping = { "NONE": DataImpact.NONE, "READ_ONLY": DataImpact.READ_ONLY, @@ -1100,6 +1112,16 @@ async def _process_new_alert_background( } risk_level = risk_mapping.get(analysis_result.risk_level.value, RiskLevel.MEDIUM) + # 2026-04-21 ogt: NO_ACTION/INVESTIGATE/OBSERVE 強制 LOW risk,避免卡 PENDING + _non_destructive_actions = {"NO_ACTION", "INVESTIGATE", "OBSERVE"} + _sa_val = ( + analysis_result.suggested_action.value + if hasattr(analysis_result.suggested_action, "value") + else str(analysis_result.suggested_action) + ) + if _sa_val in _non_destructive_actions: + risk_level = RiskLevel.LOW + blast = analysis_result.blast_radius impact_mapping = { "NONE": DataImpact.NONE, diff --git a/apps/api/src/services/flywheel_stats_service.py b/apps/api/src/services/flywheel_stats_service.py index b7c8e702..ff8a29b0 100644 --- a/apps/api/src/services/flywheel_stats_service.py +++ b/apps/api/src/services/flywheel_stats_service.py @@ -204,9 +204,9 @@ class FlywheelStatsService: status = pb.get("status", "") if status == "approved": count += 1 - exec_count = pb.get("execution_count", 0) or 0 success_count = pb.get("success_count", 0) or 0 - total_exec += exec_count + failure_count = pb.get("failure_count", 0) or 0 + total_exec += success_count + failure_count total_success += success_count except (json.JSONDecodeError, KeyError): continue diff --git a/apps/api/src/services/openclaw.py b/apps/api/src/services/openclaw.py index c81730a8..98898626 100644 --- a/apps/api/src/services/openclaw.py +++ b/apps/api/src/services/openclaw.py @@ -32,6 +32,7 @@ from src.core.config import settings from src.core.prompts import NEMOTRON_SYSTEM_PROMPT, OPENCLAW_SYSTEM_PROMPT from src.core.redis_client import get_redis from src.models.ai import ( + AIRiskLevel, OpenClawDecision, SuggestedAction, ) @@ -1214,6 +1215,12 @@ class OpenClawService: result.confidence = 0.0 except Exception: pass + # 2026-04-21 ogt: 降級後風險強制 LOW,避免 NO_ACTION 因原 HIGH/CRITICAL risk + # 留在 PENDING 等 Telegram 批准(已無執行內容,等待毫無意義) + try: + result.risk_level = AIRiskLevel.LOW + except Exception: + pass def _parse_analysis_result(self, raw_response: str) -> OpenClawDecision | None: """