feat(api): Phase 18.2 FailureWatcher 失敗自動修復閉環
All checks were successful
E2E Health Check / e2e-health (push) Successful in 17s
All checks were successful
E2E Health Check / e2e-health (push) Successful in 17s
2026-03-31 Claude Code (統帥批准) 新增: - IFailureWatcher Protocol (interfaces.py) - FailureWatcherService 失敗監聽服務 - AI 分析失敗原因 (規則引擎 + LLM 深度分析) - 風險等級評估 (LOW/MEDIUM/CRITICAL) - LOW 風險自動修復 (Phase 18.3 實際執行) - MEDIUM/CRITICAL 推送 Telegram 請求授權 整合: - executor._write_audit_log() 失敗時觸發 FailureWatcher - 失敗分類寫入 AuditLog.failure_classification - 自動修復結果寫入 AuditLog.auto_repair_result Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -435,3 +435,88 @@ class IK8sRepository(Protocol):
|
||||
True 如果 K8s 連線正常
|
||||
"""
|
||||
...
|
||||
|
||||
|
||||
# =============================================================================
|
||||
# Phase 18: Failure Auto-Repair Loop Protocols
|
||||
# =============================================================================
|
||||
# 2026-03-31 Claude Code (統帥批准)
|
||||
# =============================================================================
|
||||
|
||||
|
||||
@runtime_checkable
|
||||
class IFailureWatcher(Protocol):
|
||||
"""
|
||||
Failure Watcher Protocol
|
||||
|
||||
職責: 監聽失敗事件並觸發修復流程
|
||||
實作: FailureWatcherService
|
||||
|
||||
版本: v1.0
|
||||
建立: 2026-03-31 (台北時區)
|
||||
建立者: Claude Code (Phase 18 失敗自動修復)
|
||||
"""
|
||||
|
||||
async def process_failure(
|
||||
self,
|
||||
audit_log_id: str,
|
||||
failure_data: dict,
|
||||
) -> dict:
|
||||
"""
|
||||
處理單一失敗事件
|
||||
|
||||
Args:
|
||||
audit_log_id: AuditLog ID
|
||||
failure_data: 失敗詳情
|
||||
|
||||
Returns:
|
||||
{
|
||||
"repair_attempted": bool,
|
||||
"repair_result": str | None,
|
||||
"risk_level": str, # LOW/MEDIUM/CRITICAL
|
||||
"next_action": str, # auto_repair/await_approval/escalate
|
||||
}
|
||||
"""
|
||||
...
|
||||
|
||||
async def analyze_failure(
|
||||
self,
|
||||
error_message: str,
|
||||
operation_type: str,
|
||||
target_resource: str,
|
||||
) -> dict:
|
||||
"""
|
||||
AI 分析失敗原因
|
||||
|
||||
Args:
|
||||
error_message: 錯誤訊息
|
||||
operation_type: 操作類型
|
||||
target_resource: 目標資源
|
||||
|
||||
Returns:
|
||||
{
|
||||
"classification": str, # TIMEOUT/K8S_ERROR/NETWORK_ERROR/PERMISSION_DENIED
|
||||
"root_cause": str,
|
||||
"suggested_repair": str,
|
||||
"risk_level": str,
|
||||
"confidence": float,
|
||||
}
|
||||
"""
|
||||
...
|
||||
|
||||
async def execute_auto_repair(
|
||||
self,
|
||||
audit_log_id: str,
|
||||
repair_strategy: str,
|
||||
) -> tuple[bool, str]:
|
||||
"""
|
||||
執行自動修復 (僅限 LOW 風險)
|
||||
|
||||
Args:
|
||||
audit_log_id: 原始失敗的 AuditLog ID
|
||||
repair_strategy: 修復策略
|
||||
|
||||
Returns:
|
||||
(success, result_message)
|
||||
"""
|
||||
...
|
||||
|
||||
Reference in New Issue
Block a user