feat(code-review): ADR-020 全自動修復政策 — 拆掉 CRITICAL/HIGH HITL 閘門
All checks were successful
CD Pipeline / deploy (push) Successful in 2m23s
All checks were successful
CD Pipeline / deploy (push) Successful in 2m23s
post-deploy code review pipeline 改為「任何 finding 一律觸發 AiderHeal」,
局部覆寫 ADR-012 L3 HITL(不影響 schema migration / 流量切換 /
customer-facing 廣播 / AIOps prod SSH 等其他 L3 場景)。安全網改為
Git revert + Gitea CI/CD 健康檢查 + 主開關 CODE_REVIEW_AUTO_FIX_ENABLED。
實作:
• _ea_orchestrate / _guard_ea_decision / rule fallback 三條路徑統一為
has_findings AND AUTO_FIX_ENABLED → auto_fix=true
• _guard 強制 LLM 即使回 auto_fix=False 也升級為 true(核心保證)
• CODE_REVIEW_AUTO_FIX_ENABLED 預設 false → true
• Telegram 文案移除「需人工審查」,改顯示主開關狀態
• action_plan status pending_review → auto_disabled(語意對齊)
• aider_heal_executor 標頭 ADR-014 → ADR-020、補「直推 main」分支策略
文件:
• 新增 docs/adr/ADR-020-code-review-full-autoheal.md
• ADR-012 加 Note 行反向引用 ADR-020
• README 索引收錄
測試:tests/test_code_review_pipeline_security.py 反轉 HITL 期望,
新增 5 case(含 LLM 降級被 guard 拒絕、LLM human_review_needed=true 被改 false)
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
- **Date**: 2026-04-19
|
||||
- **Deciders**: 統帥
|
||||
- **Related**: ADR-001(三 Agent 分工), ADR-004(NemoTron Fallback), ADR-007(AI Dual-Write), ADR-011(跨專案隔離), ADR-018(四 AI Agent 自動化控制面)
|
||||
- **Note**: [ADR-020](ADR-020-code-review-full-autoheal.md) 局部覆寫本 ADR 對「post-deploy code review pipeline」場景的 L3 HITL 規定 — 該場景改採全自動修復 + Git/CI/CD 回滾安全網。本 ADR 對 schema migration / 流量切換 / customer-facing 廣播 / AIOps prod SSH 等其他 L3 場景仍生效。
|
||||
|
||||
## Context
|
||||
|
||||
|
||||
95
docs/adr/ADR-020-code-review-full-autoheal.md
Normal file
95
docs/adr/ADR-020-code-review-full-autoheal.md
Normal file
@@ -0,0 +1,95 @@
|
||||
# ADR-020: Code Review 全自動修復政策(覆寫 ADR-012 對 code review 的 HITL 限制)
|
||||
|
||||
- **Status**: Accepted
|
||||
- **Date**: 2026-05-02
|
||||
- **Deciders**: 統帥
|
||||
- **Related / Supersedes**: 局部覆寫 ADR-012(Agent Action Ladder L3 HITL)對「post-deploy code review pipeline」場景的人工審查門檻;不影響 ADR-012 對其他 L3 場景(如 schema migration、production restart、telegram broadcast)的 HITL 規定
|
||||
- **Affects**: `services/code_review_pipeline_service.py`、`services/aider_heal_executor.py`、`.env.example`、Gitea CI/CD 部署 env
|
||||
|
||||
## Context
|
||||
|
||||
ADR-012 把所有「實際修改程式碼」的動作劃為 L3,預設要求 Human-In-The-Loop 審查。`services/code_review_pipeline_service.py` 依此規則實作四道閘門:
|
||||
|
||||
1. `AUTO_FIX_ENABLED` env 預設 `false`
|
||||
2. EA prompt 寫死「CRITICAL/HIGH → auto_fix=false」
|
||||
3. Rule fallback `priority not in {critical, high}` 才允許 auto_fix
|
||||
4. `_guard_ea_decision` 的 `has_high_risk` override,即使 LLM 回 auto_fix=true 也擋下
|
||||
|
||||
**結果**:2026-05-02 17:38 commit `52c06f6` 觸發 code review,找到 1 CRITICAL(routes/openclaw_bot_routes.py 缺 ALLOWED_USERS 空集處理)+ 1 HIGH(`_is_authorized` 複雜度過高),Telegram 通知顯示「⚠️ Elephant Alpha:CRITICAL 👁 需人工審查」——但統帥的政策一直是「全自動修復、Git+CI/CD 為回滾安全網」。
|
||||
|
||||
**根本衝突**:
|
||||
- ADR-012 假設「程式碼修改 = 高風險 = 必須人工」
|
||||
- 統帥實際立場:「Code review 找到的都應該全自動修,安全網不是人,是 Git revert + Gitea CI/CD」
|
||||
- 過去 memory 引述為「ADR-014」是筆誤(ADR-014 實為 PPT 系統)
|
||||
|
||||
## Decision
|
||||
|
||||
**對 post-deploy code review pipeline 場景**,覆寫 ADR-012 的 HITL 規定:
|
||||
|
||||
### 四條規則
|
||||
|
||||
| # | 規則 | 實作位置 |
|
||||
|---|------|---------|
|
||||
| 1 | 任何 finding(CRITICAL/HIGH/MEDIUM/LOW)一律 `auto_fix=true` | `_ea_orchestrate` prompt + rule fallback |
|
||||
| 2 | `_guard_ea_decision` 不再依 severity 決定 auto_fix,只受 `CODE_REVIEW_AUTO_FIX_ENABLED` 主開關控制 | `_guard_ea_decision` |
|
||||
| 3 | `CODE_REVIEW_AUTO_FIX_ENABLED` 預設值改為 `true`(過去是 `false`) | `services/code_review_pipeline_service.py:43` + `.env.example:187` |
|
||||
| 4 | Telegram 通知文案移除「需人工審查」,改顯示「自動修復未啟用(旗標)」或「已觸發 AiderHeal」 | `_notify_complete` |
|
||||
|
||||
### 安全網(取代 HITL)
|
||||
|
||||
| 層級 | 機制 | 觸發點 |
|
||||
|-----|------|-------|
|
||||
| 1 | AiderHeal 限流:每次最多修 2 個檔案 / 至多 5 個 fix_files | `_trigger_aider_heal:457`、`_nemotron_dispatch fix_files[:5]` |
|
||||
| 2 | 修復產生的 commit 走 Gitea Action CI/CD pipeline,測試失敗自動拒絕 merge | `.gitea/workflows/cd.yaml` |
|
||||
| 3 | CD 健康檢查不過 → compose up 失敗 → 服務維持舊版本 | ADR-008 / ADR-010 |
|
||||
| 4 | Git 歷史完整保留,`git revert <sha>` 一行回滾 | 標準 git 流程 |
|
||||
| 5 | 主開關 `CODE_REVIEW_AUTO_FIX_ENABLED=false` 可即時切斷整條鏈(不需 redeploy 程式碼) | env var |
|
||||
|
||||
### 邊界(不影響的場景)
|
||||
|
||||
ADR-012 的 HITL 規定**仍對下列場景生效**,本 ADR 不覆寫:
|
||||
|
||||
- Schema migration / DB 結構變更
|
||||
- Production 服務重啟、流量切換
|
||||
- Telegram 廣播訊息(用戶可見)
|
||||
- 任何牽涉 customer-facing data 的 mutation
|
||||
- AIOps AutoHeal 對 production 主機的 SSH 修復動作(ADR-013)
|
||||
|
||||
換言之:本 ADR 只對「post-deploy 的 code review → AiderHeal → 提 commit → CI/CD 自動回測」這一條閉環給綠燈。
|
||||
|
||||
## Alternatives Considered
|
||||
|
||||
| 方案 | 為何不選 |
|
||||
|------|---------|
|
||||
| A. 維持 ADR-012 HITL,用 Telegram 按鈕做 one-click approve | 統帥多次表態「不要人工審查」,且 17:38 截圖顯示 Telegram 出現 HITL 訊息就是引爆點 |
|
||||
| B. 全部 ADR-012 場景都改全自動 | 風險面過大,schema migration / 流量切換不適用「Git revert」這種事後回滾 |
|
||||
| C. 用 severity 切:MEDIUM/LOW 自動、CRITICAL/HIGH 仍 HITL | 即現況;統帥明確指出「之前的 HIGH 1-2 → 人工審查門檻是錯誤的」 |
|
||||
| D. 留 HITL 但加「24 小時無人回應自動 fix」timer | 引入時間視窗複雜度,且仍不符「全自動」的精神 |
|
||||
|
||||
## Consequences
|
||||
|
||||
### 正面
|
||||
- Code review pipeline 真正端到端自動化,符合統帥對 AI Agent 的期待
|
||||
- HITL 通道清空,Telegram 訊息聚焦「修復進度」而非「等你決定」
|
||||
- AiderHeal 修復頻率提高 → 觸發更多 OpenClaw learning data(符合 ADR-007 雙寫)
|
||||
|
||||
### 負面 / 風險
|
||||
- AiderHeal 誤判機率提高時,會在 main 留下需 revert 的 commit(雖然 CI/CD 會擋住部署,但歷史會有雜訊)
|
||||
- 主開關 `CODE_REVIEW_AUTO_FIX_ENABLED` 變成關鍵 env,誤設 false 會悄然斷掉整條鏈
|
||||
- ADR-012 文件需註解「ADR-020 已局部覆寫」(待後續 commit 補上)
|
||||
|
||||
### 監控指標
|
||||
- `ai_insights.metadata_json.auto_fix_triggered=true` 比例(部署後應 → 100% 在有 finding 時)
|
||||
- AiderHeal 後 CI/CD 失敗率(觀察 1 週,>30% 要重新評估)
|
||||
- `git revert` 頻率(>每週 1 次代表 AiderHeal 品質有問題)
|
||||
|
||||
## 實作 checklist
|
||||
|
||||
- [x] `services/code_review_pipeline_service.py` 拆四道閘
|
||||
- [x] `.env.example` 預設 true
|
||||
- [x] `tests/test_code_review_pipeline_security.py` 反轉 HITL 期望(含 LLM 降級被 guard 拒絕的測試)
|
||||
- [x] `docs/adr/README.md` 索引加 ADR-020
|
||||
- [x] `docs/adr/ADR-012-agent-action-ladder.md` 加反向引用註記(**Note** 行)
|
||||
- [x] `services/aider_heal_executor.py` 標頭從「ADR-014」更正為「ADR-020」並補分支策略說明
|
||||
- [x] Memory `feedback_code_review_autoheal.md` ADR 號碼從「ADR-014」改為「ADR-020」
|
||||
- [ ] 188 / Gitea env 設 `CODE_REVIEW_AUTO_FIX_ENABLED=true`(程式碼預設已 true,此 env 為冗餘保險,部署時統帥決定)
|
||||
@@ -41,6 +41,7 @@
|
||||
| [017](ADR-017-modularization-cleanup-roadmap.md) | 模組化收尾路線圖(Phase 3f) | Accepted | 2026-04-29 |
|
||||
| [018](ADR-018-four-agent-ai-automation-control-plane.md) | 四 AI Agent 自動化控制面(Hermes/NemoTron/OpenClaw/ElephantAlpha) | Accepted | 2026-04-29 |
|
||||
| [019](ADR-019-telegram-bot-agentic-conversation-layer.md) | Telegram Bot Agentic Conversation Layer(菜單→Agent 決策統一入口) | Accepted | 2026-05-02 |
|
||||
| [020](ADR-020-code-review-full-autoheal.md) | Code Review 全自動修復政策(局部覆寫 ADR-012 HITL) | Accepted | 2026-05-02 |
|
||||
|
||||
## 規範
|
||||
|
||||
|
||||
Reference in New Issue
Block a user