feat(governance): add remediation dry run entrypoint
All checks were successful
Code Review / ai-code-review (push) Successful in 10s
CD Pipeline / tests (push) Successful in 1m5s
CD Pipeline / build-and-deploy (push) Successful in 3m43s
CD Pipeline / post-deploy-checks (push) Successful in 1m33s

This commit is contained in:
Your Name
2026-05-14 22:20:34 +08:00
parent 102f92dfc3
commit 04fdaee83a
8 changed files with 820 additions and 3 deletions

View File

@@ -1,3 +1,37 @@
## 2026-05-14 | T25 補救佇列新增安全試跑入口replay/reverify 可先讀證據不改狀態
**背景**T24 已把 non-success verifier rows 轉成 `remediation_queue`,但 Operator 仍只能看見「應該 replay / reverify」無法從前端或 API 直接觸發一個安全、可觀測、低風險的試跑步驟。這會讓「AI 可接手」停在文字標籤,還沒有形成可操作入口。
**修正**
- 新增 `Adr100RemediationService`,從 ADR-100 `verification_coverage.remediation_queue` 找 work item提供 read-only `preview``dry_run`
- 新增 API
- `GET /api/v1/ai/slo/remediation/preview?work_item_id=...`
- `POST /api/v1/ai/slo/remediation/preview`
- `POST /api/v1/ai/slo/remediation/dry-run`
- `dry_run` 不會更新 incident 狀態、不會新增 auto-repair result、不會做真正修復它只做 queue readiness / read-only guardrail / incident loaded / supported executor route 等檢查,並用 verifier 收集當前狀態產生 `verification_result_preview`
- `ready_for_reverify``post_execution_verifier` read-only current-state collection回傳 PromQL 與 MCP route metadata。
- `ready_for_replay` 先驗證 legacy SSH diagnostic 是否可轉成 `auto_repair_executor -> mcp:ssh_diagnose -> required_scope=read`,再收集 current-state preview。
- `AutoRepairService` 新增 `preview_read_only_ssh_mcp_route()`,讓 remediation dry-run 能驗證 supported executor path而不碰私有修復執行流程。
- `/governance` SLO tab 的補救工作佇列每筆新增「試跑」按鈕,呼叫 dry-run API 後回顯 mode、preview result、工具數文案補齊 `zh-TW` / `en` i18n使用 lucide icon不用 emoji。
**本地驗證**
- `python -m py_compile apps/api/src/services/adr100_remediation_service.py apps/api/src/api/v1/ai_slo.py apps/api/src/services/auto_repair_service.py`pass。
- `DATABASE_URL=postgresql+asyncpg://test:test@localhost:5432/test python -m pytest tests/test_adr100_remediation_service.py tests/test_adr100_slo_status_service.py tests/test_auto_repair_service.py -q`33 passed。
- `DATABASE_URL=postgresql+asyncpg://test:test@localhost:5432/test python -m pytest tests/test_adr100_remediation_service.py tests/test_adr100_slo_status_service.py tests/test_adr100_slo_metrics_service.py tests/test_governance_agent.py tests/test_ai_governance_endpoints.py -q`59 passed。
- `ruff check --select F,E9 apps/api/src/services/adr100_remediation_service.py apps/api/src/api/v1/ai_slo.py apps/api/src/services/auto_repair_service.py apps/api/tests/test_adr100_remediation_service.py`pass。
- i18n JSON parse / `git diff --check`pass。
- `pnpm --filter @awoooi/web typecheck`pass。
- `pnpm --dir apps/web exec next lint --file src/app/[locale]/governance/tabs/slo-tab.tsx`pass。
- `NEXT_PUBLIC_API_URL=https://awoooi.wooo.work pnpm --filter @awoooi/web build`pass。
**推版與 production 驗證**
- 待 T25 commit 推 Gitea main 後驗證。
**目前整體進度**
- Alertmanager 低風險自動修復主線:約 98%。
- 完整 AI 自動化管理產品化:約 90%。
- T25 把「補救工作」從可視化清單推到安全試跑入口。下一段應把 dry-run 結果寫回可稽核 timeline / work item history並把真正可 auto-closure 的條件與需要建 Ticket / 人工介入的條件分開。
## 2026-05-14 | T24 非成功驗證補救工作佇列,讓舊 degraded 變成可追蹤工作項
**背景**T22/T23 已找出近 24h non-success verifier 的根因並修掉 executor / PromQL template 斷點,但 `/api/v1/ai/slo` 仍只把 historical degraded rows 顯示為 warning。Operator 仍無法直接判斷每筆舊 degraded 要 replay、reverify、建 Ticket還是人工檢查。