feat(Phase 3): 學習閉環補完 — Root cause 3 + 診斷 feedback + 知識遺忘 + Fine-tune 管線
Some checks failed
CD Pipeline / build-and-deploy (push) Has been cancelled
Some checks failed
CD Pipeline / build-and-deploy (push) Has been cancelled
- approval_execution.py: _run_post_execution_verify() 補接 record_verification_result() Root cause 3 終結:環境驗證結果(success/degraded/failed/timeout)不再孤立 - learning_service.py: 新增 record_verification_result() — 驗證結果 → Redis + Playbook EWMA - learning_service.py: 新增 record_diagnosis_outcome() — 誤診負向訊號回寫(L3×D4) - jobs/knowledge_decay_job.py: 新建 30d 知識遺忘 Job(未引用 draft/review → archived) - services/finetune_exporter.py: 新建每週 JSONL 匯出(EvidenceSnapshot × AgentSession) - main.py: 掛載 knowledge_decay_loop(24h)+ finetune_export_loop(7d) - MASTER §8: Phase 3 核心改造項全部落地記錄 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -645,6 +645,110 @@ class LearningService:
|
||||
)
|
||||
return False
|
||||
|
||||
async def record_diagnosis_outcome(
|
||||
self,
|
||||
incident_id: str,
|
||||
matched_playbook_id: str | None,
|
||||
was_correct: bool,
|
||||
actual_fix: str | None = None,
|
||||
) -> None:
|
||||
"""
|
||||
記錄 AI 診斷結果的正確性。
|
||||
|
||||
ADR-083 Phase 3: 誤診回寫 playbook_diagnosis_feedback(L3×D4)。
|
||||
當 AI 提議被人工拒絕、或執行後驗證失敗,代表診斷可能有誤;
|
||||
此時回寫負向信號,讓對應 Playbook trust_score EWMA 收縮。
|
||||
|
||||
Args:
|
||||
incident_id: 關聯 Incident ID
|
||||
matched_playbook_id: 此次診斷使用的 Playbook ID(若有)
|
||||
was_correct: 診斷是否正確(False = 誤診)
|
||||
actual_fix: 實際有效的修復動作(可供 Evolver 學習)
|
||||
|
||||
2026-04-15 ogt + Claude Sonnet 4.6(亞太): Phase 3 誤診回饋接線
|
||||
"""
|
||||
# 1. 記錄到 Repository(diag: 前綴與 exec: / verify: 區分)
|
||||
try:
|
||||
await self._repository.record_repair(
|
||||
anomaly_key=f"diag:{incident_id}",
|
||||
repair_action=actual_fix or "unknown",
|
||||
success=was_correct,
|
||||
fix_description=f"diagnosis_correct={was_correct}",
|
||||
)
|
||||
except Exception as e:
|
||||
logger.warning(
|
||||
"record_diagnosis_to_repo_failed",
|
||||
incident_id=incident_id,
|
||||
error=str(e),
|
||||
)
|
||||
|
||||
# 2. 誤診時強化 Playbook 負向學習(已有 2x EWMA 衰減係數)
|
||||
if matched_playbook_id and not was_correct:
|
||||
await self._update_playbook_stats(
|
||||
playbook_id=matched_playbook_id,
|
||||
success=False,
|
||||
)
|
||||
|
||||
logger.info(
|
||||
"diagnosis_outcome_recorded",
|
||||
incident_id=incident_id,
|
||||
was_correct=was_correct,
|
||||
matched_playbook_id=matched_playbook_id,
|
||||
)
|
||||
|
||||
async def record_verification_result(
|
||||
self,
|
||||
incident_id: str,
|
||||
action_taken: str,
|
||||
verification_result: str,
|
||||
matched_playbook_id: str | None = None,
|
||||
) -> None:
|
||||
"""
|
||||
記錄環境驗證結果到學習系統。
|
||||
|
||||
ADR-083 Phase 3 Root cause 3: post_execution_verifier → learning 接線修復。
|
||||
環境驗證(Pod Running / 指標恢復)比執行指令 exit code 更精確,
|
||||
單獨存一條 verify: 前綴記錄,並更新 Playbook EWMA stats。
|
||||
|
||||
Args:
|
||||
incident_id: 關聯 Incident ID
|
||||
action_taken: 執行的動作描述(例如 "restart_service:awoooi-api")
|
||||
verification_result: "success" | "degraded" | "failed" | "timeout"
|
||||
matched_playbook_id: 匹配的 Playbook ID(有則更新 EWMA stats)
|
||||
|
||||
2026-04-15 ogt + Claude Sonnet 4.6(亞太): Phase 3 Root cause 3 修復
|
||||
"""
|
||||
success = (verification_result == "success")
|
||||
|
||||
# 1. 記錄環境驗證結果到 Repository(anomaly_key 加 verify: 前綴與執行記錄區分)
|
||||
try:
|
||||
await self._repository.record_repair(
|
||||
anomaly_key=f"verify:{incident_id}",
|
||||
repair_action=action_taken,
|
||||
success=success,
|
||||
fix_description=verification_result,
|
||||
)
|
||||
except Exception as e:
|
||||
logger.warning(
|
||||
"record_verification_to_repo_failed",
|
||||
incident_id=incident_id,
|
||||
error=str(e),
|
||||
)
|
||||
|
||||
# 2. 更新 Playbook EWMA stats(比執行 exit code 更精確的訊號)
|
||||
if matched_playbook_id:
|
||||
await self._update_playbook_stats(
|
||||
playbook_id=matched_playbook_id,
|
||||
success=success,
|
||||
)
|
||||
|
||||
logger.info(
|
||||
"verification_result_recorded",
|
||||
incident_id=incident_id,
|
||||
verification_result=verification_result,
|
||||
matched_playbook_id=matched_playbook_id,
|
||||
)
|
||||
|
||||
async def get_recommended_fix(self, anomaly_key: str) -> dict:
|
||||
"""
|
||||
根據歷史學習,推薦最佳修復方案
|
||||
|
||||
Reference in New Issue
Block a user