88 lines
7.0 KiB
Markdown
88 lines
7.0 KiB
Markdown
# AI 自動化閉環記憶(2026-04-29)
|
||
|
||
> 用途:讓新 Codex session 快速掌握 2026-04-29 這輪「AI 自動化」修復後的實況,不必重讀整串對話與所有 commit。
|
||
|
||
## 核心結論
|
||
|
||
- AI 自動化控制面已從三 Agent 擴展為四 Agent:Hermes、NemoTron、OpenClaw、ElephantAlpha。
|
||
- EventRouter 是告警與 L2 安全 action 的入口;AI 掛掉時必須降級,不可中斷通知。
|
||
- AutoHeal 是自癒副作用入口;`momo-db` / `momo-postgres` 受保護,不可自動 restart / stop / recreate。
|
||
- OpenClaw learning 是 AI 記憶與 embedding queue 的橋接層;raw `ai_insights` 寫入者必須 enqueue embedding 或可回補。
|
||
- ElephantAlpha 只負責 orchestration / HITL / AutoHeal bridge,不可繞過 ADR-011、ADR-012、ADR-013。
|
||
- AI 自動化最小 Prometheus 指標已接入 `/metrics`,來源為 `services/ai_automation_metrics.py`。
|
||
- 線上 smoke dashboard 已接入 `/ai_automation_smoke`,JSON API 為 `/api/ai-automation/smoke`。
|
||
- Smoke API 會保存最近快檢 JSONL 趨勢,dashboard 顯示 OK / Warning / Critical 最近分布。
|
||
- Smoke history 已支援 JSONL 匯出、清理與每日摘要;清理只影響 smoke history,不碰 DB 或 EventRouter queue。
|
||
- Smoke 每日摘要已支援手動 Telegram 推播與 scheduler 09:10 排程入口;摘要只讀 JSONL history。
|
||
- Grafana provisioning 已新增 `MOMO AI Automation Overview`,由 Prometheus `/metrics` 觀測 EventRouter、safe action、replay 與 AutoHeal 趨勢。
|
||
- 2026-04-30 active Grafana 已載入 4 個 dashboard;AI dashboard 檔案同步到 188 實際掛載目錄 `monitoring/grafana/provisioning/dashboards/json/`。
|
||
- 2026-04-30 active Prometheus 補 `momo-app` scrape job,目標 `momo-pro-system:80/metrics`;Prometheus 需加入 `momo-network` 才能解析 app container DNS。
|
||
- 2026-04-30 發現並修復 `gunicorn.conf.py` `post_fork` 掃到 Flask/Werkzeug LocalProxy 導致 worker boot fail 的問題。
|
||
- 2026-04-30 CD 健康檢查曾因 rebuild 後短暫 502 太早失敗;已改為 internal `docker exec momo-pro-system /health` + external `https://mo.wooo.work/health` 雙檢查,重試約 3 分鐘。
|
||
- 2026-04-30 CD Sync 模式曾只 rsync + `docker compose up -d`,導致 host 檔案已是新版但 gunicorn process 仍跑舊版;已補 `docker compose restart momo-app scheduler telegram-bot`。
|
||
- 2026-04-30 `gunicorn.conf.py` 不是 app container bind mount,曾導致手動 restart 後回吃 image 內舊設定;`momo-app` 已補 `./gunicorn.conf.py:/app/gunicorn.conf.py:ro`。
|
||
- 2026-04-30 `/metrics` 對 `realtime_sales_monthly` 改用 raw `SELECT COUNT(*)`,避免 ORM 欄位與線上表 schema drift 時每次 Prometheus scrape 都產生 warning。
|
||
|
||
## 已落地範圍
|
||
|
||
- EventRouter 增加同步 dispatch、AI 失敗降級、Telegram 失敗 file queue、成功後 replay、去重冷卻、靜音檢查、L2 SAFE_ACTIONS 限制。
|
||
- NemoTron 在缺 API key、quota、timeout、network/HTTP error、0 tool call 時 fallback 到 Hermes 規則。
|
||
- Code review pipeline 預設關閉 auto-fix,高風險只走 HITL/action_plan,內部 webhook token 預設必填。
|
||
- AutoHeal 補 incident / heal log / KM 沉澱,DB 不可用時安全降級,SSH_CMD 限 read-only allowlist。
|
||
- OpenClaw learning 補 raw insert embedding bridge、stale processing reset、missing embedding backfill、pgvector semantic RAG fallback。
|
||
- Scheduler 重要失敗路徑接入 EventRouter,減少裸 exception 漏通知。
|
||
- ElephantAlpha 執行引擎補 sync timeout、HITL reply_markup、未知 step fail fast、code/resource action 走 AutoHeal bridge。
|
||
- L2 `agent_actions.py` 的 `flag_for_human_review`、`route_to_km`、`mark_for_relearn` 已從 stub 改為可審計 OpenClaw memory 寫入。
|
||
- `/metrics` 已匯出 EventRouter dispatch、latency、safe action、Telegram replay、AutoHeal action 與 duration 指標。
|
||
- Smoke dashboard read-only 檢查 EventRouter queue、AutoHeal protected resources、NemoTron fallback、OpenClaw embedding queue、ElephantAlpha HITL,不做外部網路呼叫。
|
||
- Smoke history 只保存精簡紀錄,不保存完整 details,避免長期檔案膨脹與敏感資訊堆積。
|
||
- Export API 回傳 `application/x-ndjson`,clear API 只刪除 `MOMO_AI_AUTOMATION_SMOKE_HISTORY` 指向檔案。
|
||
- Daily summary API:`POST /api/ai-automation/smoke/daily-summary/send`。
|
||
- Grafana dashboard 檔案:`docker/grafana/provisioning/dashboards/json/ai-automation-overview.json`;provider 會載入 JSON 目錄,不需要修改 dashboard provider。
|
||
- Active monitoring 使用 `monitoring/prometheus.yml`,不是 `docker/prometheus/prometheus.yml`;若線上 panel 無資料,先查 Prometheus 是否有 `momo-app` target。
|
||
- App container 的 runtime `gunicorn.conf.py` 由 `docker-compose.yml` bind mount;若未來改 gunicorn 設定,不應再手動 `docker cp` 作為常態流程。
|
||
|
||
## 驗證紀錄
|
||
|
||
- 2026-04-29 AI metrics 批次:`26 passed`。
|
||
- 2026-04-29 AI smoke dashboard 批次:`2 passed`(單檔 smoke service),後續核心組需持續納入。
|
||
- 2026-04-29 AI smoke trend 批次:`5 passed`(smoke + metrics)。
|
||
- 2026-04-29 AI smoke management 批次:`7 passed`(smoke + metrics)。
|
||
- 2026-04-29 AI smoke summary 批次:`9 passed`(smoke + metrics)。
|
||
- 2026-04-29 AI Grafana observability 批次:`3 passed`(Grafana dashboard JSON 結構與必要 metric)。
|
||
- 2026-04-29 AI Grafana observability + AI core 回歸:`36 passed`,collect-only:`36 tests collected`。
|
||
- 2026-04-30 Gunicorn LocalProxy 修復:新增 `tests/test_gunicorn_config.py`。
|
||
- 2026-04-30 Prometheus scrape 修復:新增 `tests/test_prometheus_ai_automation_scrape.py`。
|
||
- 2026-04-30 CD health check hardening:新增 `tests/test_cd_health_check.py`。
|
||
- 2026-04-30 CD Gunicorn mount hardening:新增 `tests/test_docker_compose_runtime_mounts.py`。
|
||
- 2026-04-30 Metrics schema drift 降噪:`tests/test_ai_automation_metrics.py` 覆蓋 raw sales count query。
|
||
- 2026-04-29 L2 安全記憶批次:`24 passed`。
|
||
- collect-only:`48 tests collected`。
|
||
- `git diff --check` 已通過。
|
||
|
||
## 相關 commit
|
||
|
||
- `779b27f` 修復 P0 告警自癒鏈與測試收集
|
||
- `0875dd8` 補強 5.5 自癒安全回看
|
||
- `1c2dc6c` 補強 AI 自動化閉環與安全降級
|
||
- `f0e044a` 補齊自癒稽核與 OpenClaw 記憶閉環
|
||
- `0c2e9bb` 串接 AI 洞察向量化與漏通知入口
|
||
- `78eebfb` 加入告警去重與洞察向量回補
|
||
- `d486598` 補強 ElephantAlpha 執行與通知閉環
|
||
- `5b25f55` 補齊 EventRouter 失敗通知回放
|
||
- `162a76b` 落地 L2 安全記憶動作
|
||
- `d58e4d0` 同步四 Agent AI 自動化治理紀錄
|
||
- `e6a1c9d` 補齊 AI 自動化可觀測性指標
|
||
- `cde8b0c` 新增 AI 自動化 Smoke Dashboard
|
||
- `81159b5` 保存 AI Smoke 趨勢紀錄
|
||
- `10bbd55` 補齊 AI Smoke 趨勢管理
|
||
- `d5f4fd7` 加入 AI Smoke 每日摘要推播
|
||
|
||
## 下次進場先看
|
||
|
||
- ADR-018:四 AI Agent 自動化控制面。
|
||
- ADR-012:Action Ladder 與 L2 SAFE_ACTIONS。
|
||
- ADR-013:AutoHeal 安全邊界。
|
||
- `docs/AI_INTELLIGENCE_MODULE_SOT.md`:目前 AI 架構事實。
|
||
- `docs/guides/ai_automation_session_sop.md`:AI 自動化 session 執行與收尾 SOP。
|