From c573a37c4fb99e23ab59da665b0ae93b8dff9466 Mon Sep 17 00:00:00 2001 From: Jeason <1710884619@qq.com> Date: Wed, 8 Apr 2026 09:16:11 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E9=A3=9E=E4=B9=A6=E9=95=BF=E8=BF=9E?= =?UTF-8?q?=E6=8E=A5=20Pipeline=20=E9=A2=84=E5=88=9D=E5=A7=8B=E5=8C=96=20+?= =?UTF-8?q?=20=E9=94=99=E8=AF=AF=E6=97=A5=E5=BF=97=E5=BC=BA=E5=88=B6?= =?UTF-8?q?=E5=88=B7=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - FeishuLongConnService.__init__ 预初始化 Pipeline(避免首条消息懒加载超时) - 初始化失败时打印完整堆栈,启动日志里就能看到错误 - _process_message_safe 异常时 flush stderr 确保日志不被缓冲 - 消息处理时优先用预初始化的 pipeline,fallback 到 service_manager --- src/integrations/feishu_longconn_service.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/integrations/feishu_longconn_service.py b/src/integrations/feishu_longconn_service.py index 29fe981..e5cc7ec 100644 --- a/src/integrations/feishu_longconn_service.py +++ b/src/integrations/feishu_longconn_service.py @@ -55,6 +55,14 @@ class FeishuLongConnService: self._executor = ThreadPoolExecutor(max_workers=5, thread_name_prefix="feishu_msg") self._msg_count = 0 + # 预初始化 Pipeline(避免首条消息时懒加载导致超时) + try: + self._pipeline = service_manager.get_pipeline() + logger.info("✅ MessagePipeline 预初始化成功") + except Exception as e: + logger.error(f"❌ MessagePipeline 预初始化失败: {e}", exc_info=True) + self._pipeline = None + def _handle_message(self, data: P2ImMessageReceiveV1) -> None: """收到消息事件,立即提交到线程池,确保 SDK 回调快速返回""" self._msg_count += 1 @@ -68,6 +76,8 @@ class FeishuLongConnService: self._process_message(data) except Exception as e: logger.error(f"❌ 消息 #{msg_no} 处理异常: {e}", exc_info=True) + import sys + sys.stderr.flush() try: mid = data.event.message.message_id self._reply_message(mid, "抱歉,系统遇到了一些问题,请稍后重试。") @@ -166,8 +176,9 @@ class FeishuLongConnService: # 使用 Pipeline 统一处理消息 session_user_id = f"feishu_{chat_id}_{sender_id}" try: - pipeline = service_manager.get_pipeline() - logger.info(f"Pipeline 开始处理: user={session_user_id}, chat_id={chat_id}") + logger.info(f"正在获取 Pipeline...") + pipeline = self._pipeline or service_manager.get_pipeline() + logger.info(f"Pipeline 开始处理: user={session_user_id}") response_data = pipeline.handle_message( user_id=session_user_id, message=text_content,