fix: hide model timeout in deploy review reports
All checks were successful
CD Pipeline / deploy (push) Successful in 1m4s

This commit is contained in:
ogt
2026-06-25 14:52:31 +08:00
parent 39ff5d5605
commit ef6c4b0abd
4 changed files with 26 additions and 8 deletions

View File

@@ -116,6 +116,7 @@ ALLOW_INSECURE_WEBHOOK = os.getenv("MOMO_ALLOW_INSECURE_INTERNAL_WEBHOOK_FOR_DEV
AIDER_AUTO_FIX_FILE_PATTERN = re.compile(
r"^(services|routes|database)/(?:[a-zA-Z0-9_]+/)*[a-zA-Z0-9_]+\.py$"
)
_OPENCLAW_RAW_ERROR_RE = re.compile(r"[;]?\s*最後錯誤:[^<\n\r]+")
# Phase 7 Frontier 升級 feature flag — 預設 OFF啟用後只作 Ollama 失敗後的雲端備援。
CODE_REVIEW_USE_CLAUDE = os.getenv("CODE_REVIEW_USE_CLAUDE", "false").lower() == "true"
@@ -127,6 +128,18 @@ def _aider_allowed_fix_files(files: List[str]) -> List[str]:
return [f for f in files if AIDER_AUTO_FIX_FILE_PATTERN.match(f or "")]
def _public_openclaw_report(report: Any) -> str:
"""Hide model timeout internals from post-deploy reports shown to operators."""
text = str(report or "")
if not text:
return ""
text = _OPENCLAW_RAW_ERROR_RE.sub("AI 延伸分析暫時略過,已以本地掃描完成部署後檢查", text)
text = text.replace("本地降級報告", "本地掃描報告")
text = text.replace("deterministic scan", "本地掃描")
text = text.replace("OpenClaw", "AI 架構檢查")
return text
def _code_review_ollama_host_reachable(host: str) -> bool:
"""Short-circuit dead GCP Ollama hosts before a generate timeout."""
if not CODE_REVIEW_OLLAMA_HOST_PREFLIGHT_ENABLED:
@@ -816,15 +829,14 @@ class CodeReviewPipeline:
top = [f for f in findings[:2] if f.get("description")]
top_text = "".join(
f"{f.get('file', 'unknown')}{f.get('description')}" for f in top
) or "本次 deterministic scan 未發現高風險問題"
error_text = (last_error or "local Ollama unavailable")[:120]
) or "本次本地掃描未發現高風險問題"
return (
f"<b>🔍 整體風險等級</b> {risk}"
f"本地掃描完成 {len(files)}CRITICAL={sev['critical']}、HIGH={sev['high']}"
f"MEDIUM={sev['medium']}、LOW={sev['low']}"
f"<b>⚠️ 最需關注問題</b> {top_text}"
f"<b>💡 架構優化方向</b> GCP-A/GCP-B OpenClaw 不可用時暫停 111 重分析,避免拖高 fallback 主機負載。"
f"<b>✅ 本次部署亮點</b> 已以本地降級報告收斂,未呼叫 Gemini最後錯誤:{error_text}"
f"<b>💡 架構優化方向</b> AI 架構檢查延伸分析不可用時,以本地掃描收斂,避免拖高模型主機負載。"
f"<b>✅ 本次部署亮點</b> 已以本地掃描報告收斂,未呼叫 GeminiAI 延伸分析暫時略過。"
)
# ── Step 4ElephantAlpha 決策 ─────────────────────────────────────────────
@@ -1169,7 +1181,10 @@ def trigger_post_deploy_review(
def get_current_state() -> Dict[str, Any]:
"""前端 polling 用:取得目前 pipeline 即時狀態"""
with _pipeline_lock:
return dict(_current_pipeline)
state = dict(_current_pipeline)
if state.get("openclaw_report"):
state["openclaw_report"] = _public_openclaw_report(state.get("openclaw_report"))
return state
def get_history(limit: int = 20) -> List[Dict]:
@@ -1203,7 +1218,7 @@ def get_history(limit: int = 20) -> List[Dict]:
"total_issues": sum(sev.values()),
"auto_fix": meta.get("auto_fix_triggered", False),
"findings": content.get("findings", []),
"openclaw_report": content.get("openclaw_report", ""),
"openclaw_report": _public_openclaw_report(content.get("openclaw_report", "")),
"ea_decision": content.get("ea_decision", {}),
"created_at": r[4].isoformat() if r[4] else "",
"status": r[5] or "active",