fix(aiops-p1): Playbook 學習閉環 5斷點全修 + DB Migration(ADR-092 B4)
Some checks failed
run-migration / migrate (push) Failing after 14s
CD Pipeline / build-and-deploy (push) Failing after 2m7s

【P0.4 補丁】pre_decision_investigator Prometheus query 欄位缺失
- _build_tool_params() 補 "query" 欄位(prometheus_query tool 必要參數)
- 新增 _build_prometheus_query() — 依告警類型生成 PromQL(CPU/Memory/Crash/Disk/HTTP/Pod/fallback)
- 修復後 D3_METRICS 感官維度實際取得資料(原本 100% 回 missing_query_parameter)

【P1 Playbook 學習閉環 B1-B5 全修】
- B2 db/models.py: ApprovalRecord 新增 matched_playbook_id 欄位 + ix_approval_matched_playbook index
- B2 db/models.py: TimelineEvent 新增 incident_id 欄位(MCP 稽核用)+ index
- B3 approval_db.py: record→ApprovalRequest 補回 incident_id + matched_playbook_id
- B4 approval_repository.py: 同 B3(兩個轉換函式必須同步)
- B5 approval_db.py: approval_request_to_record_data 補 matched_playbook_id → DB 才能存值

【P1.5 KM 寫入】approval_execution.py: fire-and-forget → await wait_for(30s)
- 根因:asyncio.create_task 在 Pod recycle 時被殺,KM 寫入靜默遺失
- 修復:await asyncio.wait_for(..., timeout=30.0) + TimeoutError log

【Migration 文件】adr092_p1_learning_chain_fix.sql
- ALTER TABLE approval_records ADD COLUMN matched_playbook_id VARCHAR(36)
- ALTER TABLE timeline_events ADD COLUMN incident_id VARCHAR(64)
- 執行:psql $DATABASE_URL -f apps/api/migrations/adr092_p1_learning_chain_fix.sql

【附帶 Agent 改動】
- decision_manager: Phase 2 YAML NO_ACTION 優先門(主機層/外部服務跳過 Agent Debate)
- alert_rules.yaml: Sentry/ClickHouse + HostDiskUsageHigh/Critical 新規則
- solver_agent: action_title 語意合成兜底(取代靜默丟棄)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Your Name
2026-04-24 15:41:35 +08:00
parent 7f4088bcd0
commit 04ff22563e
11 changed files with 321 additions and 20 deletions

View File

@@ -1698,6 +1698,41 @@ Phase 6 完成後
---
### 2026-04-24 — 12 Agent 全景審計 + P0-P2 並行修復啟動
**審計方式**12 個專責 Agent 並行掃描 125 個服務檔案 × 7 層架構 × 13 個關鍵節點
**核心發現:系統有效串接率 ~60%,連接的 60% 有大量靜默故障**
| 病根 | 位置 | 嚴重度 |
|------|------|--------|
| A. Prometheus MCP 100% KeyError | `pre_decision_investigator.py:469-481` | 🔴🔴🔴 |
| B. auto_execute Gate 9+11 必攔唯讀指令 | `blast_radius_calculator.py:38-61`, `operation_parser.py:51-185` | 🔴🔴🔴 |
| C. Playbook 學習閉環5個斷鏈matched_playbook_id 永遠None | `proposal_service.py:232-257`, `db/models.py:59`, `approval_db.py:91-112` | 🔴🔴🔴 |
| D. KM每天+5主因s.description AttributeError 100% 失敗 | `knowledge_extractor_service.py:210` | 🔴🔴🔴 |
| E. consensus_engine 4個 ExpertAgent confidence=0.0 硬寫死 | `consensus_engine.py:165-334` | 🔴🔴 |
| F. auto_repair 主路徑完全不接 PostExecutionVerifier | `auto_repair_service.py:324-500` | 🔴🔴 |
| G. ProactiveInspector 5個 PromQL 全回空 vector基線9天0筆 | `proactive_inspector.py:40-71` | 🔴🔴 |
| H. timeline_events 每天+1raw SQL INSERT 欄位不存在被靜默吞 | `pre_decision_investigator.py:344,361` | 🔴🔴 |
**孤立服務12個重要服務零引用**trust_drift_detector / rollback_manager / resource_resolver / diagnosis_aggregator / model_rollback_service / kb_rot_cleaner / ci_auto_repair / sentry_webhook_service 等
**P0 修復(今日並行執行)**
- P0.1: knowledge_extractor_service.py:210 s.description → alert_name + annotations.summary
- P0.2+P0.3: blast_radius + operation_parser 補唯讀指令白名單
- P0.4: pre_decision_investigator Prometheus _build_tool_params 補 query 欄位
- P0.5: alert_rules.yaml generic_fallback NO_ACTION + 6條語義矛盾修正
- P0.6: proactive_inspector 5個 PromQL 修正 label + datname
**P1 DB Migration今日並行執行**
- ApprovalRecord 加 matched_playbook_id 欄位Alembic migration
- timeline_events 加 incident_id + stage 欄位
- proposal_service / approval_db / approval_repository 讀寫補齊
- decision_manager:2463 冷啟動豁免total_executions=0 略過 success_rate 過濾)
- approval_execution:702-704 KM 寫入 fire-and-forget → await asyncio.wait_for(timeout=10s)
---
### 2026-04-20 晚 (台北) — C1-C4 全流程串接 — Playbook 鏈路保護commit de2d34d
**觸發**:統帥全景盤查 AI 自動化節點後,發現 Playbook 自動修復鏈路有 3 個結構性斷點。