fix(api): 修復 34 個 Ruff lint 錯誤
- 自動修復 import 排序、unused imports - 手動修復 raise from、isinstance union、unused variable - scripts/ 暫時保留 (非 CI 阻擋) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -187,6 +187,71 @@ class AIDecisionChain(BaseModel):
|
||||
}
|
||||
|
||||
|
||||
# =============================================================================
|
||||
# Incident Frequency Stats (ADR-037: 異常頻率統計)
|
||||
# =============================================================================
|
||||
|
||||
|
||||
class IncidentFrequencyStats(BaseModel):
|
||||
"""
|
||||
事件頻率統計 - ADR-037 監控增強架構
|
||||
|
||||
2026-03-29 ogt: 統帥指示「重啟只是治標,太常發生的異常必須徹底解決」
|
||||
|
||||
用途:
|
||||
- 統計同一異常在不同時間窗口內的發生次數
|
||||
- 根據頻率決定修復策略的升級 (Tier 1→4)
|
||||
- 讓使用者知道這個問題有多頻繁
|
||||
|
||||
升級閾值:
|
||||
- REPEAT: ≥ 3 次/24h (標記重複)
|
||||
- ESCALATE: ≥ 5 次/24h (升級 Tier,通知 Owner)
|
||||
- PERMANENT_FIX: ≥ 10 次/24h (強制根因修復)
|
||||
"""
|
||||
|
||||
anomaly_key: str = Field(
|
||||
...,
|
||||
description="異常簽名 Hash (前 16 字元)",
|
||||
)
|
||||
count_1h: int = Field(
|
||||
default=0,
|
||||
ge=0,
|
||||
description="1 小時內發生次數",
|
||||
)
|
||||
count_24h: int = Field(
|
||||
default=0,
|
||||
ge=0,
|
||||
description="24 小時內發生次數",
|
||||
)
|
||||
count_7d: int = Field(
|
||||
default=0,
|
||||
ge=0,
|
||||
description="7 天內發生次數",
|
||||
)
|
||||
count_30d: int = Field(
|
||||
default=0,
|
||||
ge=0,
|
||||
description="30 天內發生次數",
|
||||
)
|
||||
escalation_level: Literal["REPEAT", "ESCALATE", "PERMANENT_FIX"] | None = Field(
|
||||
None,
|
||||
description="升級建議 (基於 24h 頻率)",
|
||||
)
|
||||
auto_repair_count: int = Field(
|
||||
default=0,
|
||||
ge=0,
|
||||
description="自動修復嘗試次數",
|
||||
)
|
||||
last_repair_action: str | None = Field(
|
||||
None,
|
||||
description="最後一次修復動作",
|
||||
)
|
||||
last_repair_success: bool | None = Field(
|
||||
None,
|
||||
description="最後一次修復是否成功",
|
||||
)
|
||||
|
||||
|
||||
# =============================================================================
|
||||
# Incident Outcome (CPO 要求:回饋循環)
|
||||
# =============================================================================
|
||||
@@ -319,6 +384,13 @@ class Incident(BaseModel):
|
||||
description="事件結果與人類回饋",
|
||||
)
|
||||
|
||||
# === 頻率統計 (ADR-037) ===
|
||||
# 2026-03-29 ogt: 統帥指示「重啟只是治標,太常發生的異常必須徹底解決」
|
||||
frequency_stats: IncidentFrequencyStats | None = Field(
|
||||
None,
|
||||
description="異常頻率統計 (用於 Tier 分級修復策略)",
|
||||
)
|
||||
|
||||
# === 時間軸 ===
|
||||
created_at: datetime = Field(
|
||||
default_factory=lambda: datetime.now(UTC),
|
||||
|
||||
Reference in New Issue
Block a user