fix(auto-repair): 修復三個阻礙自動修復的根本原因
Some checks failed
CD Pipeline / build-and-deploy (push) Has been cancelled

1. playbook_rag: Ollama embedding http_client 滾動重啟後 is_closed
   - 新增 _get_http_client() 偵測 is_closed 自動重建
   - singleton get_playbook_rag_service() 加 is_closed 重建判斷

2. telegram: 加入 ai_model 欄位顯示底層判斷模型
   - TelegramMessage.ai_model 欄位
   - format() / format_with_nemotron() 顯示 "Nemotron (nemotron-70b)"
   - openclaw proposal_dict 加入 model 欄位
   - decision_manager / send_approval_card 串接

3. DB: 清除 9 筆 3/26 殭屍 PENDING (mock_fallback CRITICAL 測試記錄)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
OG T
2026-04-04 11:46:25 +08:00
parent 12bc94796a
commit d0f09705e5
4 changed files with 33 additions and 6 deletions

View File

@@ -153,11 +153,24 @@ class PlaybookRAGService:
# Embedding Operations
# =========================================================================
async def _get_http_client(self) -> httpx.AsyncClient:
"""
取得有效的 HTTP Client若已關閉則重建
2026-04-04 ogt: 修復滾動重啟後 is_closed=True 導致 embedding 失敗
"""
if self._http_client.is_closed:
logger.warning("playbook_rag_http_client_closed_rebuilding")
from src.core.http_client import get_general_client
self._http_client = await get_general_client()
return self._http_client
async def embed_text(self, text: str) -> list[float] | None:
"""
使用 Ollama 生成文字 embedding
2026-03-27 ogt: 改用 DI 注入的 http_client (P1 違規修復)
2026-04-04 ogt: 加入 is_closed 自動重建機制
Args:
text: 要向量化的文字
@@ -166,8 +179,8 @@ class PlaybookRAGService:
向量 (768 維) 或 None (失敗時)
"""
try:
# 使用 DI 注入的 http_client設置單次請求 timeout
response = await self._http_client.post(
client = await self._get_http_client()
response = await client.post(
f"{self.ollama_url}/api/embeddings",
json={
"model": self.embedding_model,
@@ -545,7 +558,8 @@ async def get_playbook_rag_service() -> PlaybookRAGService:
2026-03-27 ogt: 改用 DI 注入,從 Lifespan 取得 http_client 和 Redis
"""
global _rag_service
if _rag_service is None:
# 2026-04-04 ogt: 滾動重啟後 http_client is_closed需重建 singleton
if _rag_service is None or _rag_service._http_client.is_closed:
# 延遲導入避免循環依賴
from src.core.http_client import get_general_client
from src.core.redis_client import get_redis