Files
awoooi/docs/adr/ADR-080-ai-autonomy-flywheel-overview.md
OG T db9e304a14 feat(adr-080): Phase 0 防護欄建立 — AI 自主化飛輪啟動
- docs/superpowers/specs/2026-04-15-MASTER-ai-autonomous-flywheel-v2.md
  (1456 行,§0-§8 全填完:42-cell 戰術矩陣、7 Phase 計畫、7 ADR 摘要、
   15 KPI、21 Feature Flags、10 風險場景)

- docs/adr/ADR-080-ai-autonomy-flywheel-overview.md
  (7 Phase 結構 + 4 北極星 + 7 架構師 Review Gates + Phase 退出條件)

- apps/api/src/core/feature_flags.py
  (AIOpsFeatureFlags: P1~P6 總開關全 False + 15 細粒度子開關
   is_phase_enabled() / is_sub_flag_enabled() + bool cast 安全)

- apps/api/src/jobs/__init__.py + baseline_snapshot.py
  (Phase 0 基線快照 Job:MCP calls / Playbook confidence / general 比例
   / learning loop rate / auto_repair — 寫入 aiops:baseline:latest)

- apps/api/tests/test_feature_flags.py  (21 tests — 全綠)

- docs/HARD_RULES.md → v1.9
  (新增 Phase 退出條件鐵律:禁止未過 exit conditions 宣告 Phase 完成)

- CLAUDE.md 防失憶閘門 1:強制讀 MASTER §0 Session Resume Protocol

Gate 0 Pass — 21/21 tests green

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-15 12:44:53 +08:00

