fix: json.dumps dict before psycopg2 insert + remove fatal raise in save_context
All checks were successful
CD Pipeline / deploy (push) Successful in 1m22s

save_context/_save_action_plan passed raw Python dicts as SQL bind params,
causing psycopg2.ProgrammingError that propagated via raise and crashed the
entire AI pipeline, forcing every natural language message to keyword fallback.

Also increase Hermes intent timeout 15s→30s for qwen2.5 cold-start latency.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
ogt
2026-04-25 10:12:20 +08:00
parent e4ad2432fd
commit e9e0ddf54f
2 changed files with 6 additions and 7 deletions

View File

@@ -1,5 +1,6 @@
# services/ai_orchestrator.py
import asyncio
import json
import logging
from typing import Any, Dict, Optional
@@ -73,14 +74,13 @@ class AIOrchestrator:
"sid": session_id,
"ag": agent,
"ck": "latest",
"cv": payload,
"cv": json.dumps(payload, ensure_ascii=False),
},
)
session.commit()
except Exception as e:
session.rollback()
logger.error(f"[AIOrchestrator] save_context failed: {e}")
raise
logger.warning(f"[AIOrchestrator] save_context failed (non-fatal): {e}")
finally:
session.close()
@@ -98,13 +98,12 @@ class AIOrchestrator:
"sid": plan.get("session_id"),
"pt": plan.get("plan_type"),
"sku": plan.get("sku"),
"pl": plan,
"pl": json.dumps(plan, ensure_ascii=False),
},
)
session.commit()
except Exception as e:
session.rollback()
logger.error(f"[AIOrchestrator] save_action_plan failed: {e}")
raise
logger.warning(f"[AIOrchestrator] save_action_plan failed (non-fatal): {e}")
finally:
session.close()

View File

@@ -154,7 +154,7 @@ class HermesAnalystService:
resp = requests.post(
f"{HERMES_URL}/api/generate",
json=payload,
timeout=15, # 意圖分類不必等 120s
timeout=30, # 意圖分類qwen2.5 首次推理可能需 ~20s
)
resp.raise_for_status()
raw = (resp.json().get("response", "") or "").strip()