feat: auto-heal checks key availability before restarting gateway
This commit is contained in:
@@ -305,6 +305,18 @@ def auto_heal():
|
||||
h = health()
|
||||
actions = []
|
||||
|
||||
# 0. LLM Provider 异常 → 先查是否有更好的 Key
|
||||
if h.get("llm_provider", {}).get("status") in ("timeout", "error"):
|
||||
bk = best_key()
|
||||
if bk:
|
||||
actions.append({
|
||||
"action": "check_keys",
|
||||
"best_key": bk["key_id"],
|
||||
"rolling_pct": bk["rolling"]["usage_percent"],
|
||||
"weekly_pct": bk["weekly"]["usage_percent"],
|
||||
"issues": bk["issues"],
|
||||
})
|
||||
|
||||
# 1. LLM Provider 超时 → 重启 Hermes Gateway
|
||||
if h.get("llm_provider", {}).get("status") in ("timeout", "error"):
|
||||
gw = h.get("gateways", {}).get("zhiwei", {})
|
||||
@@ -341,3 +353,12 @@ def auto_heal():
|
||||
"success": False, "detail": str(e)[:100]})
|
||||
|
||||
return {"actions": actions, "status": h.get("status", "unknown")}
|
||||
|
||||
|
||||
def _verify_heal():
|
||||
"""自愈后验证:等 Gateway 启动完成,检测 LLM 是否恢复"""
|
||||
_time.sleep(8) # 等 Gateway 完全启动
|
||||
h = health()
|
||||
llm_ok = h.get("llm_provider", {}).get("status") == "ok"
|
||||
gw_ok = h.get("gateways", {}).get("zhiwei", {}).get("alive", False)
|
||||
return {"llm_recovered": llm_ok, "gateway_alive": gw_ok, "status": h.get("status")}
|
||||
|
||||
Reference in New Issue
Block a user