150 lines
6.8 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# ADR-080: AI 自主化飛輪總綱
> **日期**: 2026-04-15台北
> **狀態**: 🔵 草稿(待統帥批准後開工)
> **作者**: Claude Sonnet 4.6(首席架構師)+ 統帥 audit
> **相關**:
> - MASTER 藍圖:`docs/superpowers/specs/2026-04-15-MASTER-ai-autonomous-flywheel-v2.md`
> - 廢棄 v1`docs/superpowers/plans/2026-04-15-MASTER-ai-autonomous-flywheel.md`
> - ADR-070 AI 自主修復全自動化迴圈(前置背景)
> - ADR-073 飛輪完整稽查(診斷根因)
---
## 背景
### 現況診斷2026-04-15 深層掃描)
2026-04-15 對整個 AWOOOI AIOps 系統進行深層診斷,確認以下根本性缺陷:
| 指標 | 現況 | 目標 |
|-----|-----|-----|
| MCP 呼叫次數/24h | **0** | > 0 |
| Playbook trust_score | **全 0.3(靜態)** | 動態 EWMA 更新 |
| 學習閉環觸發率 | **0%fire-and-forget** | ≥ 99% |
| 告警分類 general 比例 | **41%** | < 10% |
| 修復動作 RESTART 比例 | **68%** | < 40% |
| 自動執行成功次數/24h | **0** | > 0 |
**根本診斷**:代碼地基在 / 流程骨架在 / **AI 智能靈魂不在**
過去 3 個月所有修復bypass / 黑名單 / 重啟兜底)都是在骨架上貼膏藥,沒有朝 AI 自主化方向推進。
### 驅動力
統帥反覆強調(不下 5 次):
> 「我不要任何寫死的規則,要往 AI 化方向走。每次執行結果都必須回寫讓系統更聰明。」
---
## 決策
### 採用 7 Phase 結構性改造Single Source of Truth MASTER MD
**廢棄**一切「先寫死、先 hardcode、先兜底」的臨時修復思路。
**確立**四大自主化北極星:
| 目標 | 定義 |
|-----|-----|
| **自主學習** | 每次執行回寫 Playbook trust / KM embedding下次決策更聰明 |
| **自主修復** | AI 透過 MCP 主動抓情報推理動作,不依賴硬編規則 |
| **自主告警** | 分類/嚴重度/聚合/路由全部 AI 動態決策 |
| **自主通知** | 收件人/通道/時機/話術由 AI 根據情境判斷 |
### 7 Phase 實施序列
```
Phase 0 防護欄建立 → Feature Flag 框架 + 基線快照 + HARD_RULES 更新
Phase 1 感官縱深 → PreDecisionInvestigator + EvidenceSnapshot + PostExecutionVerifier
Phase 2 多 Agent 協作 → 5 角色Diagnostician/Solver/Reviewer/Critic/Coordinator
Phase 3 學習機制重建 → 3 根因修復 + Evolver + Fine-tune pipeline最關鍵
Phase 4 異常偵測源頭升級 → Holt-Winters + Drain3 + Prophet + 主動巡檢
Phase 5 修復抽象化 → Declarative + Blast Radius 四級分控 + GitOps PR
Phase 6 自我治理閉環 → SLO + Trust Drift + KB Rot + 離線回放 + 自我降級
```
### 防失憶四道閘門
為防止跨 session 方向漂移,確立:
1. **閘門 1**`CLAUDE.md` 強制讀 MASTERSession 啟動第一步)
2. **閘門 2**`project_master_aiops_blueprint.md` 跨 session 狀態指針
3. **閘門 3**MASTER `§0 Session Resume Protocol`(接手 Claude 必讀 7 步驟)
4. **閘門 4**MASTER `§8 Living Changelog`(只追加,記錄每次變更)
### 架構師評審框架(強制)
| Gate | 觸發點 | 審查項目 |
|------|-------|---------|
| Gate 0 | Phase 0 完成 | Feature Flag 結構 / ADR-080 完整性 |
| Gate 1 | Phase 1 完成 | 感官架構邊界 / Prompt Injection 防護 / EvidenceSnapshot schema |
| Gate 2 | Phase 2 完成 | Agent 接口設計 / 熔斷覆蓋 / Redis Streams 隔離 |
| Gate 3 | Phase 3 完成 | 學習閉環三根因 / EWMA 正確性 / fire-and-forget 已消滅 |
| Gate 4 | Phase 4 完成 | 動態基線準確性 / Drain3 整合 / 靜態 rules 減量驗證 |
| Gate 5 | Phase 5 完成 | Blast Radius 分級正確 / dry-run 強制 / GitOps PR 流程 |
| Gate 6 | Phase 6 完成 | SLO 計算準確 / 自我降級不得反向升級 / KB rot 月清可用 |
---
## 影響
### 新增檔案(跨所有 Phase
| Phase | 關鍵新增 |
|-------|---------|
| P0 | `core/feature_flags.py`, `jobs/baseline_snapshot.py` |
| P1 | `services/pre_decision_investigator.py`, `services/evidence_snapshot.py`, `services/post_execution_verifier.py`, `services/mcp_tool_registry.py`, `services/sanitization_service.py` |
| P2 | `agents/diagnostician_agent.py`, `agents/solver_agent.py`, `agents/reviewer_agent.py`, `agents/critic_agent.py`, `agents/coordinator_agent.py`, `services/agent_orchestrator.py` |
| P3 | `services/playbook_evolver.py`, `services/finetune_exporter.py`, `jobs/knowledge_decay_job.py`, `jobs/detection_feedback_writer.py` |
| P4 | `services/dynamic_baseline_service.py`, `services/log_anomaly_detector.py`, `services/trend_predictor.py`, `services/proactive_inspector.py` |
| P5 | `services/blast_radius_calculator.py`, `services/declarative_remediation.py`, `services/gitops_pr_service.py`, `services/rollback_manager.py` |
| P6 | `services/ai_slo_calculator.py`, `services/trust_drift_detector.py`, `services/model_rollback_service.py`, `jobs/offline_replay_service.py`, `jobs/kb_rot_cleaner.py` |
### 修改核心檔案
- `services/decision_manager.py` — 廢棄 25 條硬規則;輸入改 EvidenceSnapshot輸出改 DeclarativeSpec
- `services/approval_execution.py` — 修復 fire-and-forget~line 471接線 PostExecutionVerifier
- `services/learning_service.py` — 填充 matched_playbook_id三段快照負向 2x EWMA
- `services/incident_service.py:classify_alert_early()` — 輸入改 EvidenceSnapshot
### DB 新增表
`incident_evidence` / `agent_sessions` / `playbook_trust_history` / `detection_feedback` /
`anomaly_baselines` / `anomaly_detections` / `forecasts` / `playbook_declarative_stats` /
`ai_governance_events` / `model_checkpoints`
---
## 替代方案(已拒絕)
| 方案 | 拒絕理由 |
|-----|---------|
| 繼續修補規則引擎 | 治標不治本;規則永遠趕不上告警多樣性 |
| 只加 LLM 分類 | 沒有 MCP 情報 → LLM 還是只能猜 RESTART |
| 先 hardcode 過渡 | 統帥明確禁止;技術債會鎖死 AI 化路徑 |
| 分多份 MD 分別追蹤 | 碎片化導致失憶Single Source of Truth 不可妥協 |
---
## 退出條件Phase 0 完成標準)
- [ ] `apps/api/src/core/feature_flags.py` 已建立,`AIOPS_P1~P6_ENABLED``False`
- [ ] `apps/api/src/jobs/baseline_snapshot.py` 已建立,可執行一次拍攝基線
- [ ] `docs/HARD_RULES.md` 已更新至 v1.9(加入 Phase 退出條件鐵律)
- [ ] 本 ADR 已 commit
- [ ] 現有測試全通(`pytest apps/api/tests/` 綠燈)
---
## 參考
- MASTER 藍圖 v2`docs/superpowers/specs/2026-04-15-MASTER-ai-autonomous-flywheel-v2.md`
- 北極星鐵律:`~/.claude/projects/-Users-ogt-awoooi/memory/feedback_ai_autonomous_direction.md`
- 感官縱深D1MASTER §3.1
- 多 AgentD2MASTER §3.2
- 修復抽象D3MASTER §3.3
- 學習深度D4MASTER §3.4
- 異常偵測D5MASTER §3.5
- 自我治理D6MASTER §3.6