fix(chat): resolve Auto-route failover event-loop freeze (#812)
Root cause: ensure_structured_column() executed a synchronous blocking engine.connect().execute(SELECT information_schema.columns ...) inside the async request path (_build_chat_history / _maybe_compress_history), freezing the uvicorn event loop and hanging all endpoints (~200s, recovered only by docker restart). Fix: - chat_context.py: remove per-request ensure_structured_column() calls; run once idempotently at app startup (main.py lifespan). Use CURRENT_DATABASE() for PostgreSQL compatibility. - main.py: add startup-only ensure_structured_column() hook (try/except). - llm_client.py: trust_env=False + bounded httpx.Timeout/wait_for so broken endpoints fail fast instead of hanging the event loop. - chat_service.py: run media generation in a background daemon thread with its own event loop (_launch_media_task_bg) so SSE end does not cancel image/video tasks (#811); remove TEMP faulthandler diagnostic. Safe-align: persist accumulated live container changes (admin/*, knowledge, market, models, config, observability, mcp_client, platform_knowledge, im_bot_platform, chat_media, capability_registry, requirements) and add workflow_templates. Verified: live failover test (model-006 -> conn-refused) returns in ~1.9s with concurrent login 0.83s/200; event-loop responsiveness restored (sub-second).
This commit is contained in:
1 parent
394a7786e0
commit
a2504bce34
27 files changed
+253
-59
No files matched your search
@@ -1251,7 +1251,7 @@ def _build_system_prompt(
|
||||
|
||||
|
||||
|
||||
system_parts.append("回复格式要求:使用 Markdown 格式,层次分明即可。对于简短问题,用 1-2 段自然文字直接回答,不必强行分点、加标题或表格;仅在确实需要分步骤或列举时才使用列表,代码/配置用 ``` 代码块包裹。避免冗余空行,保持紧凑、美观、易读。")
|
||||
system_parts.append("回复格式要求:使用 Markdown 格式,层次分明即可。对于简短问题,用 1-2 段自然文字直接回答,不必强行分点、加标题或表格;仅在确实需要分步骤或列举时才使用列表,代码/配置用 \"\"\" 代码块包裹。避免冗余空行,保持紧凑、美观、易读。")
|
||||
|
||||
|
||||
|
||||
@@ -2536,7 +2536,6 @@ def _build_chat_history(db, conv_id, max_tokens=6000, max_messages=40,
|
||||
- 按 token 估算从新到旧累加,超预算即截断(隔离:不溢出上下文窗口)。
|
||||
- exclude_latest_user=True 时丢弃最新一条 user 消息(当前轮次另行发送)。
|
||||
"""
|
||||
ensure_structured_column()
|
||||
summary_block = None
|
||||
if include_summary:
|
||||
try:
|
||||
@@ -2707,7 +2706,7 @@ def ensure_structured_column():
|
||||
with engine.connect() as conn:
|
||||
exists = conn.execute(text(
|
||||
"SELECT COUNT(*) FROM information_schema.columns "
|
||||
"WHERE table_schema = DATABASE() AND table_name='conversation_summaries' "
|
||||
"WHERE table_schema = CURRENT_DATABASE() AND table_name='conversation_summaries' "
|
||||
"AND column_name='structured_memory'"
|
||||
)).scalar()
|
||||
if not exists:
|
||||
@@ -2832,7 +2831,6 @@ async def _maybe_compress_history(conv_id):
|
||||
|
||||
失败静默回滚,绝不阻塞用户本次响应(fire-and-forget)。
|
||||
"""
|
||||
ensure_structured_column()
|
||||
sdb = None
|
||||
try:
|
||||
sdb = SessionLocal()
|
||||
|
||||
Reference in new issue
Block a user