fix(ai): enforce ollama first for drift governance
All checks were successful
Code Review / ai-code-review (push) Successful in 16s
CD Pipeline / tests (push) Successful in 1m17s
CD Pipeline / build-and-deploy (push) Successful in 4m54s
CD Pipeline / post-deploy-checks (push) Successful in 3m10s

This commit is contained in:
Your Name
2026-05-06 19:26:09 +08:00
parent d90414ddfa
commit 2ef54ccc94
6 changed files with 157 additions and 9 deletions

View File

@@ -4014,3 +4014,51 @@ py_compile apps/api/src/services/heartbeat_report_service.py apps/api/tests/test
ruff check --select F401,F821,I001 apps/api/src/services/heartbeat_report_service.py apps/api/tests/test_heartbeat_ollama_endpoints.py
# All checks passed
```
---
## 2026-05-06台北— Drift AI 治理路徑改為 Ollama-first
**觸發**production 仍出現 `provider=gemini` 的成功呼叫,路徑為 `/api/v1/drift/internal/scan`,不是 Telegram 告警卡片。追查後確認 Redis AI Control 仍停用 `openclaw_nemo`OpenClaw `/health` 雖正常,但直接呼叫 `/api/v1/analyze/incident` 回傳 `openclaw_degraded`,原因為下游 LLM 輸出非法 JSON escape`JSONDecodeError: Invalid \\uXXXX escape`),因此不能直接重新啟用。
### 已修正
| 範圍 | 結果 |
|------|------|
| `openclaw.py` | 新增顯式 `enforce_ollama_first` 治理旗標;除了 Telegram/incident alertAI governance 任務也能強制 GCP-A → GCP-B → 111 → Gemini 備援 |
| `ai_router.py` | cache gate 同步辨識 `enforce_ollama_first`,避免 Ollama-first 任務誤用舊 Gemini cache |
| `drift_interpreter.py` | Config drift intent 分析呼叫 OpenClaw 時帶上 `enforce_ollama_first``task_type=diagnose``allow_gcp_heavy_model=true`,避免 drift/governance 掃描直接走 Gemini |
| 測試 | 新增 drift interpreter 回歸測試,並擴充 OpenClaw provider-order 測試 |
### Live 判斷
| 檢查點 | 結果 |
|--------|------|
| GCP-A / GCP-B / 111 | API Pod 目前都可探測成功;心跳報告可分別顯示三端點 |
| 188 Ollama | 已退場,不再作為 AWOOOI Ollama provider |
| `openclaw_nemo` | 仍不可重新啟用,因實際 analyze 端點回 degraded需另修 OpenClaw 服務端 JSON 修復/結構化輸出 |
| Gemini | 保留為最後備援,不禁用;但 drift/governance 現在會先走 Ollama 三段式 |
### 驗證
```text
DATABASE_URL='postgresql+asyncpg://test:test@localhost:5432/test' pytest \
apps/api/tests/test_openclaw_alert_cloud_fallback_gate.py \
apps/api/tests/test_drift_interpreter_ollama_first.py
# 8 passed
ruff check \
apps/api/src/services/openclaw.py \
apps/api/src/services/drift_interpreter.py \
apps/api/tests/test_openclaw_alert_cloud_fallback_gate.py \
apps/api/tests/test_drift_interpreter_ollama_first.py
# All checks passed
py_compile \
apps/api/src/services/openclaw.py \
apps/api/src/services/ai_router.py \
apps/api/src/services/drift_interpreter.py \
apps/api/tests/test_openclaw_alert_cloud_fallback_gate.py \
apps/api/tests/test_drift_interpreter_ollama_first.py
# 通過
```