From e9e0ddf54fe276344bd95ea37f96a23bba782653 Mon Sep 17 00:00:00 2001 From: ogt Date: Sat, 25 Apr 2026 10:12:20 +0800 Subject: [PATCH] fix: json.dumps dict before psycopg2 insert + remove fatal raise in save_context MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- services/ai_orchestrator.py | 11 +++++------ services/hermes_analyst_service.py | 2 +- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/services/ai_orchestrator.py b/services/ai_orchestrator.py index c5e180b..9814615 100644 --- a/services/ai_orchestrator.py +++ b/services/ai_orchestrator.py @@ -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() diff --git a/services/hermes_analyst_service.py b/services/hermes_analyst_service.py index d4f4f22..6b89064 100644 --- a/services/hermes_analyst_service.py +++ b/services/hermes_analyst_service.py @@ -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()